Ausgewählte Arbeitsblätter mit Node.js über C++ in PDF speichern
Standardmäßig speichert Aspose.Cells alle sichtbaren Arbeitsblätter in einer Arbeitsmappe als PDF. Mit der PdfSaveOptions.getSheetSet()-Option können Sie ausgewählte Arbeitsblätter in einer PDF speichern, z.B. das aktive Arbeitsblatt, alle sichtbaren (und ausgeblendeten) Arbeitsblätter oder benutzerdefinierte mehrere Arbeitsblätter.
Aktives Arbeitsblatt als PDF speichern
Wenn Sie nur das aktive Blatt in PDF exportieren möchten, können Sie dies erreichen, indem Sie SheetSet.getActive() an die PdfSaveOptions.getSheetSet()-Option übergeben.
Das Blatt Sheet2
ist das aktive Blatt der Quelldatei sheetset-example.xlsx.
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "sheetset-example.xlsx");
// Open the template excel file
const workbook = new AsposeCells.Workbook(filePath);
// Set active sheet to output
const pdfSaveOptions = new AsposeCells.PdfSaveOptions();
pdfSaveOptions.setSheetSet(AsposeCells.SheetSet.getActive());
// Save the pdf file with PdfSaveOptions
workbook.save("output.pdf", pdfSaveOptions);
Alle Arbeitsblätter in PDF speichern
SheetSet.getVisible() zeigt sichtbare Blätter in einer Arbeitsmappe an, und SheetSet.getAll() zeigt alle Blätter einschließlich sichtbarer und unsichtbarer Blätter an. Wenn Sie alle Blätter als PDF exportieren möchten, können Sie einfach SheetSet.getAll() an die PdfSaveOptions.getSheetSet()-Option übergeben.
Die Quelldatei sheetset-example.xlsx enthält alle vier Blätter mit dem versteckten Blatt Blatt3
.
const AsposeCells = require("aspose.cells.node");
const path = require("path");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "sheetset-example.xlsx");
// Open the template excel file
const workbook = new AsposeCells.Workbook(filePath);
// Set all sheets to output
const pdfSaveOptions = new AsposeCells.PdfSaveOptions();
pdfSaveOptions.setSheetSet(AsposeCells.SheetSet.getAll());
// Save the pdf file with PdfSaveOptions
workbook.save("output.pdf", pdfSaveOptions);
Bestimmte Arbeitsblätter als PDF speichern
Wenn Sie gewünschte/benutzerdefinierte mehrere Blätter in PDF exportieren möchten, können Sie dies erreichen, indem Sie mehrere Blattsindizes an PdfSaveOptions.getSheetSet() übergeben.
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "sheetset-example.xlsx");
// Open the template excel file
const workbook = new AsposeCells.Workbook(filePath);
// Set custom multiple sheets(Sheet1, Sheet3) to output
const sheetSet = new AsposeCells.SheetSet([0, 2]);
const pdfSaveOptions = new AsposeCells.PdfSaveOptions();
pdfSaveOptions.setSheetSet(sheetSet);
// Save the pdf file with PdfSaveOptions
workbook.save("output.pdf", pdfSaveOptions);
Arbeitsblätter nach PDF neu anordnen
Wenn Sie Blätter in eine andere Reihenfolge bringen möchten (z. B. in umgekehrter Reihenfolge), um sie als PDF zu exportieren, ohne die Quelldatei zu ändern, können Sie dies erreichen, indem Sie die neu angeordneten Blattindizes an die PdfSaveOptions.getSheetSet()-Option übergeben.
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "sheetset-example.xlsx");
// Open the template excel file
const wb = new AsposeCells.Workbook(filePath);
// Reorder sheets(Sheet1, Sheet2, Sheet3, Sheet4) to sheets(Sheet4, Sheet3, Sheet2, Sheet1)
const sheetSet = new AsposeCells.SheetSet([3, 2, 1, 0]);
const pdfSaveOptions = new AsposeCells.PdfSaveOptions();
pdfSaveOptions.setSheetSet(sheetSet);
// Save the pdf file with PdfSaveOptions
wb.save("output.pdf", pdfSaveOptions);