我需要编写一个Python脚本来读取Excel文件,查找每个工作表,然后使用在Excel中定义的标准格式打印到PDF中。
我发现了以下问题How can I open an Excel file in Python?,其中指向了http://www.python-excel.org/
这使我能够找到每个工作表的名称。
import xlrd
book = xlrd.open_workbook("myfile.xls")
print "Worksheet name(s):", book.sheet_names()
这导致了Worksheet name(s): [u'Form 5', u'Form 3', u'988172 Adams Road', u'379562 Adams Road', u'32380 Adams Road', u'676422 Alderman Road', u'819631 Appleyard Road', u'280998 Appleyard Road', u'781656 Atkinson Road', u'949461 Barretts Lagoon Road', u'735284 Bilyana Road', u'674784 Bilyana Road', u'490894 Blackman Road', u'721026 Blackman Road']
现在我想将以数字开头的每个工作表打印到PDF中。
因此,我可以
worksheetList=book.sheet_names()
for worksheet in worksheetList:
if worksheet.find('Form')!=0: #this just leaves out worksheets with the word 'form' in it
<function to print to pdf> book.sheet_by_name(worksheet) #what can I use for this?
有没有类似于上述的东西…我可以用什么来实现这个?
XLRD文档令人困惑,它说
格式特性不包括在xlrd版本0.6.1中:杂项 工作表级和书级项目,如打印布局、屏幕窗格
和
格式
介绍
这些特性的集合是xlrd版本0.6.1中的新功能,旨在 提供所需的信息,以便在屏幕或PDF文件中显示/呈现电子表格内容
见https://secure.simplistix.co.uk/svn/xlrd/trunk/xlrd/doc/xlrd.html?p=4966
哪一个是正确的?还有其他的软件包可以用来打印PDF吗?
对于Unix,我看到有http://dag.wieers.com/home-made/unoconv/,有Windows的吗?我找到了https://gist.github.com/mprihoda/2891437,但还不知道如何使用它。