[Solved] Error with storeAsURL: can’t figure out the reason

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
esperantisto
Volunteer
Posts: 578
Joined: Mon Oct 08, 2007 1:31 am

[Solved] Error with storeAsURL: can’t figure out the reason

Post by esperantisto »

I’m trying to make a Calc macro that exports a (currently) spreadsheet to a tab-delimited file in UTF-8. Ideally, it should save under the same file name replacing .odt/.xls/.xslx with .txt, but for testing purposes I just hard-code the file name so far. Thus, the code is:

Code: Select all

Sub ExportToGlossary

Dim oDoc as Object
Dim glossaryFileProperties(3) as new com.sun.star.beans.PropertyValue
Dim sURL as String

oDoc = ThisComponent

If oDoc.getLocation() = "" Then Exit Sub

sURL = "file:///E:/export_to_glossary.txt"

glossaryFileProperties(0).Name = "FilterName"  ' setting properties of exported file such as tab as field delimiter, nothing as text delimiter, UTF-8 as encoding
glossaryFileProperties(0).Value = "scalc: Text - txt - csv (StarCalc)" 
glossaryFileProperties(1).Name = "FilterOptions" 
glossaryFileProperties(1).Value = "9,0,76,1,,0,false,true,false"
glossaryFileProperties(2).Name = "Overwrite" 
glossaryFileProperties(2).Value = True

oDoc.storeAsURL(sURL, glossaryFileProperties())
End Sub
When I run the macro from Apache OpenOffice 4.2.0 (420m1 Build:9800), I get the following error message:

Code: Select all

BASIC runtime error.
An exception occurred
Type: com.sun.star.task.ErrorCodeIOException
Message:.


(Damn those programmers that don’t bother about producing clear error messages!)

LibreOffice 5.0.0.4 is somewhat more eloquent:

Code: Select all

BASIC runtime error.
An exception occurred
Type: com.sun.star.task.ErrorCodeIOException
Message: SfxBaseModel::impl_store <fiIe:///E:/expоrt_to_glоssary.txt> failed: 0x81a.
However, I still can’t understand what’s wrong. Here’s an example from StarBasic Programming Guide:

Code: Select all

Dim mFileProperties(0) As New com.sun.star.beans.PropertyValue
Dim sUrl As String
sUrl = "file:///complete/path/To/New/document"
mFileProperties(0).Name = "Overwrite"
mFileProperties(0).Value = FALSE
oDocument.storeAsURL(sUrl, mFileProperties())
I can’t see any substantial difference as compared to my code.

Can anyone give me a pointer what should I look at?

P. S. I have full read/write permissions on the partition concerned.
Last edited by esperantisto on Fri Sep 11, 2015 8:36 am, edited 1 time in total.
AOO 4.2.0 (of 2015) / LO 7.x / Win 7 / openSUSE Linux Leap 15.4 (64-bit)
User avatar
Zizi64
Volunteer
Posts: 11482
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Error with storeAsURL: can’t figure out the reason

Post by Zizi64 »

Tips:

1.: Device 'E:' is not available
2.: Device 'E:' is read only

If you want EXPORT some data then you need use the 'storeToURL' command instead of the 'storeAsURL'.
The 'storeAsURL' equivalent to the Save As function: the source file being a .txt file: the original .ods file will be closed, and you can edit the newly created .txt file.
The 'storeToURL' will create a .txt standalone file, but the original .ods file stay opened.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
esperantisto
Volunteer
Posts: 578
Joined: Mon Oct 08, 2007 1:31 am

Re: Error with storeAsURL: can’t figure out the reason

Post by esperantisto »

Thanks, but your tips don’t help:
a) the partition e: is available and writeable (it’s my working partition under Windows);
b) storeToURL doesn’t work either.
AOO 4.2.0 (of 2015) / LO 7.x / Win 7 / openSUSE Linux Leap 15.4 (64-bit)
User avatar
Villeroy
Volunteer
Posts: 31345
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Error with storeAsURL: can’t figure out the reason

Post by Villeroy »

You set Overwrite=False, so I guess you are the programmer supposed to handle the error which is raised when the file exists.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
esperantisto
Volunteer
Posts: 578
Joined: Mon Oct 08, 2007 1:31 am

Re: Error with storeAsURL: can’t figure out the reason

Post by esperantisto »

No, it’s true (see the first listing), false is in the example from the programming guide. Besides, it won’t work even if I manually delete the text file.
AOO 4.2.0 (of 2015) / LO 7.x / Win 7 / openSUSE Linux Leap 15.4 (64-bit)
FJCC
Moderator
Posts: 9549
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Error with storeAsURL: can’t figure out the reason

Post by FJCC »

Try setting the filter to
Text-txt-csv (StarCalc)
That is the name I see in the Developer's guide and I ran into problems with the one you are using many years ago.

Your filter options (9,0,76,1,,0,false,true,false) also look strange to me. Do you need to use Character set = 76? Try using 9,0,0,1,1.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Error with storeAsURL: can’t figure out the reason

Post by B Marcelly »

Yes, the correct Filter name is :
Text - txt - csv (StarCalc)
Copy exactly this name, spaces and letter case are important.
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
esperantisto
Volunteer
Posts: 578
Joined: Mon Oct 08, 2007 1:31 am

Re: Error with storeAsURL: can’t figure out the reason

Post by esperantisto »

FJCC and B Marcelly, thanks a lot for the pointer! It was exactly the filter name that was bad. It’s strange because "scalc: Text - txt - csv (StarCalc)" works fine in a couple of macros that I use for loading certain CSV files.

FJCC, I got those filter options by manually saving a file to CSV with macro recording on. I’ll try your suggestion, thanks!

Zizi64, thank you for the pointer about storeToURL()! Now, when I got the macro working, I see that storeToURL() is what I need rather than storeAsURL().

The problem is solved. The next task is changing the file name rather than hardcoding. Thus, I’ll be back with new questions :-)
AOO 4.2.0 (of 2015) / LO 7.x / Win 7 / openSUSE Linux Leap 15.4 (64-bit)
Post Reply