Converting from Excel to PDF

I added the following code to the footer of the Excel file and it works perfectly there but for some reason when I then convert to PDF it only goes as far as 4 in the Total # of Pages. Is this because of a bug or because I am using the trial version of Aspose.Cells v 4.7.1

Thanks

pageSetup.SetFooter(1, "&P of &N" );

Hi,

After an initial test, we found the issue you have pointed out, we will fix it soon.

Thank you.

Thanks

I have another question about when saving the Excel to PDF. Is there any way to send the PDF to the browser. When I have tried it seems to want me to download an ActiveX component called MSXML 3.0? Is there any way to do it so it won't ask for it. I understand that you are converting the Excel to XML then to PDF.

Below is the code I am using:

workbook.Save( mapPath + "\\" + _fileName + ".xls" );

workbook.Open( mapPath + "\\" + _fileName + ".xls" );

workbook.Save( mapPath + "\\" + _fileName + ".pdf", SaveType.OpenInBrowser, FileFormatType.Pdf, Response );

I have one more question and that is when I do a Print Preview in Excel everything looks great but when I convert to PDF it doesn't have the exact same look to it. Is there some conversion issues that I need to be aware of that can take care of this. I am attaching an example of the Excel and the PDF I converted.

Thanks

Hi,

1)

miehlb:

I have another question about when saving the Excel to PDF. Is there any way to send the PDF to the browser.............

Please try our latest version v4.7.1 and add a line to your code if it works fine:

workbook.Save( mapPath + "\\" + _fileName + ".pdf", SaveType.OpenInBrowser, FileFormatType.Pdf, Response );

Response.End();

2).

We have found the issue converting your sample file i.e.., "Service_Summary_Report_05_20_2009_03_21_40.xls", we will look into your issue and get back to you soon.

Thank you.

Thanks for the quick response

1. I am using version 4.7.1 unless you have made some updates recently that will affect the code because I have tried it with the Response.End() but with no luck.

2. Thanks for looking into that file.

For #1 I have tried a few other items but with no luck. I keep getting a blank IE page

and it requesting that I download the MSXML ActiveX. Is there anything else I can try

to get it to work.

Thanks

Example of my code:

FileStream stream = new FileStream( mapPath + "\\Service_Summary_Report.pdf", FileMode.Open, FileAccess.Read, FileShare.Read);

try

{

int bufSize = (int)stream.Length;

byte[] buf = new byte[bufSize];

int bytesRead = stream.Read(buf, 0, bufSize);

Response.Clear();

Response.Buffer = true;

Response.ContentType = "application/pdf";

Response.OutputStream.Write(buf, 0, bytesRead);

Response.End();

}

finally

{

stream.Close();

}

Hi,

Well, it works fine on our end. I use a simple Asp.NET page to open the generated pdf file into Adobe reader, it works fine. I have IE browser type. Now, since you have not involved Aspose.Cells APIs, and it does not make any difference too. Could you give us your environment details, OS, .NET framework, IIS settings, Browser type, any other extensions.

Anyways, we will further look into your issue and get back to you soon.

Thank you.

I was able to get it to work on my end finally. For some strange reason it worked fine with my code and then it didn't so I can to change it so that the HTML headers did not show up at all. Not sure why it even worked in the first place but the code changes took care of it. Thanks for looking into it for me.

What is your ETA on getting the other bugs done? I appreciate all the feedback you have excellent support for a great product.

I was able to force the PDF to be downloaded by using the code below in case anyone else needs it:

workbook.Save( mapPath + "\\" + _fileName + ".xls" );

workbook.Open( mapPath + "\\" + _fileName + ".xls" );

workbook.Save( mapPath + "\\" + _fileName + ".pdf", FileFormatType.Pdf );

Response.Clear();

Response.AppendHeader("content-disposition", "attachment; filename=" + _fileName + ".pdf");

Response.ContentType = "text/plain";

Response.WriteFile( mapPath + "\\" + _fileName + ".pdf" );

Response.Flush();

Response.End();

Hi,

We are working on your other issues and hopefully, we can fix them soon.

Why don't you open the excel file then copy the xls file to pdf format, you may do it without opening the xls file, skip this step.

e.g

...............

workbook.Save( mapPath + "\\" + _fileName + ".xls" );

workbook.Save( mapPath + "\\" + _fileName + ".pdf", FileFormatType.Pdf );

Also, your code should work fine in the way as follows:

.....................

workbook.Save( mapPath + "\\" + _fileName + ".xls" );

MemoryStream ms = new MemoryStream();

workbook.Save(ms, FileFormatType.Pdf);

Response.ContentType = "application/pdf";

//This is same as OpenInExcel option

//Response.AddHeader( "content-disposition","attachment; filename=myfile.pdf");

//This is same as OpenInBrowser option

Response.AddHeader( "content-disposition","inline; filename=" + _fileName + ".pdf");

Response.BinaryWrite(ms.ToArray());

Response.End();

Thank you.

Thanks for the extra code to skip a step.

I implemented it in my code but it still did not force the browser to create a Save As dialog box but opened it in the Browser itself with Adobe imbedded. I used your code with mine to fix that by doing it below:

workbook.Save( mapPath + "\\" + _fileName + ".xls" );

MemoryStream ms = new MemoryStream();

workbook.Save( ms, FileFormatType.Pdf );

Response.Clear();

Response.AppendHeader("content-disposition", "attachment; filename=" + _fileName + ".pdf");

Response.ContentType = "text/plain";

Response.BinaryWrite( ms.ToArray() );

Response.Flush();

Response.End();

Sorry to bug you but I was wondering if you could tell me if the bugs I found would be fixed by this week or not? The reason I ask is because my company wanted to launch the software product we have developed and really want to use your API for the launch. I can at least let my boss know what to expect.

Thanks

Hi,

We will update you soon regarding your other issues we found.

Thank you.

Hi,

Thank you for considering Aspose.

Please try the attached latest version. We have fixed your mentioned issue.

Thank You & Best Regards,

Thanks it works great!!

I wanted to reply to this ticket because the version of Apose.Cells you gave me in this ticket worked great for my original issue but now a new one has been created.

When I do the following:

Workbook workbook = new Workbook();

workbook.open( _filePath );

It will open it but when I try to delete the file after opening it in

the finally area of try-catch-finally it says it can't because another process

has it. I can only assume that the Workbook has it and will not close it by default.

Can you please check that this is true with the version you gave me in this ticket?

Thanks

Nevermind I figured it out. The error message was that the process was already open so the file can't be deleted but the real error was that the file was in Excel 95 instead of 97-2003 so I am going to fix it on my side.

Thanks anyway.

Sorry I thought I had the solution but I am still running into an issue with closing the file.

The issue seems to be with an Excel file that is saved in this format "Microsoft Excel 97 - Excel 2003 & 5.0/95 Workbook". Workbook.Open will open it but will never close it correctly so when I do a File.Delete it says that the process still holds it instead of telling me the file is a BIFF7 so I don't have any recourse but to again ask you to look into please.

Thanks

Hi,

Well, we does close the streams. Actually, we do not support to read the file in the format "Microsoft Excel 97 - Excel 2003 & 5.0/95 Workbook" as it has records in Excel 5.0/95. I think that 's why the file is not read fine, so, you may get this exception.

Thank you.

It doesn't close for me when I deal with that particular kind of file unlike the rest of the files.

It completely keeps a lock on the file and will not release it yet it will work fine for all other Excel file types.

Is there any way I can close it manually in my code to make it release it?

Thanks