Problem with Workbook.Save(""-FileFormatType.Pdf- SaveType.OpenInExcel- httpResponse)

We are trying to convert Excel to PDF using

Workbook.Save("",FileFOrmtaType.Pdf,SaveType.OpenInExcel,httpResponse).

But when we do the same thing uing following steps it woks fine:

1. workbook.Save() to store file in local filesystem in pdf format.

2. reading that files & generating response.

Is there anything I am doing wrong ?

Or is there any better way available to convert Excel File to PDF & Open it in response ?

Hi,

I think you may try:

[C#]



//Creating an Workbook object


Workbook workbook = new Workbook();


//… Your code goes here



//Save in pdf format and send the file to the client browser, he may open the file in


//some application or save it to some location


workbook.Save(“Report.pdf, SaveType.OpenInBrowser, FileFormatType.Pdf, Response);


Response.End();



[VB.NET]



‘Creating an Workbook object


Dim workbook As Workbook = New Workbook()


’… Your code goes here



'Save in pdf format and send the file to the client browser, he may open the file in


'some application or save it to some location


workbook.Save(“Report.pdf, SaveType.OpenInBrowser, FileFormatType.Pdf, Response)


Response.End()


See the document: http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/saving-files.html

Thank you.

Hi,

When I tried this code segment Excel file opened in Excel not in a PDF , following is the code lines I used for this.

//Instantiate a new Workbook object.

Workbook book = new Workbook();

book.Open("c:\\test.xls");

//Save the workbook as a PDF File

book.Save("yahoo.pdf", SaveType.OpenInBrowser, FileFormatType.Pdf, HttpContext.Current.Response);

Hi,

Please add Response.End(); to your code (after book.Save() line) and let us know if it works or not.

Thank you.

H

Thank you for considering Aspose.

Please use SaveType.OpenInExcel and Response.End() in your code. I tested using the below sample code and it works fine and opens the file in Adobe Acrobat Reader (for Pdf File).

//Instantiate a new Workbook object.

Workbook book = new Workbook();

book.Open("c:\\test.xls");

//Save the workbook as a PDF File

book.Save("yahoo.pdf", SaveType.OpenInExcel, FileFormatType.Pdf, Response);

Response.End();

Also, you may check the following online demo for your reference:

GitHub

GitHub - aspose-cells/Aspose.Cells-for-.NET: Aspose.Cells for .NET examples,…

Aspose.Cells for .NET examples, plugins and showcases - GitHub - aspose-cells/Aspose.Cells-for-.NET: Aspose.Cells for .NET examples, plugins and showcases

Thank You & Best Regards,

Thanks for the reply but I had tried it with OpenInExcel also , when I tried to open this PDF I got attached error message while opening PDF file .

Please find attached excel file I am trying to convert. I am using response.end() . I forgot to paste complete code last time :

//Instantiate a new Workbook object.

Workbook book = new Workbook();

book.Open("c:\\test.xls");

//Save the workbook as a PDF File

book.Save("yahoo.pdf", SaveType.OpenInExcel, FileFormatType.Pdf, HttpContext.Current.Response);

// HttpContext.Current.Response.Buffer = true;

// HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=Report " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + ".pdf");

// HttpContext.Current.Response.ContentType = "application/pdf";

// HttpContext.Current.Response.TransmitFile("C:\\cot\\yahoo.pdf");

HttpContext.Current.Response.End();

Hi,

Thank you for considering Aspose.

Well, I tried your file with the attached latest version of Aspose.Cells and it opens fine without any issue. Please try the latest version and let us know if it works fine for you.

Thank You & Best Regards,

Wow that worked like a magic . Thank you very much.

We already have license to Aspose I don't know complete terms but just checking is the available for all the licensed user's or we need to purchase special copy ?

Hi,

Thank you for considering Aspose.

Well, If your license is still valid, you can use the provide Aspose.Cells for .NET latest fix. You may verify this by opening your license file in a notepad and check for the expiry date.

Thank You & Best Regards,