I want to output two sheets in an Excel workbook, and merge into single pdf, I found that when I call Worksheet.Dispose(), the result is incorrect (different pages, different sheet), , is there any guideline for this problem?
Another problem is equation in cell F1 didn't render in output pdf file, whether calling worksheet.Dispose() or not.
Thanks in advance.
- Code: Select all
Workbook workbook = new Workbook();
workbook.LoadFromFile("test.xlsx", ExcelVersion.Version2016);
string[] sheets = { "001", "002" };
List<MemoryStream> pdfList = new List<MemoryStream>();
for (int i = 0; i < sheets.Length; i++)
{
Worksheet ws = workbook.Worksheets[sheets[i]];
if (ws == null) continue;
MemoryStream stream = new MemoryStream();
ws.SaveToPdfStream(stream);
pdfList.Add(stream);
// *** This line produces incorrect pdf file
//ws.Dispose();
}
string outputFile = "result.pdf";
PdfDocumentBase pdf = PdfDocument.MergeFiles(pdfList.ToArray());
pdf.Save(outputFile);
System.Diagnostics.Process.Start(outputFile);
workbook.Dispose();