我需要編寫一個python腳本來讀取excel文件,找到每個工作表,然後用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,所以如果你提交你的解決方案作爲anwer將是有益的:) –
@GustavoVargas我沒有使用以下,因爲它不保留格式化,但xtopdf似乎做一個好的解決方案 - dancingbison.com/products.html,開發人員也非常有幫助。 – GeorgeC