Spara varje kalkylblad till en annan PDF-fil
Contents
[
Hide
]
Aspose.Cells stöder konvertering av XLS-filer (som innehåller bilder, diagram, etc.) till PDF-dokument. Aspose.Cells for .NET kan arbeta självständigt för att konvertera ett kalkylblad till PDF och du behöver inte använda Aspose.PDF for .NET för konverteringen. Konverteringen kräver inte att programvaran skapar eller använder några temporära filer eftersom hela processen kan göras i minnet.
Spara varje kalkylblad till en annan PDF-fil
Om du behöver spara varje kalkylblad i din Excel-mall för att generera olika PDF-filer, kan du enkelt uppnå detta. Du kan försöka gömma ark i filen och göra ett ark synligt i taget för att rendera till PDF.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Get the Excel file path | |
string filePath = dataDir + "input.xlsx"; | |
// Instantiage a new workbook and open the Excel, File from its location | |
Workbook workbook = new Workbook(filePath); | |
// Get the count of the worksheets in the workbook | |
int sheetCount = workbook.Worksheets.Count; | |
// Define PdfSaveOptions | |
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); | |
// Take Pdfs of each sheet | |
for (int j = 0; j < sheetCount; j++) | |
{ | |
Worksheet ws = workbook.Worksheets[j]; | |
//set worksheet to output | |
SheetSet sheetSet = new SheetSet(new int[] { ws.Index }); | |
pdfSaveOptions.SheetSet = sheetSet; | |
workbook.Save(dataDir + "worksheet-" + ws.Name + ".out.pdf", pdfSaveOptions); | |
} |
Om ditt kalkylblad innehåller formler är det bäst att ringaWorkbook.CalculateFormula()precis innan du renderar kalkylarket till formatet PDF. Om du gör det säkerställs att de formelberoende värdena räknas om och att de korrekta värdena återges i PDF.