Created
April 29, 2020 17:23
-
-
Save astoeckel/fae7fd37a0f5c5f48bce03bee301fbcd to your computer and use it in GitHub Desktop.
Libre Office Export All Sheets As CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub ExportAllToCsv | |
document = ThisComponent | |
' Use the global string tools library to generate a base filename for each CSV | |
' based on the current prefixless filename | |
GlobalScope.BasicLibraries.loadLibrary("Tools") | |
DocumentName = Left(document.Namespace, Len(document.Namespace) - 1) | |
BasePath = Tools.Strings.DirectoryNameoutofPath(DocumentName, "/") | |
BaseFilename = Tools.Strings.GetFileNameWithoutExtension(DocumentName, "/") | |
' Work out number of sheets for looping over them later. | |
Sheets = document.Sheets | |
NumSheets = Sheets.Count - 1 | |
' Set up a propval object to store the filter properties | |
Dim Propval(1) as New com.sun.star.beans.PropertyValue | |
Propval(0).Name = "FilterName" | |
Propval(0).Value = "Text - txt - csv (StarCalc)" | |
Propval(1).Name = "FilterOptions" | |
Propval(1).Value ="44,34,0,1,,0" | |
For I = 0 to NumSheets | |
' For each sheet, assemble a filename and save using the filter | |
SheetName = LCase(Sheets(I).Name) | |
SheetName = Replace(SheetName, " ", "_") | |
document.getCurrentController.setActiveSheet(Sheets(I)) | |
Filename = BasePath + "/" + BaseFilename + "_" + SheetName + ".csv" | |
FileURL = convertToURL(Filename) | |
document.StoreToURL(FileURL, Propval()) | |
Next I | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment