【发布时间】:2013-05-17 00:13:45
【问题描述】:
我需要编写一个 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 版中的新功能集合旨在 提供 (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,但还不知道怎么用。
【问题讨论】:
-
嘿@GeorgeC,你找到解决方案了吗?我正在寻找一种将整个 xsl “打印”为 pdf 的方法,因此,如果您将解决方案作为答案提交将很有帮助:)
-
@GustavoVargas 我没有使用以下内容,因为它不保留格式,但 xtopdf 似乎是一个不错的解决方案 - dancebison.com/products.html,开发人员也非常乐于助人。跨度>
标签: python excel pdf printing export