Contatore caratteri open office
- Mago Nick
- Scoppiettante Seguace

- Messaggi: 708
- Iscrizione: venerdì 13 luglio 2007, 18:54
- Desktop: ubuntu
- Distribuzione: Ubuntu 12.04.4 LTS x86_64
Contatore caratteri open office
Ho notato che open office non ha il conteggio caratteri spazi esclusi, come posso rimediare? devo fare un lavoro per cui mi è richiesto un preciso numero di caratteri, sono disperato >:( >:( >:(
help please!
help please!
- Kitpou
- Entusiasta Emergente

- Messaggi: 1577
- Iscrizione: giovedì 7 settembre 2006, 22:32
- Località: London, and Florence
Re: Contatore caratteri open office
Ho provato e funziona.
Se vai in Strumenti-> Conteggio Parole ti da il numero delle parole e dei caratteri dell'intero documento.
Se selezioni una parte del testo e fai la stessa operazione, oltre a darti le parole e i caratteri dell'intero documento fornisce anche i dati relativi alla parte selezionata.
Se vai in Strumenti-> Conteggio Parole ti da il numero delle parole e dei caratteri dell'intero documento.
Se selezioni una parte del testo e fai la stessa operazione, oltre a darti le parole e i caratteri dell'intero documento fornisce anche i dati relativi alla parte selezionata.
Bye, Fulvio aka Kitpou
During times of universal deceit, telling the truth becomes a revolutionary act. George Orwell
Minitrue Blog
During times of universal deceit, telling the truth becomes a revolutionary act. George Orwell
Minitrue Blog
- Mago Nick
- Scoppiettante Seguace

- Messaggi: 708
- Iscrizione: venerdì 13 luglio 2007, 18:54
- Desktop: ubuntu
- Distribuzione: Ubuntu 12.04.4 LTS x86_64
Re: Contatore caratteri open office
i caratteri però sono spazi inclusi, o sbaglio?
- jepessen
- Imperturbabile Insigne

- Messaggi: 3569
- Iscrizione: lunedì 26 dicembre 2005, 11:49
- Desktop: KDevelop
- Distribuzione: Ubuntu 20.04
- Sesso: Maschile
- Località: Somma Lombardo
Re: Contatore caratteri open office
Mi pare ci fosse una macro in giro su internet che fa quello che vuoi... prova a fare una ricerca
Daniele
Daniele
Compiz l'ha creato Chuck Norris quando ha colpito un computer con un calcio rotante.
http://www.renderosity.com/mod/gallery/ ... e=Jepessen
http://jepessen.wordpress.com/
http://www.renderosity.com/mod/gallery/ ... e=Jepessen
http://jepessen.wordpress.com/
- Mago Nick
- Scoppiettante Seguace

- Messaggi: 708
- Iscrizione: venerdì 13 luglio 2007, 18:54
- Desktop: ubuntu
- Distribuzione: Ubuntu 12.04.4 LTS x86_64
Re: Contatore caratteri open office
ti ringrazio!!!! sei il mio dio!!!
- jepessen
- Imperturbabile Insigne

- Messaggi: 3569
- Iscrizione: lunedì 26 dicembre 2005, 11:49
- Desktop: KDevelop
- Distribuzione: Ubuntu 20.04
- Sesso: Maschile
- Località: Somma Lombardo
Re: Contatore caratteri open office
Fanciulle in sacrificio... ricorda....
Comunque vedi se lo trovi, prima di convertirti...
Daniele
Comunque vedi se lo trovi, prima di convertirti...
Daniele
Compiz l'ha creato Chuck Norris quando ha colpito un computer con un calcio rotante.
http://www.renderosity.com/mod/gallery/ ... e=Jepessen
http://jepessen.wordpress.com/
http://www.renderosity.com/mod/gallery/ ... e=Jepessen
http://jepessen.wordpress.com/
- Kitpou
- Entusiasta Emergente

- Messaggi: 1577
- Iscrizione: giovedì 7 settembre 2006, 22:32
- Località: London, and Florence
Re: Contatore caratteri open office
Dai gli\ti do una manojepessen ha scritto: Fanciulle in sacrificio... ricorda....
Comunque vedi se lo trovi, prima di convertirti...
Daniele
Vedi un pò qua:
http://www.ooomacros.org/user.php
Bye, Fulvio aka Kitpou
During times of universal deceit, telling the truth becomes a revolutionary act. George Orwell
Minitrue Blog
During times of universal deceit, telling the truth becomes a revolutionary act. George Orwell
Minitrue Blog
- Mago Nick
- Scoppiettante Seguace

- Messaggi: 708
- Iscrizione: venerdì 13 luglio 2007, 18:54
- Desktop: ubuntu
- Distribuzione: Ubuntu 12.04.4 LTS x86_64
Re: Contatore caratteri open office
hem ho provato l'unica macro che conteneva un contatore caratteri migliorato rispetto a quello di openoffice, però è sempre spazi inclusi... >:(
>:(
>:(
- Kitpou
- Entusiasta Emergente

- Messaggi: 1577
- Iscrizione: giovedì 7 settembre 2006, 22:32
- Località: London, and Florence
Re: Contatore caratteri open office
A questo punto alzo le mani...speriamo intervenga qualcuno che risolva questo dettaglio :-[
Bye, Fulvio aka Kitpou
During times of universal deceit, telling the truth becomes a revolutionary act. George Orwell
Minitrue Blog
During times of universal deceit, telling the truth becomes a revolutionary act. George Orwell
Minitrue Blog
- jepessen
- Imperturbabile Insigne

- Messaggi: 3569
- Iscrizione: lunedì 26 dicembre 2005, 11:49
- Desktop: KDevelop
- Distribuzione: Ubuntu 20.04
- Sesso: Maschile
- Località: Somma Lombardo
Re: Contatore caratteri open office
Posta qua il codice della macro, vediamo se riusciamo a modificarlo...
Daniele
Daniele
Compiz l'ha creato Chuck Norris quando ha colpito un computer con un calcio rotante.
http://www.renderosity.com/mod/gallery/ ... e=Jepessen
http://jepessen.wordpress.com/
http://www.renderosity.com/mod/gallery/ ... e=Jepessen
http://jepessen.wordpress.com/
- Mago Nick
- Scoppiettante Seguace

- Messaggi: 708
- Iscrizione: venerdì 13 luglio 2007, 18:54
- Desktop: ubuntu
- Distribuzione: Ubuntu 12.04.4 LTS x86_64
Re: Contatore caratteri open office
come devo fare?
- jepessen
- Imperturbabile Insigne

- Messaggi: 3569
- Iscrizione: lunedì 26 dicembre 2005, 11:49
- Desktop: KDevelop
- Distribuzione: Ubuntu 20.04
- Sesso: Maschile
- Località: Somma Lombardo
Re: Contatore caratteri open office
Andando in strumenti macro, dovresti poter selezionare le macro presenti nel documento, ed eventualmente modificarle.. appena ti si apre l'editor, copi tutto e posti qua...
Daniele
Daniele
Compiz l'ha creato Chuck Norris quando ha colpito un computer con un calcio rotante.
http://www.renderosity.com/mod/gallery/ ... e=Jepessen
http://jepessen.wordpress.com/
http://www.renderosity.com/mod/gallery/ ... e=Jepessen
http://jepessen.wordpress.com/
- Mago Nick
- Scoppiettante Seguace

- Messaggi: 708
- Iscrizione: venerdì 13 luglio 2007, 18:54
- Desktop: ubuntu
- Distribuzione: Ubuntu 12.04.4 LTS x86_64
Re: Contatore caratteri open office
ecchilo
thx ^^
m.
Codice: Seleziona tutto
REM ***** BASIC *****
Sub Main
acbwc
End Sub
Sub acbwc
' v3.0 with hotcount
' 12 October 2004
'
' the test for this is that that it is very fast, and, if you select
' a whole document, will give you the same number of words in the selection as
' OOo returns for the whole doc.
' there is one exception: fields such as page numbers and dates are not counted
' in the OOo word count statistics. They are counted by the selected text macro.
' If anything, that makes it more accurate :-)
'
' there is one possible snag: the language it counts selected text in
' is officially declared as English. Translated versions need to change
' the line in hotcount aLocale.Language="en" to their locale.
' Someone with time on their hands could write code to detect the language in use
' and make that change automatically.
' This version written almost entirely by Andrew Brown.
dim xDoc, xSel, nSelcount
dim nAllChars
dim nAllWords
dim nAllPars
dim thisrange, sRes
dim nSelChars, nSelwords, nSel
dim atext, bigtext
dim fnotes, thisnote, nfnotes, fnotecount
xDoc = thiscomponent
xSel = xDoc.getCurrentSelection()
nSelCount = xSel.getCount()
' by popular demand ...
fnotes=xdoc.getFootNotes()
if fnotes.hasElements() then
fnotecount=0
for nfnotes=0 to fnotes.getCount()-1
thisnote=fnotes.getbyIndex(nfnotes)
fnotecount=fnotecount+hotcount(thisnote)
next nfnotes
end if
' this next "if" works around the problem that if you have made a selection, then
' collapsed it, then count again, the empty selection is still counted which was confusing and ugly
if nSelCount=1 and xSel.getByIndex(0).getString()="" then
nSelCount=0
end if
' access easy document statistics
nAllChars = xDoc.CharacterCount
nAllWords = xDoc.WordCount
nAllPars = xDoc.ParagraphCount
' initialize counts
nSelChars = 0
nSelWords = 0
' the fancy bit starts here
' iterate over multiple selection
for nSel = 0 to nSelCount - 1
thisrange=xSel.GetByIndex(nSel)
atext=thisrange.getString()
nselwords=nSelWords+hotcount(atext)
nSelChars=nSelChars+len(atext)
next nSel
' dialog code rewritten for legibility
if fnotes.hasElements() then
sRes="Document count (with footnotes): " + nAllWords + " words. " + chr(13)
sRes=sRes+"Word count without footnotes: "+ str(nAllWords-fnotecount) + " words. " + chr(13)+"(Total: " +nAllChars +" Chars in "
else
sRes= "Document count: " + nAllWords +" words. " + chr(13)+"(" +nAllChars +" Chars in "
end if
sRes=sRes + nAllPars +" Paragraphs.)"+ chr(13)+ chr(13)
if nselCount>0 then
sRes=sRes + "Selected text count: " + nSelWords + " words" + chr(13) + "(" + nSelChars + " chars"
if nSelcount=1 then
sRes=sRes + " In " + str(nselCount) + " selection.)"
else
sRes=sRes + " In " + str(nselCount-1) +" selections.)" ' don't know why, but need this adjustment
end if
sRes=sRes+chr(13)+chr(13)+"Document minus selected:" + chr(13)+ str(nAllWords-nSelWords) + " words." +chr(13) +chr(13)
end if
if fnotes.hasElements() then
if fnotes.getCount()=1 then
sRes=sRes+"There are "+ str(fnotecount) + " words in the "+ fnotes.getCount() +" footnote." +chr(13) +chr(13)
else
sRes=sRes+"There are "+ str(fnotecount) + " words in "+ fnotes.getCount() +" footnotes." +chr(13) +chr(13)
end if
end if
msgbox(sRes,64,"Word Count 3.0")
End Sub
function hotcount(aString)
' the ultimate, using the same breakiterator as the program
'
dim mystartpos as long
dim numwords,nw
dim nextwd as new com.sun.star.i18n.Boundary
dim aLocale as new com.sun.star.lang.Locale
aLocale.Language="en"
' Urska, you may need to change the line above.
numwords=1 ' don't ask me why we need this
mystartpos=0
brk=createUnoService("com.sun.star.i18n.BreakIterator")
nextwd=brk.nextWord(aString,startpos,aLocale,com.sun.star.i18n.WordType.WORD_COUNT)
Do while nextwd.startPos<> nextwd.endPos
numwords=numwords+1
nw=nextwd.startPos
nextwd=brk.nextWord(aString,nw,aLocale,com.sun.star.i18n.WordType.WORD_COUNT)
Loop
hotcount=numwords
end Functionm.
- Mago Nick
- Scoppiettante Seguace

- Messaggi: 708
- Iscrizione: venerdì 13 luglio 2007, 18:54
- Desktop: ubuntu
- Distribuzione: Ubuntu 12.04.4 LTS x86_64
Re: Contatore caratteri open office
up please T.T
Re: Contatore caratteri open office
questo interessa anche a me, ho il suo stesso problema (:P) e necessito del conteggio caratteri spazi esclusi T_TA. Nicastro ha scritto: up please T.T
qualcuno sa dare una mano?
- jepessen
- Imperturbabile Insigne

- Messaggi: 3569
- Iscrizione: lunedì 26 dicembre 2005, 11:49
- Desktop: KDevelop
- Distribuzione: Ubuntu 20.04
- Sesso: Maschile
- Località: Somma Lombardo
Re: Contatore caratteri open office
Mmmm....
Scusate tutti, avevo perso l'aggiornamento di questo thread...
Stasera uppate per ricordarmelo, che se sono a casa do uno sguardo al codice...
Daniele
Scusate tutti, avevo perso l'aggiornamento di questo thread...
Stasera uppate per ricordarmelo, che se sono a casa do uno sguardo al codice...
Daniele
Compiz l'ha creato Chuck Norris quando ha colpito un computer con un calcio rotante.
http://www.renderosity.com/mod/gallery/ ... e=Jepessen
http://jepessen.wordpress.com/
http://www.renderosity.com/mod/gallery/ ... e=Jepessen
http://jepessen.wordpress.com/
Re: Contatore caratteri open office
io te lo uppo e mi affido a te :Pjepessen ha scritto: Mmmm....
Scusate tutti, avevo perso l'aggiornamento di questo thread...
Stasera uppate per ricordarmelo, che se sono a casa do uno sguardo al codice...
Daniele
dover loggare su winzoz per qualsiasi motivo che non sia giocare ad un qualche gioco demenziale che gira solo li mi deprime profondamente, e dato che dovrò lavorare ancora per 3 anni con il conteggio caratteri spazi esclusi preferirei dover evitare questa sofferenza eheh ^^
comunque aspetto e spero che qualcuno sappia risolvere^^
- jepessen
- Imperturbabile Insigne

- Messaggi: 3569
- Iscrizione: lunedì 26 dicembre 2005, 11:49
- Desktop: KDevelop
- Distribuzione: Ubuntu 20.04
- Sesso: Maschile
- Località: Somma Lombardo
Re: Contatore caratteri open office
Allora, cercando documentazione ho trovato un'altra macro che fa più o meno la stessa cosa...
L'ho modificata un pochetto, ma non completamente, anche perchè c'ho sonno...
Aprite l'editor (Strumenti->Macro->Organizza Macro->Macro): su Macro Personali cliccate su Nuovo, e copiate il seguente codice:
Salvate con un bel nome. A questo punto, nella finestra di gestione macro, se scegliete la vostra compaiono due funzioni: selezionate la funzione SelectionCount e vi da una statistica di tutte le parole e lettere.
Ora, se volete escludere gli spazi, dovete selezionare il testo, quindi eventualmente selezionate tutto il documento (un bel CTRL+a dovrebbe bastare), e rieseguite la stessa funzione. Ora nella finestra, oltre al conteggio globale, dovrebbe comparire il conteggio della selezione, con il conteggio dei caratteri spazi esclusi.
Se volete escludere altri caratteri (tipo le virgole), cercate la riga
e aggiungete i vari caratteri che volete escludere. Se poi avrò tempo la sistemerò meglio, per fare il lavoro anche senza bisogno di selezionare manualmente tutto il documento.
Daniele
L'ho modificata un pochetto, ma non completamente, anche perchè c'ho sonno...
Aprite l'editor (Strumenti->Macro->Organizza Macro->Macro): su Macro Personali cliccate su Nuovo, e copiate il seguente codice:
Codice: Seleziona tutto
' Based on the original* "dvwc" macro by Daniel Vogelheim *see end of doc
' Displays a message box with number of words & characters
' in the document and the current selection.
' John Vigor edited this in 2003 to provide both a character count
' and a character count with exclusions. DV's had one of these.
' Does not normally count in frames, headers, footers or footnotes
' although these items may be individually selected. Selected text
' cannot exceed 64K of characters. (About 18 dense single spaced pages
' using New Times Roman size 12 and 1 inch margins all around. This
' size takes about 20 seconds on a 770MHz machine, so go get a cup
' of coffee or just be patient.)
' OO's word count, as of OO1.1 rc4, does not count in fields but does
' count in the other areas mentioned above. OO's character count
' counts a line break (Shift+Enter) as a character (Issue filed #16918).
Sub SelectionCount
'DEFINE CHARACTER COUNT BELOW. The default exclusions from character count are
'spaces & tabs, i.e., one of each of these is contained in the definition of e$.
'You can add characters between the quotes and/or delete the space and/or tab.
e$ = Chr(32) + Chr(9) ' Chr(32) is a space, Chr(9) is a tab. Valid replacements would
'be e$ = Chr(32) or e$ = Chr(9) or e$ = "" with the latter being no exclusions. If you
'did not change e$ and if the line below read:
' sExcludeFromCharacterCount$ = e$ + "a" then spaces, tabs and the letter "a" would not
'be counted.
sExcludeFromCharCount$ = e$ + " "
'DEFINE WORD SEPERATORS BELOW. The default word separators are spaces and
'hyphens (true hyphenated words like "half-dollar" will be counted as two words
'instead of one). You can add separators between the quotes and/or delete the hyphen.
'Examples: "/" to count "and/or" as two words. "&" to count "Johnson & Johnson" as
'two words instead of three. A period is not normally needed but you can add one
'to count "www.website.com" as three words instead of one.
sWordSeps = " -"
' This section is basically all DV's code with small modifications needed by JV
sWordSeps = sWordSeps + chr(9) + chr(10) + chr(13)'a tab, line break and paragraph break
sNeverCountChars = chr(10) & chr(13)'never include line or paragraph breaks in char count
oDocument = thisComponent
oSelection = oDocument.getCurrentSelection()
nSelCount = oSelection.getCount()
' access the program's document statistics
nAllChars = oDocument.CharacterCount
nAllWords = oDocument.WordCount
' initialize counts
nSelWords = 0 : nSelChars = 0 : nSelCharEx = 0
' iterate over multiple selections
Do
sText = oSelection.getByIndex(nSel).getString()
' count word in sText by scanning the selected text character for character
nCount = Len(sText)
bLastWasSeparator = true
bWord = false
'first letter starts a word
i = 1
Do ' DV used different logic for this section and there was nothing wrong
' with it. A programing exercise for JV and it better fit his needs.
sChr = Mid(sText,i,1)
If instr(sWordSeps, sChr) = 0 then 'if true then it's part of a word
bWord = true
GoSub CountIt 'count this character?
Elseif bWord = True then 'is a seperator and at end of word.
nSelWords = nSelWords + 1
bWord = false
GoSub CountIt
Else
GoSub CountIt 'is seperator but not the at end of a word.
EndIf
' End of JV's logic.
i = i + 1
Loop Until i > nCount 'get the next character in the string
nSel = nSel + 1
Loop while nSel < nSelCount
' Begin JV stuff
if bWord then nSelWords = nSelWords + 1
sExclude$ = " "
if Len(sExcludeFromCharCount$) = 0 then
sExclude$ = "* No exclusions."
else sExclude$ = Build_sExclude(sExcludeFromCharCount$)
endif
' JV altered DV's message box.
sT = chr(9): sP = chr(13) 'a Tab and Paragraph Break
a$ = "Program Document Count" + sP + sT & " All words: " + nAllWords + sP
b$ = sT & " All chars: " + nAllChars + sP + "Macro Selection Count" + sP
sMsg = a$ & b$
If nSelChars > 0 then
a$ = sT & " Words: " + nSelWords + sP + sT & " Chars: " + nSelChars + sP + sT
b$ = " * Chars: " + nSelCharEx + sP & sExclude$
sMsg = sMsg + a$ + b$
Else a$ = "No text was selected or the selection" & sP & sT & "exceeded 64K characters."
sMsg = sMsg + sT & a$
EndIf
msgbox sMsg
Exit Sub
CountIt: 'Going to count this character/excluded char count?
Select Case instr(sNeverCountChars,sChr)
case = 0
If instr(sExcludeFromCharCount$, sChr) = 0 then
nSelCharEx = nSelCharEx + 1 : nSelChars = nSelChars + 1
Else nSelChars = nSelChars + 1
Endif
End Select
Return
End Sub
' This JV function constructs the string that shows
' the excluded characters for the character count.
Function Build_sExclude(sExcludeFromCharCount$)
sExclude$ = "* Excluding "
sOthers = sExcludeFromCharCount$
iPos = instr(sOthers," ")
If iPos > 0 then
Mid(sOthers,iPos,1,"")
select Case len(sOthers)
case 0 : sExclude$ = sExclude$ & "spaces."
case > 0: If instr(sOthers,chr(9)) = 0 then
sExclude$ = sExclude$ & "spaces and "
Else sExclude$ = sExclude$ & "spaces"
EndIf
end select
EndIf
iPos = instr(sOthers,chr(9))
If iPos > 0 then
Mid(sOthers,iPos,1,"")
Select Case len(sOthers)
Case 0 : If len(sExclude$) < 13 then
sExclude$ = sExclude$ & "tabs."
Else sExclude$ = sExclude$ & " and tabs."
EndIf
Case > 0: If len(sExclude$) < 13 then
sExclude$ = sExclude$ & "tabs and "
Else sExclude$ = sExclude$ & ", tabs and "
EndIf
End Select
EndIf
Build_sExclude = sExclude$ & sOthers
End Function
Ora, se volete escludere gli spazi, dovete selezionare il testo, quindi eventualmente selezionate tutto il documento (un bel CTRL+a dovrebbe bastare), e rieseguite la stessa funzione. Ora nella finestra, oltre al conteggio globale, dovrebbe comparire il conteggio della selezione, con il conteggio dei caratteri spazi esclusi.
Se volete escludere altri caratteri (tipo le virgole), cercate la riga
Codice: Seleziona tutto
sExcludeFromCharCount$ = e$ + " "Daniele
Compiz l'ha creato Chuck Norris quando ha colpito un computer con un calcio rotante.
http://www.renderosity.com/mod/gallery/ ... e=Jepessen
http://jepessen.wordpress.com/
http://www.renderosity.com/mod/gallery/ ... e=Jepessen
http://jepessen.wordpress.com/
Re: Contatore caratteri open office
l'ho provata ora e funziona a meraviglia^^jepessen ha scritto: Allora, cercando documentazione ho trovato un'altra macro che fa più o meno la stessa cosa...
L'ho modificata un pochetto, ma non completamente, anche perchè c'ho sonno...
Aprite l'editor (Strumenti->Macro->Organizza Macro->Macro): su Macro Personali cliccate su Nuovo, e copiate il seguente codice:
Salvate con un bel nome. A questo punto, nella finestra di gestione macro, se scegliete la vostra compaiono due funzioni: selezionate la funzione SelectionCount e vi da una statistica di tutte le parole e lettere.Codice: Seleziona tutto
' Based on the original* "dvwc" macro by Daniel Vogelheim *see end of doc ' Displays a message box with number of words & characters ' in the document and the current selection. ' John Vigor edited this in 2003 to provide both a character count ' and a character count with exclusions. DV's had one of these. ' Does not normally count in frames, headers, footers or footnotes ' although these items may be individually selected. Selected text ' cannot exceed 64K of characters. (About 18 dense single spaced pages ' using New Times Roman size 12 and 1 inch margins all around. This ' size takes about 20 seconds on a 770MHz machine, so go get a cup ' of coffee or just be patient.) ' OO's word count, as of OO1.1 rc4, does not count in fields but does ' count in the other areas mentioned above. OO's character count ' counts a line break (Shift+Enter) as a character (Issue filed #16918). Sub SelectionCount 'DEFINE CHARACTER COUNT BELOW. The default exclusions from character count are 'spaces & tabs, i.e., one of each of these is contained in the definition of e$. 'You can add characters between the quotes and/or delete the space and/or tab. e$ = Chr(32) + Chr(9) ' Chr(32) is a space, Chr(9) is a tab. Valid replacements would 'be e$ = Chr(32) or e$ = Chr(9) or e$ = "" with the latter being no exclusions. If you 'did not change e$ and if the line below read: ' sExcludeFromCharacterCount$ = e$ + "a" then spaces, tabs and the letter "a" would not 'be counted. sExcludeFromCharCount$ = e$ + " " 'DEFINE WORD SEPERATORS BELOW. The default word separators are spaces and 'hyphens (true hyphenated words like "half-dollar" will be counted as two words 'instead of one). You can add separators between the quotes and/or delete the hyphen. 'Examples: "/" to count "and/or" as two words. "&" to count "Johnson & Johnson" as 'two words instead of three. A period is not normally needed but you can add one 'to count "www.website.com" as three words instead of one. sWordSeps = " -" ' This section is basically all DV's code with small modifications needed by JV sWordSeps = sWordSeps + chr(9) + chr(10) + chr(13)'a tab, line break and paragraph break sNeverCountChars = chr(10) & chr(13)'never include line or paragraph breaks in char count oDocument = thisComponent oSelection = oDocument.getCurrentSelection() nSelCount = oSelection.getCount() ' access the program's document statistics nAllChars = oDocument.CharacterCount nAllWords = oDocument.WordCount ' initialize counts nSelWords = 0 : nSelChars = 0 : nSelCharEx = 0 ' iterate over multiple selections Do sText = oSelection.getByIndex(nSel).getString() ' count word in sText by scanning the selected text character for character nCount = Len(sText) bLastWasSeparator = true bWord = false 'first letter starts a word i = 1 Do ' DV used different logic for this section and there was nothing wrong ' with it. A programing exercise for JV and it better fit his needs. sChr = Mid(sText,i,1) If instr(sWordSeps, sChr) = 0 then 'if true then it's part of a word bWord = true GoSub CountIt 'count this character? Elseif bWord = True then 'is a seperator and at end of word. nSelWords = nSelWords + 1 bWord = false GoSub CountIt Else GoSub CountIt 'is seperator but not the at end of a word. EndIf ' End of JV's logic. i = i + 1 Loop Until i > nCount 'get the next character in the string nSel = nSel + 1 Loop while nSel < nSelCount ' Begin JV stuff if bWord then nSelWords = nSelWords + 1 sExclude$ = " " if Len(sExcludeFromCharCount$) = 0 then sExclude$ = "* No exclusions." else sExclude$ = Build_sExclude(sExcludeFromCharCount$) endif ' JV altered DV's message box. sT = chr(9): sP = chr(13) 'a Tab and Paragraph Break a$ = "Program Document Count" + sP + sT & " All words: " + nAllWords + sP b$ = sT & " All chars: " + nAllChars + sP + "Macro Selection Count" + sP sMsg = a$ & b$ If nSelChars > 0 then a$ = sT & " Words: " + nSelWords + sP + sT & " Chars: " + nSelChars + sP + sT b$ = " * Chars: " + nSelCharEx + sP & sExclude$ sMsg = sMsg + a$ + b$ Else a$ = "No text was selected or the selection" & sP & sT & "exceeded 64K characters." sMsg = sMsg + sT & a$ EndIf msgbox sMsg Exit Sub CountIt: 'Going to count this character/excluded char count? Select Case instr(sNeverCountChars,sChr) case = 0 If instr(sExcludeFromCharCount$, sChr) = 0 then nSelCharEx = nSelCharEx + 1 : nSelChars = nSelChars + 1 Else nSelChars = nSelChars + 1 Endif End Select Return End Sub ' This JV function constructs the string that shows ' the excluded characters for the character count. Function Build_sExclude(sExcludeFromCharCount$) sExclude$ = "* Excluding " sOthers = sExcludeFromCharCount$ iPos = instr(sOthers," ") If iPos > 0 then Mid(sOthers,iPos,1,"") select Case len(sOthers) case 0 : sExclude$ = sExclude$ & "spaces." case > 0: If instr(sOthers,chr(9)) = 0 then sExclude$ = sExclude$ & "spaces and " Else sExclude$ = sExclude$ & "spaces" EndIf end select EndIf iPos = instr(sOthers,chr(9)) If iPos > 0 then Mid(sOthers,iPos,1,"") Select Case len(sOthers) Case 0 : If len(sExclude$) < 13 then sExclude$ = sExclude$ & "tabs." Else sExclude$ = sExclude$ & " and tabs." EndIf Case > 0: If len(sExclude$) < 13 then sExclude$ = sExclude$ & "tabs and " Else sExclude$ = sExclude$ & ", tabs and " EndIf End Select EndIf Build_sExclude = sExclude$ & sOthers End Function
Ora, se volete escludere gli spazi, dovete selezionare il testo, quindi eventualmente selezionate tutto il documento (un bel CTRL+a dovrebbe bastare), e rieseguite la stessa funzione. Ora nella finestra, oltre al conteggio globale, dovrebbe comparire il conteggio della selezione, con il conteggio dei caratteri spazi esclusi.
Se volete escludere altri caratteri (tipo le virgole), cercate la riga
e aggiungete i vari caratteri che volete escludere. Se poi avrò tempo la sistemerò meglio, per fare il lavoro anche senza bisogno di selezionare manualmente tutto il documento.Codice: Seleziona tutto
sExcludeFromCharCount$ = e$ + " "
Daniele
grazie mille
Chi c’è in linea
Visualizzano questa sezione: Google [Bot] e 6 ospiti