Spara angivna arkpapper till PDF

Som standard sparar Aspose.Cells alla synliga arkpapper i en arbetsbok till en pdf-fil. Med PdfSaveOptions.SheetSet alternativet kan du spara angivna arkpapper till en pdf-fil. t.ex. kan du spara aktivt arkpapp till pdf, spara alla arkpapper (både synliga och dolda arkpapper) till pdf, spara anpassade flera arkpapper till pdf.

Spara aktivt arkpapp till PDF

Om du bara vill exportera det aktiva arkpappret till pdf, kan du uppnå detta genom att skicka SheetSet.Active till PdfSaveOptions.SheetSet alternativet.

Arket Ark2 är det aktiva arkpappret i källfilen sheetset-example.xlsx.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Open the template excel file
Workbook wb = new Workbook("sheetset-example.xlsx");
// Set active sheet to output
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.SheetSet = SheetSet.Active;
// Save the pdf file with PdfSaveOptions
wb.Save("output.pdf", pdfSaveOptions);

Spara alla arkpapper till PDF

SheetSet.Visible indikerar synliga ark i en arbetsbok, och SheetSet.All indikerar alla ark inklusive både synliga ark och dolda/osynliga ark i en arbetsbok. Om du vill exportera alla ark till pdf, kan du helt enkelt skicka SheetSet.All till PdfSaveOptions.SheetSet alternativet.

Källfilen sheetset-example.xlsx innehåller alla fyra ark med dolt ark Ark3.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Open the template excel file
Workbook wb = new Workbook("sheetset-example.xlsx");
// Set all sheets to output
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.SheetSet = SheetSet.All;
// Save the pdf file with PdfSaveOptions
wb.Save("output.pdf", pdfSaveOptions);

Spara angivna arbetsblad som PDF

Om du vill exportera önskade/anpassade flera ark till pdf, kan du uppnå detta genom att skicka flera arkindex till PdfSaveOptions.SheetSet alternativet.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Open the template excel file
Workbook wb = new Workbook("sheetset-example.xlsx");
// Set custom multiple sheets(Sheet1, Sheet3) to output
SheetSet sheetSet = new SheetSet(new int[] { 0, 2 });
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.SheetSet = sheetSet;
// Save the pdf file with PdfSaveOptions
wb.Save("output.pdf", pdfSaveOptions);