使用C++ via Node.js将XLSX文件转换为PDF格式

将Excel转换为PDF

这个示例使用Excel文件(SampleInput.xlsx)作为模板。工作簿包含带有图表和图片的工作表。每个工作表使用不同类型的格式,包括字体、属性、颜色、阴影效果和边框。第一个工作表有柱状图,最后一个工作表有图片。

模板Excel文件

模板文件包含三个工作表,包括图表和作为媒体的图片。第一个工作表有图表,最后一个工作表包含图片,如下面的截图所示。

todo:image_alt_text todo:image_alt_text
第一个工作表 (销售预测) 第二个工作表 (销售报告)
todo:image_alt_text todo:image_alt_text
第三个工作表 (数据录入) 最后一个工作表 (图像)

转换过程

const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const designerFile = path.join(dataDir, "SampleInput.xlsx");
const pdfFile = path.join(dataDir, "Output.out.pdf");

try {
// Open the template excel file
const wb = new AsposeCells.Workbook(designerFile);

// Save the pdf file.
wb.save(pdfFile, AsposeCells.SaveFormat.Pdf);
} catch (e) {
console.log(e.message);
}

结果

当上述代码运行后,在应用程序目录的Files文件夹中创建了一个PDF文件。 以下屏幕截图显示了PDF页面。 请注意,页眉和页脚也在输出PDF文件中保留。

todo:image_alt_text todo:image_alt_text
第一个工作表 (销售预测) 第二个工作表 (销售报告)
todo:image_alt_text todo:image_alt_text
第三个工作表 (数据录入) 最后一个工作表 (图像)