简体   繁体   English

如何在Java中将MS-Excel文件转换为Pdf?

[英]How to convert ms-Excel file to Pdf in java?

因为我已经将JXL api用于excel,但是现在我想将其转换为pdf文件,所以请告诉我如何更改我的代码以将excel转换为pdf

You could use iText to create a pdf file in java and use Apache POI to access the data in the MS-EXCEL file. 您可以使用iText在Java中创建pdf文件,并使用Apache POI访问MS-EXCEL文件中的数据。 If you combine both, you could convert your excel file. 如果两者结合使用,则可以转换excel文件。

A raw example is given here 这里给出一个原始的例子

Also, there is this new API: You can try Aspose.Cells for Java which allows you to convert Excel file to PDF in Java applications. 另外,还有一个新的API:您可以尝试Java的Aspose.Cells ,它允许您在Java应用程序中将Excel文件转换为PDF。 It doesn't require MS Office/OpenOffice etc to be installed on your development or deployment machine. 不需要在开发或部署计算机上安装MS Office / OpenOffice等。 It also works on both Windows and Linux platforms. 它也可以在Windows和Linux平台上使用。 The code is very simple as shown below: 代码非常简单,如下所示:

    //Instantiate a new workbook with excel file path
Workbook workbook = new Workbook("F:\\FileTemp\\Book1.xls");

//Save the document in Pdf format
workbook.save("F:\\FileTemp\\MyPdfFile.pdf", FileFormatType.PDF);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM