| View previous topic :: View next topic |
| Author |
Message |
cstorm Newbie

Joined: 16 Jun 2005 Posts: 3 Location: Annawan, IL
|
Posted: Tue Aug 09, 2005 1:52 pm Post subject: How to test a file before opening it |
|
|
Hello,
I'm looking to figure out how to test a file before opening it.
Here's the existing macro code, copied and pasted from the raw .xba file (hence the "'s):
| Code: | Sub SxwToDoc( filenameList )
filenameArray=parse_filenames(filenameList)
for i = 0 to (Array1_Size(filenameArray)-1)
cFile = filenameArray(i)
cURL = ConvertToURL( cFile )
oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, Array(_
MakePropertyValue( "Hidden", True ),_
) )
cFile = Left( cFile, Len( cFile ) - 4 ) + ".doc"
cURL = ConvertToURL( cFile )
oDoc.storeToURL( cURL, Array ( MakePropertyValue ("FilterName","MS Word 97") ) )
oDoc.close( True )
next
End Sub
|
I'm calling this from some php code, in a headless environment (-invisible option using Xvfb for the display), and if I pass it a bogus file name, it hangs OpenOffice as it's waiting for someone to click on the OpenOffice Basic Error popup. If I turn off the headless stuff and watch what it's doing, it pops open the Macro Basic IDE and highlights the line with the storeToURL call.
I'm guessing then, that I need to somehow test this file to make sure it exists before I try and write to it.
Any one have a good suggestion for testing the file? I've searched the oooforums, and haven't come up with much, but I'm willing to bet that this top has been discussed at some point, perhaps off-topic to another post.
Thanks in advance,
/cs _________________ Chad Storm |
|
| Back to top |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
Posted: Tue Aug 09, 2005 11:42 pm Post subject: |
|
|
test for existance of a file is easy ...
| Code: | oSFA = createUNOService ("com.sun.star.ucb.SimpleFileAccess")
if (oSFA.exists(cURL)) then
...
endif
|
Hope that solves your problem
m777 |
|
| Back to top |
|
 |
cstorm Newbie

Joined: 16 Jun 2005 Posts: 3 Location: Annawan, IL
|
Posted: Wed Aug 10, 2005 2:45 pm Post subject: what about an invalid but existing sxw doc? |
|
|
How do I check an sxw file to make sure it's actually xml compliant and won't cause openoffice to complain? I have the scenario where the file exists, but isn't XML-compliant, so efforts to convert it to a doc will hang a headless ooffice instance.
Thanks,
/cs _________________ Chad Storm |
|
| Back to top |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
Posted: Wed Aug 10, 2005 3:34 pm Post subject: |
|
|
how about an on error construct ?
| Code: | on error resume next
doc = loadComponentFromUrl(...)
on error goto 0
if Isnull(doc) then
...
endif |
|
|
| Back to top |
|
 |
Marinus OOo Advocate

Joined: 07 Nov 2004 Posts: 261
|
Posted: Mon Aug 15, 2005 4:41 pm Post subject: |
|
|
Not a true answer to checking XML compliancy but perhaps of help still...
| Code: |
sub Main
' Check integrity
oDoc = StarDesktop.getCurrentComponent()
' *** adjust for other documenttypes ***
if not oDoc.SupportsService("com.sun.star.sheet.SpreadsheetDocument") then
' do something
endif
end sub |
Cheers,
Marinus. |
|
| Back to top |
|
 |
cstorm Newbie

Joined: 16 Jun 2005 Posts: 3 Location: Annawan, IL
|
Posted: Mon Aug 15, 2005 4:51 pm Post subject: Sweet |
|
|
The on error construct worked perfectly for my needs... thanks ms777 on that suggestion! For this particular situation, if the SXW document is corrupt, I don't want to continue at all, but rather exit out immediately...
Here's what I ended up using:
| Code: | Sub X
on error goto ErrorHandler
.
.
.
Exit Sub
ErrorHandler:
Reset
End Sub |
_________________ Chad Storm |
|
| Back to top |
|
 |
Cybb20 Super User


Joined: 02 Mar 2004 Posts: 1569 Location: Frankfurt, Germany
|
Posted: Wed Aug 17, 2005 3:32 pm Post subject: |
|
|
cstorm: Problem solved ?
Christian _________________ - Knowledge is Power - |
|
| Back to top |
|
 |
|