Free Support Forum - aspose.com

Save in pdf formaat of a worksheet

hi, I have a workbook containing 3 sheets. sheet 1 is for input, sheet 2 for calculation, sheet 3 for output.

I need to save and print sheet 3(output) only post entering data in sheet 1. when i am using workbook.save(option1,option,…) it is saving complete workbook in pdf/excel format. i have not found wookshhet.save() method to save a single wooksheet.

Kindly guide me.


Hi,

Thanks for your posting and using Aspose.Cells for .NET.

You can convert your workbook having multiple worksheets into multiple pdf files.

Here is a sample code for your reference.

[C#]


string filePath = @“C:\Downloads\test.xlsx”;


Workbook workbook = new Workbook(filePath);


int sheetCount = workbook.Worksheets.Count;


//Make all sheets invisible except first

for (int i = 1; i < workbook.Worksheets.Count; i++)

{

     workbook.Worksheets[i].IsVisible = <span class="kwrd">false</span>;<br>

}//for


//Take pdfs of each sheet

for (int j = 0; j < workbook.Worksheets.Count; j++)

{

Worksheet ws = workbook.Worksheets[j];


Debug.Print("Processing: " + ws.CodeName);


workbook.Save(“F:\downloads\sheet-” + ws.CodeName + “.pdf”);


if (j < workbook.Worksheets.Count - 1)

{

              workbook.Worksheets[j + 1].IsVisible = <span class="kwrd">true</span>;<br>
              workbook.Worksheets[j].IsVisible = <span class="kwrd">false</span>;<br>
     }<span class="rem">//if</span><br>

}//for

Hi,


I have tried the above code. it is giving required output but the value of calculated field in output sheet is not coming. it is printed as “#Value!”.

Run time cell value is not updated in output sheet.

Please help.



Hi,


Please add a line before saving to PDF,
e.g
Workbook.CalculateFormula();

Thank you.

Hi,


I have already added this function before save, but still my calculated cell value is not displaying.
is there any function to do full worksheet refresh?

Hi,


Please paste your sample code (runnable) here with your input Excel file(s) if you have any. Also provide us the output PDF file here. We will check your issue soon.

Thank you.

Hi,


PFA file containing
1. Excel file which needs to convert into pdf
2. PDF output
3. code file.

Hi,


Your worksheet is protected, please either give us the password or provide us the unprotected version of your template Excel file, so that we need to evaluate your issue in Ms Excel and then by Aspose.Cells product to render to PDF file.

Thank you.