| View previous topic :: View next topic |
| Author |
Message |
netbeansfan General User

Joined: 05 May 2012 Posts: 7
|
Posted: Sat May 05, 2012 7:03 am Post subject: How to open text file in OpenOffice Write and keep format? |
|
|
Hi All,
I would like to find out how to get OpenOffice Writer to carry out the following tasks from a Windows XP command prompt:
( i ) open up a ASCII file generated from Java application, say C:\Temp\ABC.TXT without prompting to accept Character set (language, font,
estern Europe(Windows-1252/WinLatin 1), Dedault fonts (Times New Roman), Language (English Australia), Paragraph break (LF).
Below is the command used to achieve this task:
"C:\Program Files\OpenOffice.org 3\program\soffice.exe" "c:\Temp\ABC.TXT"
( ii ) Why is the alignment of this file in general especially towards the end of each line are no longer intact after opening up in OpenOffice?
Correct format in Wordpad of this text file
| Code: | +-----------------------------------------------------------------------------++
¦Schedule |Description | Full ¦¦
¦---------|--------------------------------------------------------|--------- ¦¦
¦TOTAL | | 58.05 ¦¦
¦---------|--------------------------------------------------------|--------- ¦¦
¦12345 |Potasium | 50.05 ¦¦
¦34256 |PEI COLLECTION CENTRE | 8.00 ¦¦
¦---------------------------------------------------------------------------- ¦¦
¦TEST BILLING - Patient: Marry Jones ¦¦
¦ Request: 11 Collection Centre: CCC -C-CAYLAX COLLECTION CENTR ¦¦
¦ Doctor: CATT -DR COMPUTER TESTING, ADDRESS 70 Years Service: 04/05/12 ¦¦
¦ A/c: C - OTHER COMPENSABLE ¦¦
¦ Panels: [N]¦¦
+-----------------------------------------------------------------------------++ |
Wrong format after opening up in OpenOffice but couldn't show
| Code: | +-----------------------------------------------------------------------------++
¦Schedule |Description | Full ¦¦
¦---------|--------------------------------------------------------|--------- ¦¦
¦TOTAL | | 58.05 ¦¦
¦---------|--------------------------------------------------------|--------- ¦¦
¦12345 |Potassium | 50.05 ¦¦
¦34256 |PEI COLLECTION CENTRE | 8.00 ¦¦
¦---------------------------------------------------------------------------- ¦¦
¦TEST BILLING - Patient: Marry Jones ¦¦
¦ Request: 11 Collection Centre: CCC -C-CAYLAX COLLECTION CENTR ¦¦
¦ Doctor: CATT -DR COMPUTER TESTING, ADDRESS 70 Years Service: 04/05/12 ¦¦
¦ A/c: C - OTHER COMPENSABLE ¦¦
¦ Panels: [N]¦¦
+-----------------------------------------------------------------------------++ |
( ii ) How to print c:\Temp\ABC.TXT using OpenOffice format without having to open it first possibly using soffice.exe -write -p c:\Temp\ABC.TXT .....
The purpose is to automate these tasks especially ( ii ) so that it is possible to run step ( ii ) without having to do ( i ).
I have looked up reference materials including startup switches but could not find any direct answer to this question.
Your assistance would be much appreciated.
Thanks,
Jack |
|
| Back to top |
|
 |
jrkrideau Super User

Joined: 08 Aug 2005 Posts: 6733 Location: Kingston ON Canada
|
Posted: Sun May 06, 2012 5:58 am Post subject: |
|
|
Just a wild guess but is there any chance your fonts are changing between notepad and OOo? _________________ jrkrideau
Kingston ON Canada
Currently using Windows 7 & OOo 3.4.0 and Ubuntu 12.04 & LibreOffice 3.5.2.2 |
|
| Back to top |
|
 |
DVezina OOo Advocate

Joined: 29 Sep 2006 Posts: 248 Location: Orlando
|
Posted: Mon May 07, 2012 7:30 am Post subject: |
|
|
i) I also noticed that in the first example you have "Potasium" and in the second example you have "Potassium". Make sure you have all the AutoCorrect options turned off.
ii) You don't need to open the file first to print.
| Code: | | soffice.exe -p C:\Temp\Document.txt |
If you find you need to open in OO and perform further processing on the file,
you can call an OpenOffice Basic macro from the command line. Something like:
| Code: | | "C:\Program Files\OpenOffice.org 3\program\swriter.exe" macro:///Standard.AddOnUtils.processFile("%1") |
Where %1 is your file name.
Your macro can then open the file with Hidden property set to true, perform desired processing (perhaps convert it to a real table & format it), print and close. |
|
| Back to top |
|
 |
netbeansfan General User

Joined: 05 May 2012 Posts: 7
|
Posted: Tue May 08, 2012 4:43 am Post subject: How to open text file in OpenOffice Write and keep format? |
|
|
Thanks for the responses from both jrkrideau and DVezina. Looks like your suggestion is close to what I am after.
The mis-alignment issue has been resolved by providing the following settings when prompted while opening C:\TEMP\ABC.txt:
| Code: | Western Europe(Windows-1252/WinLatin 1), Dedault fonts (Courier New), Language
(English Australia), Paragraph break (CR&LF). |
Nevertheless, I am looking for a similar command line to the above suggested codes to pass OO Writer those 4 opening settings without having (possibly in a macro) to open C:\TEMP\ABC.txt before printing to a nominated / default printer. Any idea on how this could be achieved?
Any examples would be much appreciated.
Thanks again,
Jack |
|
| Back to top |
|
 |
DVezina OOo Advocate

Joined: 29 Sep 2006 Posts: 248 Location: Orlando
|
Posted: Tue May 08, 2012 8:57 am Post subject: |
|
|
Is the name of the file you are trying to open really ABC.txt?
I ask because when I try to open files with .txt extension on my PC, OpenOffice doesn't ask me for those ascii filter options. I only get prompted for that info with files that have no extension or extensions that OO doesn't consider ASCII.
I notice that you have your operating system listed as Ubuntu. That could be the difference. You could probably mess with the linux "/etc/magic" file to define the file type.
If none of that works, then I think the option left is to not open with OO directly but call OO with a macro to open it for you with these settings. Let me know if you need help with that.
DVezina |
|
| Back to top |
|
 |
DVezina OOo Advocate

Joined: 29 Sep 2006 Posts: 248 Location: Orlando
|
Posted: Tue May 08, 2012 9:01 am Post subject: |
|
|
| Sorry - I see it is not you using Ubuntu but jrkrideau |
|
| Back to top |
|
 |
netbeansfan General User

