Es hat mich sehr viel weitergebracht.
Hier für alle die es interessiert mein gesamtes Makro vom Öffnen bis zu Schliessen:
Code: Alles auswählen
sub blafasel
rem Sub lade_csv_mit_Datumsformat
Dim Args(1) as New com.sun.star.beans.PropertyValue
sURL = converttourl("/bla/fasel.csv") ' <------ Dateipfad der zu ladenden Datei
Args(0).Name = "FilterName"
Args(0).Value ="Text - txt - csv (StarCalc)"
Args(1).Name = "FilterOptions"
Args(1).Value = "59,34,76,1,,0,false,true" ' <------ weitere Infos dazu hier: https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Filter_Options
odoc = StarDesktop.loadComponentFromURL(sURL,"_blank", 0, Args)
rem End sub
rem Sub loesche_Spalten
oSheet = ThisComponent.CurrentController.getActiveSheet()
oCellCursor = oSheet.CreateCursor()
oCellCursor.GotoEndOfUsedArea(True)
iLastCol = oCellCursor.getRangeAddress.EndColumn
oColumns=oSheet.getColumns
arToDel = Array("name2", "name3", "name4", "name5") ' <------ alle zu loeschenden Spalten
for i = iLastCol to 0 Step -1
strVal = oSheet.getCellByPosition(i,0).String
for each varItem in arToDel
if strVal = varItem Then
oColumns.removeByIndex(i,1)
exit for
endif
next
next
rem End Sub
rem sub loesche_wenn_Datum_kleiner_als
oSheet = ThisComponent.CurrentController.getActiveSheet()
oCursor = oSheet.CreateCursor
oCursor.GotoEndOfUsedArea(false)
nEndrow = oCursor.Rangeaddress.EndRow
for i = nEndrow to 1 step - 1
oCell = oSheet.GetCellByPosition(4,i)' <------ 4 entspricht Spalte E
if cdate(oCell.value) < cdate("01.01.2017") then ' <------ hier das Datum eingeben
oSheet.Rows.RemoveByIndex(i,1)
endif
next i
rem end sub
rem sub loesche_Zeilen_die_in_Spalte_enthalten
oSheet = ThisComponent.CurrentController.getActiveSheet()
oCursor = oSheet.CreateCursor
oCursor.GotoEndOfUsedArea(false)
nEndrow = oCursor.Rangeaddress.EndRow
for i = nEndrow to 0 step - 1
oCell = oSheet.GetCellByPosition(1,i)' <------ 1 entspricht Spalte B
if (oCell.string = "error") then ' <------ das Wort nachdem zu loeschen ist
oSheet.Rows.RemoveByIndex(i,1)
endif
next i
for i = nEndrow to 0 step - 1
oCell = oSheet.GetCellByPosition(5,i)' <------ 5 entspricht Spalte F
if (oCell.string = "storno" ) then ' <------ das Wort nachdem zu loeschen ist
oSheet.Rows.RemoveByIndex(i,1)
endif
next i
rem end sub
rem sub fuege_Spalte_hinzu
oSheet = ThisComponent.CurrentController.getActiveSheet()
columns=oSheet.getcolumns()
columns.insertByIndex(0,1) ' <------ an welcher Position und wieviele; hier Spalte A (0) und eine (1)
rem end sub
rem sub fuelle_Spalte_A
oSheet = ThisComponent.CurrentController.getActiveSheet() ' <------ aktives Tabellenblatt
oCursor = oSheet.CreateCursor
oCursor.GotoEndOfUsedArea(True)
nEndrow = oCursor.Rangeaddress.EndRow
for i = nEndrow to 0 step - 1
oCell = oSheet.GetCellByPosition(0,i) ' <------ 0 entspricht Spalte A
Select Case oCell.String
Case ""
oCell.String = "bla" ' <------ "Hier den Text eingeben"
End Select
next i
rem End sub
rem sub fuelle_A1
oSheet = ThisComponent.CurrentController.getActiveSheet()
mycell = oSheet.getCellByPosition(0,0) ' <------ 0 entspricht Spalte A
mycell.string="fasel" ' <------ "Hier den Text eingeben"
rem end sub
rem sub Datei_speichern
dim document as object ' <------ definieren einer Variablen
dim dispatcher as object ' <------ definieren einer Variablen
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dim args1(2) as new com.sun.star.beans.PropertyValue
args1(0).Name = "URL"
args1(0).Value = "file:///bla/fasel_bearbeitet.csv" ' <------ Dateipfad und -name der zu speichernden Datei
args1(1).Name = "FilterName"
args1(1).Value = "Text - txt - csv (StarCalc)"
args1(2).Name = "FilterOptions"
args1(2).Value = "59,34,76,1,,0,false,true,true" ' <------ weitere Infos dazu hier: https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Filter_Options
dispatcher.executeDispatch(document, ".uno:SaveAs", "", 0, args1())
rem end sub
rem sub schliesse_Datei
odoc=thisComponent
checkclose=odoc.ismodified()
if checkclose=false then
odoc.close(false)
else
msgbox "Dokument wurde geändert"
end if
end sub