用 Node.js 通过 C++ 加载工作簿中的特定工作表
Contents
[
Hide
]
默认情况下,Aspose.Cells会将整个电子表格加载到内存中。也可以只加载特定的工作表。这样可以提高性能,减少内存消耗。在处理由许多工作表组成的大型工作簿时,这种方法非常有用。
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Define a new Workbook.
let workbook;
// Load the workbook with the specified worksheet only.
const loadOptions = new AsposeCells.LoadOptions(AsposeCells.LoadFormat.Xlsx);
loadOptions.setLoadFilter(new CustomLoad());
// Create the workbook.
workbook = new AsposeCells.Workbook(path.join(dataDir, "TestData.xlsx"), loadOptions);
// Perform your desired task.
// Save the workbook.
workbook.save(path.join(dataDir, "outputFile.out.xlsx"));
这是 CustomLoad 类的实现。
const AsposeCells = require("aspose.cells.node");
class CustomLoad extends AsposeCells.LoadFilter {
startSheet(sheet) {
if (sheet.getName() === "Sheet2") {
// Load everything from worksheet "Sheet2"
this.setLoadDataFilterOptions(AsposeCells.LoadDataFilterOptions.All);
} else {
// Load nothing
this.setLoadDataFilterOptions(AsposeCells.LoadDataFilterOptions.Structure);
}
}
}