Unisci File con Node.js tramite C++

Introduzione

Aspose.Cells fornisce diversi metodi per unire file. Per file semplici con dati, formattazione e formule, si può usare il metodo Workbook.combine(Workbook) per combinare diversi libri di lavoro, e il metodo Worksheet.copy(Worksheet) per copiare fogli di lavoro in un nuovo libro. Questi metodi sono facili da usare ed efficienti, ma se hai molti file da unire, potresti trovare che richiedono molte risorse di sistema. Per evitarlo, usa il metodo statico **CellsHelper.mergeFiles(string[], string, string)**, un modo più efficiente per unire diversi file.

Unisci File Usando Aspose.Cells for Node.js via C++

Il seguente esempio di codice illustra come unire grandi file usando il metodo **CellsHelper.mergeFiles(string[], string, string)**. Prende due file semplici ma grandi, Book1.xls e Book2.xls. I file contengono solo dati formattati e formule.

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

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");

// Create an Array (length=2)
const files = new Array(2);
// Specify files with their paths to be merged
files[0] = path.join(dataDir, "book1.xls");
files[1] = path.join(dataDir, "Book2.xlsx");

// Create a cachedFile for the process
const cacheFile = path.join(dataDir, "test.txt");

// Output File to be created
const dest = path.join(dataDir, "output.xlsx");

// Merge the files in the output file. Supports only .xls files
AsposeCells.CellsHelper.mergeFiles(files, cacheFile, dest);
console.log(cacheFile);
// Now if you need to rename your sheets, you may load the output file
const workbook = new AsposeCells.Workbook(path.join(dataDir, "output.xlsx"));

let i = 1;

// Browse all the sheets to rename them accordingly
const worksheets = workbook.getWorksheets();
for (let j = 0; j < worksheets.getCount(); j++) {
worksheets.get(j).setName(`Sheet1${i}`);
i++;
}

// Re-save the file
workbook.save(path.join(dataDir, "output.xlsx"));