在将Excel渲染为PDF时忽略错误
Contents
[
Hide
]
可能的使用场景
有时,当你将Excel文件转换为PDF时,会出现错误或异常,导致转换过程中断。你可以使用PdfSaveOptions.IgnoreError属性在转换过程中忽略所有这样的错误。这样,转换过程将顺利完成,而不会抛出任何错误或异常,但可能会丢失数据。因此,请仅在数据丢失不是关键问题时使用此属性。
在将Excel渲染为PDF时忽略错误
以下代码加载了示例Excel文件(55541813.xlsx),但示例Excel文件存在错误,在17.11版本中将其转换为PDF时会引发错误。但由于我们使用了PdfSaveOptions.IgnoreError属性,所以不会引发错误。但是,以下截图中显示的一个圆角红色箭头形状会丢失。
示例代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
//Load the Sample Workbook that throws Error on Excel2Pdf conversion | |
Workbook wb = new Workbook("sampleErrorExcel2Pdf.xlsx"); | |
//Specify Pdf Save Options - Ignore Error | |
PdfSaveOptions opts = new PdfSaveOptions(); | |
opts.setIgnoreError(true); | |
//Save the Workbook in Pdf with Pdf Save Options | |
wb.save("outputErrorExcel2Pdf.pdf", opts); |