OOoのCalcで全シートをCSVで保存するマクロ
複数のシート(ページ)が含まれる.odtファイルとか.xlsファイルの、全シートをそれぞれ.csvで保存するマクロを組んだ。あ、OOo2.0系向けですな。
Sub SaveAllSheetAsCSV
Dim oDoc As Object
oDoc = ThisComponent
Dim oCController as object
oCController = oDoc.CurrentController
If oDoc.supportsService( "com.sun.star.sheet.SpreadsheetDocument" ) Then
Dim oSheets As Object
oSheets = oDoc.getSheets()
Dim oFolderPicker As Object
oFolderPicker = createUnoService("com.sun.star.ui.dialogs.FolderPicker")
oFolderPicker.execute()
Dim aArgs(1) As New com.sun.star.beans.PropertyValue
aArgs(0).Name = "FilterName"
aArgs(0).Value = "Text - txt - csv (StarCalc)"
aArgs(1).Name = "FilterOptions"
aArgs(1).Value = "44,34,76"
Dim SaveDir As String
SaveDir = oFolderPicker.getDirectory()
For i% = 0 To oSheets.getCount() - 1
Dim SaveURL As String
SaveURL = SaveDir + "/" + oSheets.getByIndex( i ).getName() + ".csv"
oCController.ActiveSheet = oSheets.getByIndex( i )
MsgBox SaveURL
oDoc.storeAsURL( ConvertToURL(SaveURL), aArgs() )
Next i
oCController.ActiveSheet = oSheets.getByIndex( 0 )
Else
MsgBox "Document is not a spreadsheet."
End If
End Sub