[Solved] OpenOffice Automation with VB6 (import file)

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
Tenebroleso
Posts: 15
Joined: Thu Jul 05, 2012 2:58 pm

[Solved] OpenOffice Automation with VB6 (import file)

Post by Tenebroleso »

Ok guys, anothter problem. I've searched on the web for a better method to import a file in Calc... but the only one I've find that works is the one written below.

This is the code:

Code: Select all

[...]
    ImportCSV sPath, "|", chr(34), "2/2/1/1/1/1/1/1/1/1", oServiceManager, oDocument, oDesktop
[...]

Public Sub ImportCSV(sURL As String, _
                     sSeparator As String, _
                     sDefineText As String, _
                     sColumns As String, _
                     oServiceManagerLav As Object, _
                     oDocumentLav As Object, _
                     oDesktopLav As Object)

    Dim oDispatcher     As Object
    Dim oArguments(1)   As Object

    Set oDispatcher = oServiceManagerLav.createInstance("com.sun.star.frame.DispatchHelper")

    Set oArguments(0) = oServiceManagerLav.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
    oArguments(0).Name = "FilterName"
    oArguments(0).Value = "Text - txt - csv (StarCalc)"

    Set oArguments(1) = oServiceManagerLav.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
    oArguments(1).Name = "FilterFlags"
    oArguments(1).Value = Asc(sSeparator) & "," & Asc(sDefineText) & ",SYSTEM,1," & sColumns

    sURL = ConvertToURL(sURL)
    Set oDocumentLav = oDesktopLav.loadComponentFromURL(sURL, "_blank", 0, oArguments())

    DoEvents
End Sub
This is the file I'm trying to import:

Code: Select all

"XXX"|"YYY"
"COL1"|"COL2"|"COL3"|"COL4"|"COL5"|"COL6"|"COL7"|"COL8"|"COL9"|"COL10"
"001.001.001"|"TEXT 1"||||1.234.567,89|-1.234.567,89|||
"002.002.002"|"TEXT 2"||||1.234.567,89|-1.234.567,89|||
"003.003.003"|"TEXT 3"||||1.234.567,89|-1.234.567,89|||
"004.004.004"|"TEXT 4"||||1.234.567,89|-1.234.567,89|||
When the import ends the file I see isn't correct (attached).

As you can see the first columns reports values like "1001001" instead of "001.001.001"... how can I solve this problem? Where is the problem?

Thank you in advance...
Attachments
OO.jpg
Last edited by Hagar Delest on Wed Jul 18, 2012 9:22 pm, edited 1 time in total.
Reason: tagged [Solved].
OpenOffice 3.4 on Windows XP
Tenebroleso
Posts: 15
Joined: Thu Jul 05, 2012 2:58 pm

Re: OpenOffice Automation with VB6 (import file)

Post by Tenebroleso »

I've changed FilterFlags with FilterOptions... still doesn't work... :(
OpenOffice 3.4 on Windows XP
User avatar
karolus
Volunteer
Posts: 1243
Joined: Sat Jul 02, 2011 9:47 am

Re: OpenOffice Automation with VB6 (import file)

Post by karolus »

Hallo
I'm not sure its helpful, but if i try to import your kind of .csv manually.
.
with 1.st Column set as Text i get Filteroptions:
124,34,76,1,1/2,0,false,false

without explizit settings
124,34,76,1,,0,false,false

with 1.st and 6.st Columns set as Text :
124,34,76,1,1/2/6/2,0,false,false

so maybe the Pairs ColNum/2 defines Import as Text

Karo
Libreoffice 25.2… on Debian 13 (trixie) (on RaspberryPI5)
Libreoffice 25.8… flatpak on Debian 13 (trixie) (on RaspberryPI5)
Tenebroleso
Posts: 15
Joined: Thu Jul 05, 2012 2:58 pm

Re: OpenOffice Automation with VB6 (import file)

Post by Tenebroleso »

Ok, I've changed "2/2/1/1/1/1/1/1/1/1" with "1/2/2/2" and now it works.

Sorry guys, I've misunderstand how to set the string... :oops:
OpenOffice 3.4 on Windows XP
Post Reply