von komma4 » Fr, 29.04.2016 17:14
Willkommen im Forum.
Für die Aufgabenstellung gibt es einen Trick:
die CSV Datei wird als LINK importiert, dann wird die Verbindung gelöst.
Hier ein Beispiel (ich glaube von 2007) aus dem englischen Forum
Code: Alles auswählen
Sub ImportCSVFile(sName$,fName$, Optional oDocument)
' http://www.oooforum.org/forum/viewtopic.phtml?t=22903
' Called by: ImportCSVFile("Prices", "d:/prices.csv", ThisComponent)
' Dims
Dim oDoc ' Calc document.
Dim oSheets ' The document sheets.
Dim oSheet ' A particular sheet.
' Sets
oDoc = IIF(IsMissing(oDocument), ThisComponent, oDocument)
If NOT oDoc.SupportsService("com.sun.star.sheet.SpreadsheetDocument") _
Then
Print "Sorry, the specified document is NOT a Calc document"
Exit Sub
End If
oSheets = oDoc.getSheets()
If oSheets.hasByName(sName) then
Print "Removing existing " & sName & " sheet"
oSheets.removeByName(sName)
End If
oSheets.insertNewByName(sName, oSheets.count())
oSheet = oSheets.getByIndex(oSheets.count()-1)
Dim sFilter$
Dim sOptions$
Dim sURL$
Dim s$
s = ""
sURL = "file:///" & fName$
sFilter = "Text - txt - csv (StarCalc)"
sOptions = "44,34,0,1,1/1/2/1"
oSheet.link(sURL, s, sFilter, sOptions, _
com.sun.star.sheet.SheetLinkMode.NORMAL)
oSheet.setLinkMode(com.sun.star.sheet.SheetLinkMode.NONE)
End Sub
Erster Parameter der Name des Tabellenblatts, zweiter der Name der CSV, dritter ein CALC-Dateiobjekt (oder die aktuelle Datei).
Den Importfilter natürlich auf Deine Werte ändern.
Hab's jetzt aktuell nicht probiert (damals von Yahoo historische Kursdaten importiert^^), sollte aber funktionieren.
Kommst' damit zurecht?
Willkommen im Forum.
Für die Aufgabenstellung gibt es einen Trick:
die CSV Datei wird als LINK importiert, dann wird die Verbindung gelöst.
Hier ein Beispiel (ich glaube von 2007) aus dem englischen Forum
[code]Sub ImportCSVFile(sName$,fName$, Optional oDocument)
' http://www.oooforum.org/forum/viewtopic.phtml?t=22903
' Called by: ImportCSVFile("Prices", "d:/prices.csv", ThisComponent)
' Dims
Dim oDoc ' Calc document.
Dim oSheets ' The document sheets.
Dim oSheet ' A particular sheet.
' Sets
oDoc = IIF(IsMissing(oDocument), ThisComponent, oDocument)
If NOT oDoc.SupportsService("com.sun.star.sheet.SpreadsheetDocument") _
Then
Print "Sorry, the specified document is NOT a Calc document"
Exit Sub
End If
oSheets = oDoc.getSheets()
If oSheets.hasByName(sName) then
Print "Removing existing " & sName & " sheet"
oSheets.removeByName(sName)
End If
oSheets.insertNewByName(sName, oSheets.count())
oSheet = oSheets.getByIndex(oSheets.count()-1)
Dim sFilter$
Dim sOptions$
Dim sURL$
Dim s$
s = ""
sURL = "file:///" & fName$
sFilter = "Text - txt - csv (StarCalc)"
sOptions = "44,34,0,1,1/1/2/1"
oSheet.link(sURL, s, sFilter, sOptions, _
com.sun.star.sheet.SheetLinkMode.NORMAL)
oSheet.setLinkMode(com.sun.star.sheet.SheetLinkMode.NONE)
End Sub[/code]
Erster Parameter der Name des Tabellenblatts, zweiter der Name der CSV, dritter ein CALC-Dateiobjekt (oder die aktuelle Datei).
Den Importfilter natürlich auf Deine Werte ändern.
Hab's jetzt aktuell nicht probiert (damals von Yahoo historische Kursdaten importiert^^), sollte aber funktionieren.
Kommst' damit zurecht?