在将Excel渲染为PDF时忽略错误
Contents
[
Hide
]
可能的使用场景
有时候,当您将Excel文件转换为PDF时,会出现错误或异常,并且转换过程会终止。您可以通过使用PdfSaveOptions.IgnoreError属性来忽略转换过程中的所有这些错误。这样,转换过程将在不抛出任何错误或异常的情况下平滑完成,但可能会出现数据丢失。因此,请只在对您来说数据丢失并不重要时使用此属性。
在将Excel渲染为PDF时忽略错误
以下代码加载了示例Excel文件,但示例Excel文件存在错误,并在转换为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-.NET | |
//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.IgnoreError = true; | |
//Save the Workbook in Pdf with Pdf Save Options | |
wb.Save("outputErrorExcel2Pdf.pdf", opts); |