【发布时间】:2009-01-08 02:10:05
【问题描述】:
OpenOffice Excel 文件导出到 PDF 正在以编程方式完成,我想知道是否有办法通过在转换过程中传递某种标志或其他东西来解决此问题,这将使单元格背景在PDF 文档。
请注意一个示例 PDF 输出。原始 Excel 文件完全不重叠边缘:http://www.freeimagehosting.net/uploads/4ab8dd9af0.jpg
这是PDF导出前的原始Excel文件:http://www.freeimagehosting.net/uploads/0cdcaad47a.jpg
OpenOffice 2.4 和 3.0 都有同样的缺陷。
非常欢迎提出建议,这是支持这个项目的最后一件事。
点击以下链接查看 OpenOffice 网站上的示例:http://user.services.openoffice.org/en/forum/viewtopic.php?f=20&t=13528
这里是问题跟踪链接:http://www.openoffice.org/issues/show_bug.cgi?id=97856
还有一些代码给你,它是Jython 2.2.1 和 Java 2.5。
def _save_as_pdf(self, docSource):
dirName=os.path.dirname(docSource)
baseName=os.path.basename(docSource)
baseName, ext=os.path.splitext(baseName)
dirTmpPdfConverted=os.path.join(dirName + DIR + PDF_TEMP_CONVERT_DIR)
if not os.path.exists(dirTmpPdfConverted):
os.makedirs(dirTmpPdfConverted)
pdfDest=os.path.join(dirTmpPdfConverted + DIR + baseName + ".pdf")
url_save=self._create_UNO_File_URL(pdfDest)
properties=self._create_properties(ext)
try:
try:
self._xstorable=UnoRuntime.queryInterface(XStorable, self._doc)
self._xstorable.storeToURL(url_save, properties)
except AttributeError,e:
self.logger.info("saving as pdf has problem: (" + str(e) + ")")
raise e
except:
self.logger.info("storeToURL exception")
raise
finally:
self.logger.info("converted document " + baseName + ext)
if not self._doc:
xCloseable = UnoRuntime.queryInterface(XCloseable, self._doc)
if not xCloseable:
try:
xCloseable.close(false)
except CloseVetoException, (ex):
xComp = UnoRuntime.queryInterface(XComponent, self._doc)
xComp.dispose()
else:
xComp = UnoRuntime.queryInterface(XComponent, self._doc)
xComp.dispose()
self._doc=None
def _create_properties(self,ext):
properties=[]
p=PropertyValue()
p.Name="Overwrite"
p.Value=True
properties.append(p)
p=PropertyValue()
p.Name="FilterName"
if ext==".doc":
p.Value='writer_pdf_Export'
elif ext==".rtf":
p.Value='writer_pdf_Export'
elif ext==".html":
p.Value='writer_pdf_Export'
elif ext==".htm":
p.Value='writer_pdf_Export'
elif ext==".xls":
p.Value='calc_pdf_Export'
elif ext==".tif":
p.Value='draw_pdf_Export'
elif ext==".tiff":
p.Value='draw_pdf_Export'
properties.append(p)
return tuple(properties)
【问题讨论】:
-
你为什么不向OOo提出一个实际的BUG(我知道你已经在他们的论坛上问过了)。
-
另外,您可以发布代码和/或电子表格吗?我是否刚刚注意到这是一个 XLS 文件(来自 Excel)而不是 ODS?
-
是的 xls 文件。好吧,我贴一些代码和 xls 电子表格的原始示例。
-
它是在 Excel 中创建的 .xls。
标签: java pdf openoffice.org xls