I've been recently looking into importing into Drupal from an Excel spreadsheet, and obviously the first step when confronted with an Excel spreadsheet is to say:
Oh my dear heavens. Can I export this as CSV?
It turns out that exporting a single sheet (the active one) to CSV is trivial. Obviously you can open it in Libreoffice and do that manually, but there's also
unoconv which lets you do it from the command line.
Exporting e.g. all sheets from one spreadsheet, each into a different CSV file, is much trickier: manually, and automatically. Here's what
unoconv's maintainer said about being willing to add the functionality to do so:
But for your specific case, modifying unoconv should be very simple (look for UNO code for selecting a sheet, or removing sheets) and integrate it just before the export takes place.
... in 2011. Even as of 2014, it looks like hacking away at the Python code of
/usr/bin/unoconv, is the only way to make it work. Now, I like Python as much as the next man, but I'd prefer to do this in a more maintainable way.
A more interesting option - exporting semi-manually, if you like - is to script the process with Libreoffice macros, possibly the most minimally tutorialized (as opposed to mere reference documentation of functions) programming language you're likely to encounter this side of Google Spreadsheet formulae. But once you work out what you need to do, and get a feel for how the language works (hint: Visual Basic) then it's fairly straightforward;
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") BaseFilename = Tools.Strings.GetFileNameWithoutExtension(document.getURL(), "/") ' 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 ="59,34,0,1,1" 'ASCII 59 = ; 34 = " For I = 0 to NumSheets ' For each sheet, assemble a filename and save using the filter SheetName = Sheets(I).Name document.getCurrentController.setActiveSheet(Sheets(I)) Filename = "/tmp/" + BaseFilename + "." + SheetName + ".csv" FileURL = convertToURL(Filename) document.StoreAsURL(FileURL, Propval()) Next I ' Libreoffice thinks our filename is now the last-exported-CSV filename, so close. Msgbox "Files saved as /tmp/" + BaseFilename + ".*.csv. You'll need to close the spreadsheet now." End Sub
I doubt if I would want to write a whole web application in it, but that particular script really hit the spot. I might try more Libreoffice macro scripting again in future. If I have to.