将 Excel 呈现为 PDF 时忽略错误
Contents
[
Hide
]
可能的使用场景
有时,当您将 Excel 文件转换为 PDF 时,会出现错误或异常,并且转换过程会终止。您可以在转换过程中使用忽略所有此类错误PdfSaveOptions.IgnoreError财产。这样,转换过程将顺利完成,不会抛出任何错误或异常,但可能会丢失数据。因此,请仅在数据丢失对您而言并不严重时才使用此属性。
将 Excel 呈现为 PDF 时忽略错误
下面的代码加载示例 Excel 文件但示例 Excel 文件是错误的,并在执行过程中抛出错误转换为 PDF在 17.11 但因为我们正在使用PdfSaveOptions.IgnoreError属性,它不会抛出错误。但是,此屏幕截图中显示的一个圆形红色箭头状形状丢失了。
示例代码
This file contains hidden or 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); |