Joined: 05 May 2012 Posts: 7
|
Posted: Tue May 08, 2012 11:48 pm Post subject: How to open text file in OpenOffice Write and keep format? |
|
|
Hi DVezina,
Thank you for your persistence in helping out in getting the OO Writer automation to work.
First of all, I am running Windows XP & 7. Secondly, the same ASCII filter option still took place even when opening up the actual filename (C:\Temp\JavaOutput.txt) with the following command line from a batch file:
"C:\Program Files\OpenOffice.org 3\program\swriter.exe" C:\Temp\JavaOutput.txt
Please provide the instruction to create OO Writer macro in order to accept / use the configured
| Code: | | (Western Europe(Windows-1252/WinLatin 1), Dedault fonts (Courier New), Language (English Australia), Paragraph break (CR&LF) | settings so that it is possible to print using OO Writer without having to open the text document up.
Many thanks again,
Jack |
|
| Back to top |
|
 |
DVezina OOo Advocate

Joined: 29 Sep 2006 Posts: 248 Location: Orlando
|
Posted: Thu May 17, 2012 11:04 am Post subject: |
|
|
Hi Jack,
This should get you started. Let me know how it works for you.
In My Macros -> Standard -> Module1 create a macro:
| Code: | Sub printdoc (sFilename as String)
Dim mArgs(3) as New com.sun.star.beans.PropertyValue
Dim oDoc
Dim oFrame
Dim s As String
Dim oDeskTop as Object
Dim printArray(0) As New com.sun.star.beans.PropertyValue
oDeskTop=CreateUnoService("com.sun.star.frame.Desktop")
mArgs(0).Name = "ReadOnly"
mArgs(0).Value = True
mArgs(1).Name = "MacroExecutionMode"
mArgs(1).Value = 4
mArgs(2).Name = "AsTemplate"
mArgs(2).Value = FALSE
mArgs(3).Name = "Hidden"
mArgs(3).Value = True
s = convertToURL(sFilename)
oDoc = oDeskTop.LoadComponentFromUrl(s, "_blank", 0, mArgs())
oDoc.print(printArray())
End Sub |
At Command line execute:
soffice -writer macro:///Standard.Module1.printdoc("C:\abc.txt") |
|
| Back to top |
|
 |
netbeansfan General User

Joined: 05 May 2012 Posts: 7
|
Posted: Sun May 20, 2012 7:35 pm Post subject: How to open text file in OpenOffice Write and keep format? |
|
|
Hi DVezina,
Yes, it worked like a chime as I intended without having to open up OO even though it is loaded in the background which is fine. However, there is a minor imperfection still where soffice.exe still hung around in Task Manager (Windows XP) not releasing C:\abc.txt to be deleted / overwrite by subsequent commands. As a result, is it possible to include additional instruction in this macro to close it after printing, or atleast release it so that it is available for another application / Java to make use of it? Otherwise, I will need to do some batch scripting to clear it from the system unless there is a soffice switch to close it.
Thank you so much already for having coming up with this solution,
Jack |
|
| Back to top |
|
 |
netbeansfan General User

Joined: 05 May 2012 Posts: 7
|
Posted: Sun May 20, 2012 8:03 pm Post subject: How to open text file in OpenOffice Write and keep format? |
|
|
Hi DVezina,
It is strange that the command "soffice -writer macro:///Standard.Module1.printdoc("C:\abc.txt")" runs fine in a DOS prompt but would not complete / end when in a batch script.
Just wonder if there is anything in the macro that can be done to release it and close OO Writer altogether.
Thanks again,
Jack |
|
| Back to top |
|
 |
netbeansfan General User

Joined: 05 May 2012 Posts: 7
|
Posted: Tue May 22, 2012 12:09 am Post subject: How to open text file in OpenOffice Write and keep format? |
|
|
Hi DVezina,
I am almost certain that the solution to closing OO Macro goes something like the following but it hasn’t quite work still:
| Code: | Sub printdoc (sFilename as String)
Dim mArgs(3) as New com.sun.star.beans.PropertyValue
Dim oDoc
Dim oFrame
Dim s As String
Dim oDeskTop as Object
Dim printArray(0) As New com.sun.star.beans.PropertyValue
oDeskTop=CreateUnoService("com.sun.star.frame.Desktop")
mArgs(0).Name = "ReadOnly"
mArgs(0).Value = True
mArgs(1).Name = "MacroExecutionMode"
mArgs(1).Value = 4
mArgs(2).Name = "AsTemplate"
mArgs(2).Value = FALSE
mArgs(3).Name = "Hidden"
mArgs(3).Value = True
s = convertToURL(sFilename)
oDoc = oDeskTop.LoadComponentFromUrl(s, "_blank", 0, mArgs())
oDoc.print(printArray())
stardesktop.terminate()
End Sub |
I am using the example from another OO threat from http://user.services.openoffice.org/en/forum/viewtopic.php?f=20&t=49434.
Thanks,
Jack |
|
| Back to top |
|
 |
DVezina OOo Advocate

Joined: 29 Sep 2006 Posts: 248 Location: Orlando
|
Posted: Tue May 22, 2012 12:00 pm Post subject: |
|
|
Does this crash? oDoc.close() would be better but that crashes too.
The crash is because we are trying to close before OO if finished operations. I don't have quickstarter running so it is not a problem for me.
I think the solution is to start an event listener and wait until the document is completely finished before doing the oDoc.close() statement. I have code around somewhere for that and I will look it up. |
|
| Back to top |
|
 |
netbeansfan General User

Joined: 05 May 2012 Posts: 7
|
Posted: Tue May 22, 2012 4:33 pm Post subject: How to open text file in OpenOffice Write and keep format? |
|
|
Hi DVezina,
I have found a working solution with the following OO Writer Macro:
| Code: | Sub printdoc (sFilename as String)
Dim mArgs(3) as New com.sun.star.beans.PropertyValue
Dim oDoc
Dim oFrame
Dim s As String
Dim oDeskTop as Object
Dim printArray(0) As New com.sun.star.beans.PropertyValue
oDeskTop=CreateUnoService("com.sun.star.frame.Desktop")
mArgs(0).Name = "ReadOnly"
mArgs(0).Value = True
mArgs(1).Name = "MacroExecutionMode"
mArgs(1).Value = 4
mArgs(2).Name = "AsTemplate"
mArgs(2).Value = FALSE
mArgs(3).Name = "Hidden"
mArgs(3).Value = True
s = convertToURL(sFilename)
oDoc = oDeskTop.LoadComponentFromUrl(s, "_blank", 0, mArgs())
oDoc.print(printArray())
wait 1200
oDoc.close(True)
End Sub |
It would be good to know what your proposed closing macro solution as well but this one works fine.
Once again, thank you very much for all your on-going persisting support. This solution would not have been possible without your valuable input.
Thanks again,
Jack |
|
| Back to top |
|
 |
|