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

Joined: 17 Nov 2003 Posts: 2
|
Posted: Mon Nov 17, 2003 9:10 am Post subject: error with Document.storeToUrl |
|
|
Hello,
I'am trying to convert a HTML file to a DOC file with Open Office. I use a macro which
store the file using the storeToUrl method. But it raises a IOException which i catch with
n error handler. The only information I have is :
1 (the value of variable Err in my error handler)
Exception com.sun.star.IOException
Message :
which is not very helpful to find the problem. Any idea to have more information on the
cause of the IOexception and/or classical problems with the storeToUrl method ?
Thanks
Olivier |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Mon Nov 17, 2003 9:37 am Post subject: |
|
|
When you open the HTML file, you are probably opening it as a Web document.
You cannot export to Word (doc) from a Web document.
You can import an HTML document into Writer. Writer has a much larger set of export possibilities.
So do this....
* Import HTML document into Writer (not Web)
* Export Writer doc as Word (doc)
Here is how you are probably opening HTML into a Web document...
| Code: | cSourceDoc = "C:\Documents and Settings\dbrewer\Desktop\test\Something.html"
' Open Html as a Web document
oDoc = StarDesktop.loadComponentFromURL( ConvertToURL( cSourceDoc ), "_blank", 0, Array() )
|
Instead, you need to specify an import filter on the loadComponentFromURL so that the HTML is imported into Writer....
| Code: | cSourceDoc = "C:\Documents and Settings\dbrewer\Desktop\test\Something.html"
' Open Html as a Writer document
oDoc = StarDesktop.loadComponentFromURL( ConvertToURL( cSourceDoc ), "_blank", 0,_
Array( MakePropertyValue( "FilterName", "HTML (StarWriter)" ) ) )
|
Now, you can use the standard technique in Writer to save as Word. Here is the COMPLETE code example that opens an HTML and saves it as (1) Writer, and (2) Word.
| Code: | cSourceDoc = "C:\Documents and Settings\dbrewer\Desktop\test\Something.html"
' Open Html as a Web document
' oDoc = StarDesktop.loadComponentFromURL( ConvertToURL( cSourceDoc ), "_blank", 0, Array() )
' Open Html as a Writer document
oDoc = StarDesktop.loadComponentFromURL( ConvertToURL( cSourceDoc ), "_blank", 0,_
Array( MakePropertyValue( "FilterName", "HTML (StarWriter)" ) ) )
' Same as cSourceDoc, but different extension
cDestDoc = Left( cSourceDoc, Len( cSourceDoc ) - 4 ) + ".sxw"
oDoc.storeToURL( ConvertToURL( cDestDoc ), Array() )
' Same as cSourceDoc, but different extension
cDestDoc = Left( cSourceDoc, Len( cSourceDoc ) - 4 ) + ".doc"
oDoc.storeToURL( ConvertToURL( cDestDoc ),_
Array( MakePropertyValue( "FilterName", "MS Word 97" ) ) )
|
Notice how the destination pathname is the same as the source pathname, but with the suffix (.html) replaced with either (.sxw) or (.doc).
All of the above examples depend on having this function available....
| Code: |
Function MakePropertyValue( Optional cName As String, Optional uValue ) As com.sun.star.beans.PropertyValue
Dim oPropertyValue As New com.sun.star.beans.PropertyValue
If Not IsMissing( cName ) Then
oPropertyValue.Name = cName
EndIf
If Not IsMissing( uValue ) Then
oPropertyValue.Value = uValue
EndIf
MakePropertyValue() = oPropertyValue
End Function
|
_________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
Guest
|
Posted: Mon Nov 17, 2003 11:29 am Post subject: |
|
|
That's exactly the way I do it. so ....
Olivier |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Mon Nov 17, 2003 11:45 am Post subject: |
|
|
| Guest wrote: | That's exactly the way I do it. so ....
Olivier |
I'm not sure of two things....
(1) is Guest the same user as oduhart who asked the original question?
(2) is Guest saying that the technique doesn't work?
If (1) is true, then probably (2) is true.
If (2) is true, then I'm puzzled. I copied the last snippet of code, the one I described as complete from a working example I posted quite some time ago.
I have had several problems that lead to the same IO error.
P1. One possibility is using a non-existant filter name. (Maybe filter name is misspelled, mistyped, or even has the wrong case.) I did post a complete list of filters for OOo here in the Macros and API section, and it is under a descriptive topic.
P2. Another problem is trying to use a filter name that does not apply to the current document type. But I'm not sure that this is really just stating the problem of the previous paragraph from a different perspective. This paragraph describes using a filter name string that is not one of the valid choices for current document type, and the previous paragraph says the same thing.
While P1 and P2 are really fundamentally the same problem from the internal point of view of OOo, we from the outside think of them differently.
If P2 is the problem, maybe this is because the HTML is really NOT getting opened as Writer? What if you just get as far as opening the document, and then end the macro right there so that you can be sure you are looking at a Writer document instead of a Web document?
There is another type of problem I have had when exporting documents.
P3. Certian types of filters only work on storeToURL but NOT on storeAsURL. For instance, you can storeAsUrl for both SXW or DOC. But you can only storeToURL for PDF.
You mentioned that you are using storeToURL, so I would assume that P3 is not the problem? _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
oduhart Newbie

Joined: 17 Nov 2003 Posts: 2
|
Posted: Tue Nov 18, 2003 3:16 am Post subject: |
|
|
You were right i opened the HTML file as a web document which made my macro go wrong. I now use a filter to load it and it works all fine. Thanks a lot
Olivier |
|
| 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
|