Updated version to generate xls instead of xls.
This was emailed to bkuhn by tmarble in the email identified below: Date: Fri, 04 Jan 2013 14:38:49 -0600 From: Tom Marble <tmarble@info9.net> To: "Bradley M. Kuhn" <bkuhn@sfconservancy.org> Subject: w/debug ods2xls.py Message-ID: <50E73DD9.4010602@info9.net>
This commit is contained in:
parent
e35ab803e9
commit
b3da77a17d
1 changed files with 13 additions and 7 deletions
20
ods2xls.py
20
ods2xls.py
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# ods2xlsx.py
|
# ods2xls.py
|
||||||
# adapted from ssconv.py
|
# adapted from ssconv.py
|
||||||
# see also
|
# see also
|
||||||
# https://help.libreoffice.org/Common/About_Converting_Microsoft_Office_Documents
|
# https://help.libreoffice.org/Common/About_Converting_Microsoft_Office_Documents
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import ooutils
|
import ooutils
|
||||||
|
import time
|
||||||
|
|
||||||
import uno
|
import uno
|
||||||
from com.sun.star.task import ErrorCodeIOException
|
from com.sun.star.task import ErrorCodeIOException
|
||||||
|
|
@ -15,7 +16,7 @@ from com.sun.star.task import ErrorCodeIOException
|
||||||
class SSConverter:
|
class SSConverter:
|
||||||
"""
|
"""
|
||||||
Spreadsheet converter class.
|
Spreadsheet converter class.
|
||||||
Converts spreadsheets to XLSX files.
|
Converts spreadsheets to XLS files.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, oorunner=None):
|
def __init__(self, oorunner=None):
|
||||||
|
|
@ -25,7 +26,7 @@ class SSConverter:
|
||||||
|
|
||||||
def convert(self, inputFile, outputFile):
|
def convert(self, inputFile, outputFile):
|
||||||
"""
|
"""
|
||||||
Convert the input file (a spreadsheet) to a XLSX file.
|
Convert the input file (a spreadsheet) to a XLS file.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Start openoffice if needed.
|
# Start openoffice if needed.
|
||||||
|
|
@ -33,7 +34,12 @@ class SSConverter:
|
||||||
if not self.oorunner:
|
if not self.oorunner:
|
||||||
self.oorunner = ooutils.OORunner()
|
self.oorunner = ooutils.OORunner()
|
||||||
|
|
||||||
|
# DEBUG
|
||||||
|
print('oorunner should be working here')
|
||||||
self.desktop = self.oorunner.connect()
|
self.desktop = self.oorunner.connect()
|
||||||
|
time.sleep(1)
|
||||||
|
print(os.popen('fuser -u 8100/tcp').read())
|
||||||
|
print('connected to LibreOffice...')
|
||||||
|
|
||||||
inputUrl = uno.systemPathToFileUrl(os.path.abspath(inputFile))
|
inputUrl = uno.systemPathToFileUrl(os.path.abspath(inputFile))
|
||||||
outputUrl = uno.systemPathToFileUrl(os.path.abspath(outputFile))
|
outputUrl = uno.systemPathToFileUrl(os.path.abspath(outputFile))
|
||||||
|
|
@ -50,7 +56,7 @@ class SSConverter:
|
||||||
# For more information see:
|
# For more information see:
|
||||||
# http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Filter_Options
|
# http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Filter_Options
|
||||||
#
|
#
|
||||||
document.storeToURL(outputUrl, ooutils.oo_properties(FilterName="Calc MS Excel 2007 XML"))
|
document.storeToURL(outputUrl, ooutils.oo_properties(FilterName="MS Excel 97"))
|
||||||
finally:
|
finally:
|
||||||
document.close(True)
|
document.close(True)
|
||||||
|
|
||||||
|
|
@ -77,9 +83,9 @@ if __name__ == "__main__":
|
||||||
converter = SSConverter()
|
converter = SSConverter()
|
||||||
while i < len(argv):
|
while i < len(argv):
|
||||||
odsname = argv[i]
|
odsname = argv[i]
|
||||||
xlsxname = odsname.replace('.ods', '.xlsx')
|
xlsname = odsname.replace('.ods', '.xls')
|
||||||
print '%s => %s' % (odsname, xlsxname)
|
print '%s => %s' % (odsname, xlsname)
|
||||||
converter.convert(odsname, xlsxname)
|
converter.convert(odsname, xlsname)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
except ErrorCodeIOException, exception:
|
except ErrorCodeIOException, exception:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue