| View previous topic :: View next topic |
| Author |
Message |
Iannz OOo Advocate

Joined: 14 Feb 2004 Posts: 494 Location: Christchurch, New Zealand
|
Posted: Mon Jun 28, 2004 1:50 am Post subject: AutoCorrect import macro? |
|
|
In a Writer thread
http://www.oooforum.org/forum/viewtopic.php?t=6459 Kyle asked about importing autocorrect entries from Word to Writer.
This seems like such a common thing to do that I feel sure that someone must have written a macro to help import Autocorrect entries. So if you know about such a macro please let us know where we can access it from.
If there isn't such a macro in existence, here is my research so far:
There is a Word macro available from http://word.mvps.org/FAQs/Customization/ExportAutocorrect.htm for creating a Word document with the AutoCorrrect entries.
OOo Autocorrect files are typically stored in ./user/autocorr/acorrXXXX.dat where XXXX corresponds to the number for a given locale. These files are zipped and contains the file
DocumentList.xml, which looks like:
<block-list:block-list>
<block-list:block block-list:abbreviated-name="(C)" block-list:name="©"/>
<block-list:block block-list:abbreviated-name="yuor" block-list:name="your"/>
</block-list:block-list>
So it would not be too difficult to create a text file to look like this and to zip it into a acorrXXXX.dat file. But, a better approach would be using the API but I haven't been able to find anything in the API - xConversionDictionary maybe? _________________ Cheers, Ian
http://wiki.services.openoffice.org/wiki/Extensions_development_basic a wiki about writing OpenOffice.org extensions. |
|
| Back to top |
|
 |
patb General User

Joined: 01 Aug 2004 Posts: 32 Location: Canberra, Aus.
|
Posted: Sun Aug 01, 2004 5:45 pm Post subject: |
|
|
| Thanks Ian. Newbie here. I tried inserting my 2,800 Word autotext entries into my DocumentList.xml and rezipping acorrXXXX.dat. That much worked fine but only the first hundred or so autocorrect entries appeared in Writer. Is there something which limits the number of autocorrect entries in Writer? Cheers, Pat. |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3208 Location: Troyes France
|
|
| Back to top |
|
 |
patb General User

Joined: 01 Aug 2004 Posts: 32 Location: Canberra, Aus.
|
Posted: Mon Aug 02, 2004 2:30 pm Post subject: |
|
|
Thanks Serge. But as Ian has pointed out on another thread, DicOOo by Laurent Godard seems to deal with dictionaries, not autocorrect entries. Ian's question remains valid: Has anyone written a macro to help import Autocorrect entries from Word?
My rather mechanical attempt to import a lot of them using Ian's information failed because there seems to be some limit on the number of autocorrect entries in Writer. Can anyone suggest how to get around this? Cheers, Pat. (Newbie). |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3208 Location: Troyes France
|
|
| Back to top |
|
 |
patb General User

Joined: 01 Aug 2004 Posts: 32 Location: Canberra, Aus.
|
Posted: Thu Sep 08, 2005 2:49 pm Post subject: AutoCorrect import macro? |
|
|
Has anyone written a macro to help import Autocorrect entries from Word? Over a year on, this question still seems valid for people like me who have to use Word on one computer and Writer on another.
In several recent versions of Writer including the latest beta, I have tried exactly the method described by Ian ie inserting my 2,800 Word autotext entries into the file DocumentList.xml and rezipping acorrXXXX.dat. But on opening Writer, the autocorrect list always gets cut back to the first 240 entries. The rest get cut off.
Writer can hold more than 240 autocorrect entries because I can manually add more, one at a time. But what I want is a reliable method to import a large number of entries at once to update the entire list.
Can anyone suggest a solution to this?
Cheers, Pat. |
|
| Back to top |
|
 |
patb General User

Joined: 01 Aug 2004 Posts: 32 Location: Canberra, Aus.
|
Posted: Fri Dec 30, 2005 12:56 am Post subject: |
|
|
For anyone who is interested, I have unearthed a little more information about how to import large numbers of autocorrect entries from Word to Writer. My previous complaint about some sort of limit on the number of autocorrect entries being imported from Word arose because some characters need to be encoded for inclusion in the DocumentList.xml file (which Ian refers to in this thread). If there are any offending characters in the file, importation stops there. So the steps involved in importing go something like this:
1. Use the Word macro at http://word.mvps.org/FAQs/Customization/ExportAutocorrect.htm to create a Word document with the AutoCorrrect entries.
2. In this document, delete everything down to and including the header row of the table, delete the third column in the table and strip out all of the following characters: tabs, hard returns, inverted commas, ampersands, double quotation marks, single quotation mark (ie apostrophes), angle brackets. (I cannot guarantee this list is complete and there seem to be slight differences between Writer versions).
3. Then convert the table to text and use find and replace to put the entries in the format for the DocumentList.xml as illustrated by Ian in this thread. The final text should be saved as a text file called "DocumentList.xml".
4. If steps 2 and 3 sound a bit onerous, they are, so running the VB macro below might prove useful as a fairly rough way of achieving most of these steps. It should replace most of the "offending characters" with the correct code for OO Writer 2. It replaces tabs with "INSERT_TAB_HERE" and hard returns with "INSERT_RETURN_HERE". You can do some surgery on those in Writer's replacement table later. You will also have to manually repair any special formatting and graphics later.
5. You will probably need to convert the text file "DocumentList.xml" to have LF not CR/LF as carriage returns. This can be done in Writer itself - save as text encoded format and select LF.
6. Back up the existing Writer autocorrect file which is called .../user/autocorr/acor_XX-XX.dat where "XX-XX" corresponds to the language locale.
7. Zip the text file "DocumentList.xml" into the file .../user/autocorr/acor_XX-XX.dat .
8. Restart Writer and see what you have in the autocorrect replacement table. If it seems to have stopped part way through, see step 2. Good luck!
In Conclusion: This is a really basic, onerous, flawed and generally unsatisfactory way of getting Word autocorrect entries to Writer en masse. It would still be great to hear from anyone who has written a macro to help import Autocorrect entries from Word more smoothly and simply. Any other comments/suggestions also most welcome. Cheers, Pat.
--------
Here's the VB macro:
| Code: |
Sub AutoCorr2DocList()
' date_051226
' Delete any headers and footers (which tend to get printed with the saved text document)
Selection.HomeKey Unit:=wdStory
On error resume next
ActiveWindow.Panes(2).Close
ActiveWindow.ActivePane.View.Type = wdPrintView
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.View.Type = wdNormalView
' Delete first few lines of file
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Name"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
' Delete right hand (3rd) column
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.Columns.Delete
' Delete rows with hard returns - unrem next 4 to omit all entries with hard returns
' Selection.Find.Text = "^p"
' Selection.Find.Execute
' Selection.EndKey Unit:=wdStory, Extend:=wdExtend
' Selection.Delete Unit:=wdCharacter, Count:=1
' Replace the obstreporous characters
' Note: the replacement text here is different for OO Writer on Linux vs Windows.
' It is probably different for different versions of OO Writer.
' This seems okay for OO Writer 2 on Linux:
Selection.HomeKey Unit:=wdStory
Selection.Find.Text = "&"
Selection.Find.Replacement.Text = "&"
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Text = """"
Selection.Find.Replacement.Text = """
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Text = "<"
Selection.Find.Replacement.Text = "<"
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Text = ">"
Selection.Find.Replacement.Text = ">"
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Text = "'"
Selection.Find.Replacement.Text = "'"
Selection.Find.Execute Replace:=wdReplaceAll
' Replace all hard returns and tabs with markers
Selection.Find.Text = "^p"
Selection.Find.Replacement.Text = "INSERT_RETURN_HERE"
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Text = "^t"
Selection.Find.Replacement.Text = "INSERT_TAB_HERE"
Selection.Find.Execute Replace:=wdReplaceAll
' Convert table to text
Selection.HomeKey Unit:=wdStory
Selection.Rows.ConvertToText Separator:=wdSeparateByTabs, NestedTables:= _
True
' Convert to OO DocumentList format
Selection.HomeKey Unit:=wdStory
Selection.TypeParagraph
Selection.HomeKey Unit:=wdStory
Selection.Find.Text = "^p"
Selection.Find.Replacement.Text = "SuffixHere01^pPrefixHere01"
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Text = "^t"
Selection.Find.Replacement.Text = "InfixHere01"
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Text = "PrefixHere01"
Selection.Find.Replacement.Text = _
" <block-list:block block-list:abbreviated-name="""
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Text = "InfixHere01"
Selection.Find.Replacement.Text = """ block-list:name="""
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Text = "SuffixHere01"
Selection.Find.Replacement.Text = """/>"
Selection.Find.Execute Replace:=wdReplaceAll
Selection.HomeKey Unit:=wdStory
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="<block-list:block-list>"
Selection.TypeParagraph
Selection.EndKey Unit:=wdStory
Selection.TypeParagraph
Selection.TypeText Text:="<block-list:block-list>"
' Delete trailling mess
Selection.EndKey Unit:=wdStory
Selection.HomeKey Unit:=wdLine
Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
'Save doc as DocumentList.xml in text format
ActiveDocument.SaveAs FileName:="DocumentList.xml", FileFormat:= _
wdFormatText
MsgBox ("With luck this file has now been saved as DOCUMENTLIST.XML in text format."), , "Finished"
End Sub
|
Last edited by patb on Thu Aug 21, 2008 9:26 pm; edited 1 time in total |
|
| Back to top |
|
 |
tikkiro Newbie

Joined: 08 Jan 2006 Posts: 1
|
Posted: Sun Jan 08, 2006 4:21 pm Post subject: SOooo pleased to find this :) |
|
|
Well - haven't actually tried it out as yet, but assuming it will work ok - now wondering if anyone has done anything similar for AutoText entries?? I use both these functions heavily in Word because of being disabled, and now having possible RSI or carpal tunnel to boot, definitely want to ensure I can still use them as much as possible. The concept of having to redo either file just doesn't appeal and would be enough to ensure I hang on to Office for the foreseeable future - other than this issue, I'm just about ready to consider a full switch over to Linux - only used it for a week, but totally impressed given the amount of times I'd read about it not being of much use etc. So if anyone knows any way of transferring across the AutoText entries please spill the beans. I've zilch knowledge about VB but am hoping it won't prove too tough to sort out given the excellent walk-through instructions you've provided Pat.
S'okay - just did what I should have first off and have discovered loads of others there before me and got the fix (I think) again. Just got to try this one now tomorrow and see what happens! |
|
| Back to top |
|
 |
drRob Newbie

Joined: 29 Apr 2006 Posts: 3
|
Posted: Sat Apr 29, 2006 9:53 am Post subject: went through the conversion procedure and... |
|
|
"4. If steps 2 and 3 sound a bit onerous, they are, so running the VB macro below might prove useful as a fairly rough way of achieving most of these steps. It should replace most of the "offending characters" with the correct code for OO Writer 2. It replaces tabs with "INSERT_TAB_HERE" and hard returns with "INSERT_RETURN_HERE". You can do some surgery on those in Writer's replacement table later. You will also have to manually repair any special formatting and graphics later.
---- This ran ok after making some minor changes to code such as removing carriage returns.
It returned text like the following:
<block-list:block block-list:abbreviated-name="absence"/>
<block-list:block block-list:abbreviated-name="absorption"/>
<block-list:block block-list:abbreviated-name="abundance"/>
<block-list:block block-list:abbreviated-name="abutting"/>
<block-list:block block-list:abbreviated-name="acceptance"/>
<block-list:block block-list:abbreviated-name="accessories"/>
<block-list:block block-list:abbreviated-name="accident"/>
<block-list:block block-list:abbreviated-name="accidentally"/>
<block-list:block block-list:abbreviated-name="accommodate"/>
<block-list:block block-list:abbreviated-name="according to"/>
The text seems to exclude the uncorrected (left) column from my word autocorrect file.
5. You will probably need to convert the text file "DocumentList.xml" to have LF not CR/LF as carriage returns. This can be done in Writer itself - save as text encoded format and select LF.
Saved appropriately, I think
6. Back up the existing Writer autocorrect file which is called .../user/autocorr/acor_XX-XX.dat where "XX-XX" corresponds to the language locale. Done.
7. Zip the text file "DocumentList.xml" into the file .../user/autocorr/acor_XX-XX.dat .
What does Zip mean in this circumstance ??-
I renamed ‘documentlist.xml to the autocorrect file name (acor_XX-XX.dat) and it didn’t work (nothing viewable in the autocorrect viewer/editor), probably not what I needed to do.
When I tried to open the .dat file, to see if it looked the same, OO said the file is corrupted, which it didn’t report when went to open my file renamed to .dat. Obviously the native .dat autocorrect file is in a proprietary format.
Does ZIP in this case mean appending the info in the file that I created into the existing .dat file? If so how do I do it?
 |
|
| Back to top |
|
 |
drRob Newbie

Joined: 29 Apr 2006 Posts: 3
|
Posted: Sat Apr 29, 2006 10:38 am Post subject: Found one mistake |
|
|
| I had manually deleted the first few rows of the word autocorr backup AND the 3rd column. Didnt realize the macro had done EVERYTHING. I'll see if my results are better now... |
|
| Back to top |
|
 |
patb General User

Joined: 01 Aug 2004 Posts: 32 Location: Canberra, Aus.
|
Posted: Sat Apr 29, 2006 4:16 pm Post subject: |
|
|
Rob,
| Quote: | | I renamed ‘documentlist.xml to the autocorrect file name (acor_XX-XX.dat) and it didn’t work |
That won't work because acor_XX-XX.dat is a zipped or compressed file which contains several different files, among them documentlist.xml. If you are in Windows, try using something like Winzip or PKzip to open acor_XX-XX.dat. In Linux, I use Gnome's File Roller. You will need to replace the old documentlist.xml with your modified new one. Then save the compressed file acor_XX-XX.dat
Sorry this is so awkward but I have not found any simple way to copy autocorrect entries from Word to Writer.
Cheers, Pat. |
|
| Back to top |
|
 |
patb General User

Joined: 01 Aug 2004 Posts: 32 Location: Canberra, Aus.
|
Posted: Sat Jul 22, 2006 7:45 pm Post subject: |
|
|
For anyone else who is interested, I have written Plan B to import autocorrect entries from MS Word to OOo Writer. The VB macro earlier in this thread was really awkward so I've written the following macro for Writer. This is just bit more friendly and automatic in operation, although it is still necessary to manually edit one temporary file. The macro is written for Writer on Linux, not Windows, and I imagine might need much editing to work on Windows. My coding shortcomings are well illustrated via my own comments in the macro! If you want to use it, you will need to read the comments and change things like home directory location, language locale and the name of your editor program. Any suggestions for improvements would be most welcome.
Cheers, Pat.
| Code: | sub ImportACLfromWord
'Works for me with OOo 2.0.2 run on Linux (Ubuntu 6.0.6) where user is "pat"
' and selected language/country locale is en-AU (English Australian)
'Before running, replace all "/pat/" in this code with "/[YourUserName]/."
'Then replace all "en-AU" in this code with "[YourLocale]".
'I had to create catdl.sh an executable file in /home/pat/.openoffice.org2/user/autocorr/
' Content is: "cat DocumentListPart1 DocumentListPart2 > DocumentList.xml"
'I also had to create an empty OOo Calc document called "dummy.ods"
' in /home/pat/.openoffice.org2/user/autocorr/
'The macro selects the unformatted entries (ie RTF='False' elements) in MS
' Word's AutoCorrect Backup Document and transposes these to a text document
' called DocumentList.xml which is then zipped into
' //.openoffice.org2/user/autocorr/acor_en-AU.dat.
'Back up your //.openoffice.org2/user/autocorr/acor_xx-xx.dat before you start.
'It does not transpose formatted entries. I suggest you do this manually.
'Use MS Word to back up your Word autocorrect list using the macro at
' http://word.mvps.org/FAQs/Customization/ExportAutocorrect.htm
'Then open that document in Writer and run this macro. The only ongoing
' manual bit is to delete the headers of one file. I use Emacs - see
' note below. Sorry about that.
'Good luck! No Warranty!
dim document as object
dim dispatcher as object
dim vcursor, txtype as object
dim msg, seln as string
Dim CalcDoc As Object
Dim CalcUrl As String
Dim OpenDummy()
dim GoRLUD(1) as new com.sun.star.beans.PropertyValue
dim TypeText(0) as new com.sun.star.beans.PropertyValue
dim argsrepl(18) as new com.sun.star.beans.PropertyValue
dim gotocell(0) as new com.sun.star.beans.PropertyValue
dim EnterStr(0) as new com.sun.star.beans.PropertyValue
dim SaveFileAs(3) as new com.sun.star.beans.PropertyValue
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
'If the table is large, these steps can take minutes. Pls be patient.
'go top of doc
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())
'del first two lines then go top again
GoRLUD(0).Name = "Count"
GoRLUD(0).Value = 1
GoRLUD(1).Name = "Select"
GoRLUD(1).Value = true
dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, GoRLUD())
dispatcher.executeDispatch(document, ".uno:Delete", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:Delete", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())
'check you are now in a table and abort if not.
vcursor = ThisComponent.currentcontroller.getViewCursor()
txtype = ThisComponent.Text.createEnumeration.nextElement
msg = "You don't seem to be in a table. " & _
chr(10) & "The open document should be the AutoCorrect Backup Document " & _
chr(10) & " created by MS Word" & _
chr(10) & "The macro may need tweaking." & _
chr(10) & "Aborting......"
If not txtype.supportsService("com.sun.star.text.TextTable") Then
MsgBox ( msg, 0, "ERROR!")
exit sub
End If
'Delete header row
dispatcher.executeDispatch(document, ".uno:DeleteRows", "", 0, Array())
'insert one dummy "true" in col 3 because I don't know how to check if none found later.
dispatcher.executeDispatch(document, ".uno:SelectTable", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:GoToEndOfLine", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array())
TypeText(0).Name = "Text"
TypeText(0).Value = "True"
dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, TypeText())
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array())
'we should be in 3rd col of table
'search for "true" in col 3
dispatcher.executeDispatch(document, ".uno:EntireColumn", "", 0, Array())
argsrepl(0).Name = "SearchItem.StyleFamily"
argsrepl(0).Value = 2
argsrepl(1).Name = "SearchItem.CellType"
argsrepl(1).Value = 0
argsrepl(2).Name = "SearchItem.RowDirection"
argsrepl(2).Value = true
argsrepl(3).Name = "SearchItem.AllTables"
argsrepl(3).Value = false
argsrepl(4).Name = "SearchItem.Backward"
argsrepl(4).Value = false
argsrepl(5).Name = "SearchItem.Pattern"
argsrepl(5).Value = false
argsrepl(6).Name = "SearchItem.Content"
argsrepl(6).Value = false
argsrepl(7).Name = "SearchItem.AsianOptions"
argsrepl(7).Value = false
argsrepl(8).Name = "SearchItem.AlgorithmType"
argsrepl(8).Value = 0
argsrepl(9).Name = "SearchItem.SearchFlags"
argsrepl(9).Value = 71680
argsrepl(10).Name = "SearchItem.SearchString"
argsrepl(10).Value = "True"
argsrepl(11).Name = "SearchItem.ReplaceString"
argsrepl(11).Value = ""
argsrepl(12).Name = "SearchItem.Locale"
argsrepl(12).Value = 255
argsrepl(13).Name = "SearchItem.ChangedChars"
argsrepl(13).Value = 2
argsrepl(14).Name = "SearchItem.DeletedChars"
argsrepl(14).Value = 2
argsrepl(15).Name = "SearchItem.InsertedChars"
argsrepl(15).Value = 2
argsrepl(16).Name = "SearchItem.TransliterateFlags"
argsrepl(16).Value = 1280
argsrepl(17).Name = "SearchItem.Command"
argsrepl(17).Value = 0
argsrepl(18).Name = "Quiet"
argsrepl(18).Value = true
dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, argsrepl())
'delete all rows from first "true" to end of table
dispatcher.executeDispatch(document, ".uno:EndOfDocumentSel", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:DeleteRows", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array())
'again we should be in 3rd col of table
'delete 3rd col
dispatcher.executeDispatch(document, ".uno:DeleteColumns", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())
'Replace Offending Chars
argsrepl(9).Name = "SearchItem.SearchFlags"
argsrepl(9).Value = 65536
argsrepl(10).Name = "SearchItem.SearchString"
argsrepl(10).Value = CHR$(38)
argsrepl(11).Name = "SearchItem.ReplaceString"
argsrepl(11).Value = "&"
argsrepl(17).Name = "SearchItem.Command"
argsrepl(17).Value = 3
dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, argsrepl())
argsrepl(10).Value = CHR$(34)
argsrepl(11).Value = """
dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, argsrepl())
argsrepl(10).Value = CHR$(60)
argsrepl(11).Value = "<"
dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, argsrepl())
argsrepl(10).Value = CHR$(62)
argsrepl(11).Value = ">"
dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, argsrepl())
argsrepl(10).Value = CHR$(39)
argsrepl(11).Value = "'"
dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, argsrepl())
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())
'check you are in a table and abort if not.
msg = "You don't seem to be in a table." & _
chr(10) & "The macro may need tweaking." & _
chr(10) & "Aborting macro......"
If not txtype.supportsService("com.sun.star.text.TextTable") Then
MsgBox ( msg, 0, "ERROR!")
exit sub
End If
dispatcher.executeDispatch(document, ".uno:SelectTable", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())
document.close(true)
'The following file must already exist. If it doesn't, create it.
CalcUrl = "/home/pat/.openoffice.org2/user/autocorr/dummy.ods"
CalcDoc = StarDesktop.loadComponentFromURL(CalcUrl, "_blank", 0, OpenDummy())
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
'fill first 2 lines
gotocell(0).Name = "ToPoint"
gotocell(0).Value = "$A$1"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, gotocell())
EnterStr(0).Name = "StringName"
EnterStr(0).Value = "<?xml version=""1.0"" encoding=""UTF-8""?>"
dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, EnterStr())
gotocell(0).Value = "$A$2"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, gotocell())
EnterStr(0).Value = "<block-list:block-list xmlns:block-list=""http://openoffice.org/2001/block-list"">"
dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, EnterStr())
'If the table is large, these steps can also take minutes. Pls be patient.
'fill col B and D
gotocell(0).Value = "$B$3"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, gotocell())
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())
GoRLUD(0).Name = "By"
GoRLUD(0).Value = 1
GoRLUD(1).Name = "Sel"
GoRLUD(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, GoRLUD())
dispatcher.executeDispatch(document, ".uno:InsertColumns", "", 0, Array())
'fill col A
gotocell(0).Value = "$A$3"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, gotocell())
EnterStr(0).Value = " <block-list:block block-list:abbreviated-name="""
dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, EnterStr())
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, GoRLUD())
GoRLUD(1).Value = true
dispatcher.executeDispatch(document, ".uno:GoToEndOfData", "", 0, GoRLUD())
dispatcher.executeDispatch(document, ".uno:GoLeftToStartOfData", "", 0, GoRLUD())
dispatcher.executeDispatch(document, ".uno:GoLeftToStartOfData", "", 0, GoRLUD())
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())
'fill col C
gotocell(0).Value = "$C$3"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, gotocell())
EnterStr(0).Value = """ block-list:name="""
dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, EnterStr())
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, GoRLUD())
dispatcher.executeDispatch(document, ".uno:GoToEndOfData", "", 0, GoRLUD())
dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, GoRLUD())
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())
'fill col E
gotocell(0).Value = "$E$3"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, gotocell())
EnterStr(0).Value = """/>"
dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, EnterStr())
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, GoRLUD())
dispatcher.executeDispatch(document, ".uno:GoToEndOfData", "", 0, GoRLUD())
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())
'fill last line ' disabled now
GoRLUD(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, GoRLUD())
dispatcher.executeDispatch(document, ".uno:GoLeftToStartOfData", "", 0, GoRLUD())
EnterStr(0).Value = "</block-list:block-list>"
'dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, EnterStr())
'Save As Text
SaveFileAs(0).Name = "URL"
SaveFileAs(0).Value = "file:///home/pat/.openoffice.org2/user/autocorr/DocumentListPart1"
SaveFileAs(1).Name = "FilterName"
SaveFileAs(1).Value = "Text - txt - csv (StarCalc)"
SaveFileAs(2).Name = "FilterOptions"
SaveFileAs(2).Value = "0,0,76,0"
SaveFileAs(3).Name = "SelectionOnly"
SaveFileAs(3).Value = true
dispatcher.executeDispatch(document, ".uno:SaveAs", "", 0, SaveFileAs())
'We now have the Word replacement list saved as DocumentListPart1
'We are constructing a new DocumentList.xml with Word's replacement list at top. Then ALL of
' Writer's existing replacement list entries underneath. Otherwise we lose Writer's formatted
' autocorrect entries. So we have a lot of duplicates which Writer will automatically remove
' at the next change to its replacement table. Second duplicate is the one discarded, hence we
' put the Word list at the top.
'These shell commands should be run synchronously. How?
'I have put message boxes between them to slow things down.
shell("gnome-terminal --working-directory=/home/pat/.openoffice.org2/user/autocorr/ -x unzip -o acor_en-AU.dat DocumentList.xml",1,)
msg = "Wait a few moments... Will rename old DocumentList.xml"
MsgBox ( msg, 0, "Creating new acor_en-AU.dat")
shell("gnome-terminal --working-directory=/home/pat/.openoffice.org2/user/autocorr/ -x mv DocumentList.xml DocumentListPart2",1,)
msg = "Wait a few moments... Will open old DocumentList.xml... DELETE FIRST TWO INTRODUCTORY ""<HEADER>"" BITS AND SAVE BUFFER."
MsgBox ( msg, 0, "Creating new acor_en-AU.dat")
'Need an editor which will open *.xml as text. Emacs, Nano, Vi, etc. Not Gedit.
'Pls change the next shell command if you don't have Emacs.
'you need to delete these bits at the start of the file DocumentListPart2:
' <?xml version="1.0" encoding="UTF-8"?>
' <block-list:block-list xmlns:block-list="http://openoffice.org/2001/block-list">
'Is there a Linux command which will delete the first x characters of a text file?
shell("emacs /home/pat/.openoffice.org2/user/autocorr/DocumentListPart2",1,)
msg = "Wait a few moments... Will join 2 parts."
MsgBox ( msg, 0, "Creating new acor_en-AU.dat")
'I don't know why next commented line does not work. I created a script file catdl.sh to get around it.
'shell("gnome-terminal --working-directory=/home/pat/.openoffice.org2/user/autocorr/ -x cat DocumentListPart1 DocumentListPart2 > DocumentList.xml",1,)
shell("gnome-terminal --working-directory=/home/pat/.openoffice.org2/user/autocorr/ -x bash ./catdl.sh",1,)
msg = "Wait a few moments... Will zip new DocumentList.xml into acor_en-AU.dat."
MsgBox ( msg, 0, "Creating new acor_en-AU.dat")
shell("gnome-terminal --working-directory=/home/pat/.openoffice.org2/user/autocorr/ -x zip acor_en-AU.dat DocumentList.xml",1,)
'next 3 lines just for studying the mess.
'msg = "Wait a few moments... Will unzip new DocumentList.xml to check"
'MsgBox ( msg, 0, "Creating new acor_en-AU.dat")
'shell("gnome-terminal --working-directory=/home/pat/.openoffice.org2/user/autocorr/ -x unzip -o acor_en-AU.dat DocumentList.xml",1,)
beep
document.close(true)
end sub
|
_________________ OOo 2.4.1 on Ubuntu Linux 8.04
"It's never too late to have a happy childhood" - bumper sticker, Zimbabwe. |
|
| Back to top |
|
 |
Zarius OOo Enthusiast


Joined: 21 Jan 2005 Posts: 142 Location: Brisbane, Australia
|
Posted: Tue Jul 25, 2006 9:10 pm Post subject: |
|
|
Hi patb, hope you don't mind me taking liberties with your code, but as a learning exercise I refactored & generalised the code above and have posted it to the Code Snippets forum here: Word AutoCorrect import macro.
I still want to tweak a couple of bits, but it works independent of OS now, and independent of locale (for OO2.x at this stage). _________________ Zarius Tularial. (WinXP - OOo 1.1.4, FedoraCore 4 - OOo 2.0, RHEL4 - StarOffice 7)
Quoots - a quicker way to open your documents and fill in template details in OOo. (written in OOBasic) |
|
| Back to top |
|
 |
patb General User

Joined: 01 Aug 2004 Posts: 32 Location: Canberra, Aus.
|
Posted: Wed Jul 26, 2006 2:18 pm Post subject: |
|
|
| Zarius wrote: | | Hi patb, hope you don't mind me taking liberties with your code. |
Absolutely no problem, Zarius. On the contrary, a big Thank you! I am really pleased that someone with better coding skills than mine has taken this up. It has been bugging me for a while. I hope it helps others. Cheers, Pat. _________________ OOo 2.4.1 on Ubuntu Linux 8.04
"It's never too late to have a happy childhood" - bumper sticker, Zimbabwe. |
|
| Back to top |
|
 |
Jim.Hitch General User


Joined: 29 Sep 2006 Posts: 10 Location: London, UK
|
Posted: Fri Sep 29, 2006 1:15 am Post subject: Importing autocor entries from word. |
|
|
Firstly thanks to Patb & Zarius for your work. I'm doing my best to move from Word to OO, but without autocorrect entries am infuriated. I'm running XP and the code for the macro was all going swimmingly until i got a runtime error at the line
oArgs = Array(_
I have no real knowledge of code. Can anyone help?
Jim |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|