PHP将Excel(.xls)转换为pdf [英] PHP Converting Excel (.xls) to pdfs
问题描述
是否存在将xls文件转换为pdf文档的php/java/开源软件转换器或php库?
Is there any php/java/open source software converters or php libraries that will convert an xls file to a pdf document?
精简版:具有生成xls电子表格的预先存在的代码(大约在2002-2006年,我相信是预打开的xml版本),出于各种原因,需要将它们转换为pdf.
Rundown: Have pre-existing code generating xls spreadsheets (circa 2002-2006, pre open xml version I believe), need to turn them into pdfs for various reasons.
开始搜索无处不在,包括此处.我想我只需要朝正确的方向撞,我敢肯定已经有东西可以做到这一点.
Been searching everywhere including here. I think I just need a bump in the right direction, I'm sure there is something out there already that does it.
推荐答案
您可以通过安装OpenOffice在Linux上将XLS文件转换为PDF 使用PDF编写器作为默认打印机驱动程序.
You can convert XLS files to PDF on Linux by installing OpenOffice with a PDF writer as the default printer driver.
然后,您可以使用"-p"命令行调用OpenOffice(来自PHP) 参数,这将使其加载指定的文件并进行打印.
Then, you can call OpenOffice (from PHP) using the "-p" command-line parameter, which will cause it to load a designated file and print it.
例如,如果您的文件是"accounts.xls",则将其称为 以下命令:
For example, if your file was "accounts.xls" you would call the following command:
soffice -p account.xls
soffice -p accounts.xls
OpenOffice将加载"accounts.xls"文件并将其打印"到 PDF writer,将其配置为将PDF文档保存到 所需的文件名.
OpenOffice would load the "accounts.xls" file and "print" it to the PDF writer, which would be configured to save the PDF document to the desired filename.
GhostScript是合适的PDF编写器.
GhostScript is a suitable PDF writer.
OpenOffice安装指南介绍了如何安装和配置 使用"spadmin"实用程序的打印机驱动程序,并讨论了 作为PDF编写者的ghostscript: "Open Office安装指南-附录" http://www.openoffice.org/docs/setup_guide/appendix.html
The OpenOffice setup guide describes how to install and configure printer drivers using the "spadmin" utility, and discusses the use of ghostscript as a PDF writer: "Open Office Setup Guide - Appendix" http://www.openoffice.org/docs/setup_guide/appendix.html
您可以使用反引号执行从PHP调用OpenOffice 运算符或"exec"功能.您可能还需要使用PHP移动 和/或重命名生成的PDF文件:
You can call OpenOffice from PHP by using the backtick execution operator, or the "exec" function. You may also need to use PHP to move and/or rename the resulting PDF files:
PHP:程序执行功能 http://www.php.net/manual/zh/ref.exec.php
PHP: Program Execution Functions http://www.php.net/manual/en/ref.exec.php
PHP:文件系统:重命名 http://www.php.net/manual/zh/function.rename.php
PHP: Filesystem: Rename http://www.php.net/manual/en/function.rename.php
OpenOffice非常擅长处理XLS文件,但可能不行 完美呈现每个此类文件-因此,如果您需要最终版本 兼容性,您将必须在Windows上使用Microsoft Excel 平台或仿真器. "IT AsiaOne"探讨了以下几种替代方案 Microsoft Office(包括OpenOffice)并写道 替代套件承诺...与Microsoft完全兼容 通常,Office创建的文档在以下方面做得不错 翻译Microsoft".doc",.ppt"和".xls"文件格式":
OpenOffice is pretty good at processing XLS files, but it may not perfectly render every such file - so if you need the ultimate in compatibility you will have to use Microsoft Excel on a Windows Platform or emulator. "IT AsiaOne" looked at several alternatives to Microsoft Office (including OpenOffice) and wrote that "while none of the alternative suites promise ... full compatibility with Microsoft Office-created documents, in general, they do a decent job of translating Microsoft ".doc", ".ppt" and ".xls" file formats":
IT AsiaOne-特价商品-您的选购 http://it.asia1.com.sg/specials/mmedia20020724_001.html
IT AsiaOne - Specials - Yours For The Picking http://it.asia1.com.sg/specials/mmedia20020724_001.html
其他链接:
OpenOffice.org主页 http://www.openoffice.org/
OpenOffice.org Home Page http://www.openoffice.org/
Ghostscript主页 http://www.cs.wisc.edu/~ghost/
Ghostscript Home Page http://www.cs.wisc.edu/~ghost/
PHP主页 http://www.php.net/
Google搜索策略:
Google search strategy:
openoffice脚本pdf Linux ://www.google.com/search?q = openoffice%20scripting%20pdf%20linux
openoffice scripting pdf linux ://www.google.com/search?q=openoffice%20scripting%20pdf%20linux
openoffice打印命令行" ://www.google.com/search?q = openoffice%20scripting%20pdf%20linux
openoffice print "command line" ://www.google.com/search?q=openoffice%20scripting%20pdf%20linux
接下来是从命令行中搜索命令行参数" openoffice.org主页.
followed by a search for "command line parameters" from the openoffice.org home page.
ref: http://answers.google.com/answers/threadview/id/177241.html
这篇关于PHP将Excel(.xls)转换为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!