deutsches Forum rund um Apache OpenOffice und LibreOffice
Zum Inhalt
von abuayyoub » Do, 27.02.2014 18:07
von F3K Total » Do, 27.02.2014 18:01
von abuayyoub » Do, 27.02.2014 17:55
von F3K Total » Do, 27.02.2014 17:30
von F3K Total » Do, 27.02.2014 06:15
von abuayyoub » Do, 27.02.2014 00:21
von F3K Total » Sa, 22.02.2014 19:42
Code: Alles auswählen
sub Import_csv odocument = StarDesktop.loadComponentFromURL("private:factory/scalc","_blank", 0, Array()) t1 = getsystemticks() oStatusIndicator = odocument.CurrentController.Frame.CreateStatusIndicator oStatusIndicator.Start("Los", 100) odocument.lockcontrollers oSheet = odocument.sheets(0) 'sPath = converttourl("C:\Users\<USER>\Desktop\pixpro_feed_v2_de_de_full_hdr_20140222012002.csv") sPath = F_get_Url oFileAccess = CreateUnoService("com.sun.star.ucb.SimpleFileAccess") oInputStream = oFileAccess.openFileRead(sPath) nlenght = oInputStream.Length oFileRead = createUnoService("com.sun.star.io.TextInputStream") oFileRead.InputStream = oInputStream oFileRead.Encoding = "UTF-8" r = 0 Do While NOT oFileRead.IsEOF sCurrentLine = oFileRead.readLine csv_data = split(sCurrentLine, ";") for c = 0 to ubound(csv_data) if isNumeric(csv_data(c)) then if c = 15 then goto 100' 15 entspricht der Spalte P: EAN-Nummer oSheet.getCellByPosition(c,r).value = csv_data(c) else 100: oSheet.getCellByPosition(c,r).String = csv_data(c) end if next c r = r + 1 if r mod 100 = 0 then nPosition = oInputStream.Position nNewvalue = int(nPosition*100/nlenght) oStatusIndicator.Value = nNewvalue oStatusIndicator.text = "~"+nNewvalue+" %" endif Loop oStatusIndicator.End oInputStream.closeInput odocument.unlockcontrollers t2 = getsystemticks() msgbox ("Fertig, es wurden "+r+" Zeilen in "+((t2-t1)/1000)+ " Sekunden importiert.",64,"CSV Import") end sub function F_get_Url as string oDialog = createunoservice("com.sun.star.ui.dialogs.FilePicker") oDialog.appendFilter("Quelldatei","*.csv") oDialog.displaydirectory="c:\" if odialog.execute = 0 then exit function endif F_get_Url = oDialog.Files(0) end function
von abuayyoub » Sa, 22.02.2014 17:38
von F3K Total » Sa, 22.02.2014 17:05
sPath = F_get_Url
sPath = converttourl("Pfad zu deiner Datei")
abuayyoub hat geschrieben:Hallo, gibt es keinen schnelleren weg, wie bei manuellen Dialog fenster? auf wunsch kann ich die komplette csv zur verfügung stellen. Danke
von abuayyoub » Sa, 22.02.2014 16:28
von F3K Total » Sa, 22.02.2014 15:24
von abuayyoub » Sa, 22.02.2014 15:17
von F3K Total » Sa, 22.02.2014 15:05
sub Import_csv odocument = StarDesktop.loadComponentFromURL("private:factory/scalc","_blank", 0, Array()) oSheet = odocument.sheets(0) sPath = F_get_Url oFileAccess = CreateUnoService("com.sun.star.ucb.SimpleFileAccess") oInputStream = oFileAccess.openFileRead(sPath) oFileRead = createUnoService("com.sun.star.io.TextInputStream") oFileRead.InputStream = oInputStream oFileRead.Encoding = "UTF-8" r = 0 Do While NOT oFileRead.IsEOF sCurrentLine = oFileRead.readLine csv_data = split(sCurrentLine, ";") for c = 0 to ubound(csv_data) if isNumeric(csv_data(c)) then if c = 15 then goto 100' 15 entspricht der Spalte P: EAN-Nummer oSheet.getCellByPosition(c,r).value = csv_data(c) else 100: oSheet.getCellByPosition(c,r).String = csv_data(c) end if next c r = r + 1 Loop oInputStream.closeInput msgbox ("Es wurden "+r+" Zeilen erfolgreich importiert ;-)",64,"Import abgeschlossen") end sub function F_get_Url as string oDialog = createunoservice("com.sun.star.ui.dialogs.FilePicker") oDialog.appendFilter("Quelldatei","*.csv") oDialog.displaydirectory="c:\" if odialog.execute = 0 then exit function endif F_get_Url = oDialog.Files(0) end function
von abuayyoub » Sa, 22.02.2014 13:35
von F3K Total » Sa, 22.02.2014 13:10
Nach oben