时间:2011-01-06 17:42:01

标签: java excel pdf landscape

3 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

你看过JasperReports了吗?它有一个非常强大的模板引擎。

我从未像你一样使用JasperReports,但他们的专长是动态报告,所以我猜他们知道如何以一种很好的方式处理页面溢出。

答案 2 :(得分:0)

这就是我最终做的事情。它使用MacOS上的QuickLook功能制作HTML文件,然后使用wkhtmltopdf将HTML文件转换为PDF格式。

#!/usr/bin/python                                                                                                           
#                                                                                                                           
# convert an excel workbook to a PDF on a Mac                                                                               
#                                                                                                                           
#                                                                                                                           
from subprocess import Popen,call,PIPE
import os, os.path, sys
import xml.dom.minidom
import plistlib

if len(sys.argv)==1:
    print("Usage: %s filename.xls output.pdf" % sys.argv[0])
    exit(1)

if os.path.exists("xdir"):
    raise RuntimeError,"xdir must not exists"
os.mkdir("xdir")
call(['qlmanage','-o','xdir','-p',sys.argv[1]])

# Now we need to find the sheets and sort them.                                                                             
# This is done by reading the property list                                                                                 
qldir = sys.argv[1] + ".qlpreview"
propfile = open("%s/%s/%s" % ('xdir',qldir,'PreviewProperties.plist'))
plist = plistlib.readPlist(propfile)
attachments = plist['Attachments']
sheets = []
for k in attachments.keys():
    if k.endswith(".html"):
        basename = os.path.basename(k)
        fn = attachments[k]['DumpedAttachmentFileName']
        print("Found %s -> %s" % (basename,fn))
        sheets.append((basename,fn))
sheets.sort()

# Use wkhtmltopdf to generate the PDF output                                                                                
os.chdir("%s/%s" % ('xdir',qldir))
cmd = ['wkhtmltopdf'];
for (basename,fn) in  sheets:
    cmd.append(fn)
cmd.append("../../" + sys.argv[2])
try:
    call(cmd)
except OSError:
    print("\n\nERROR: %s is not installed\n\n" % (cmd[0]))
    exit(1)
os.chdir("../..")
call(['/bin/rm','-rf','xdir'])
相关问题