使用C++在将Excel转换为PDF时忽略错误
Contents
[
Hide
]
可能的使用场景
有时在将您的Excel文件转换为PDF时,会发生错误或异常并终止转换过程。您可以在转换过程中使用PdfSaveOptions.PaginatedSaveOptions(PaginatedSaveOptions_Impl impl)*属性忽略所有此类错误。这样,转换过程将顺利完成而不会抛出任何错误或异常,但可能会丢失数据。因此,仅当数据丢失对您不关键时才使用此属性。
在将Excel渲染为PDF时忽略错误
以下代码加载了示例Excel文件,但该Excel文件存在错误,在转换为PDF的17.11中会抛出错误,但由于我们使用了PdfSaveOptions.PaginatedSaveOptions(PaginatedSaveOptions_Impl impl)*属性,不会抛出错误。然而,如此截图所示,一个圆角红色箭头形状会丢失。
示例代码
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Path of input excel file
U16String inputFilePath = srcDir + u"sampleErrorExcel2Pdf.xlsx";
// Path of output pdf file
U16String outputFilePath = outDir + u"outputErrorExcel2Pdf.pdf";
// Load the Sample Workbook that throws Error on Excel2Pdf conversion
Workbook wb(inputFilePath);
// Specify Pdf Save Options - Ignore Error
PdfSaveOptions opts;
opts.SetIgnoreError(true);
// Save the Workbook in Pdf with Pdf Save Options
wb.Save(outputFilePath, opts);
std::cout << "Workbook saved successfully with error ignored!" << std::endl;
Aspose::Cells::Cleanup();
}