Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Tue Mar 19, 2013 1:03 pm

Hi ,

Kindly give me the code sample for excel to pdf conversion using Spire.Xls.

i wanted to show one sheet per page in pdf irrespective of no of fields in excel sheet.

for example if the single sheet has 150 fields , the converted file needs to show those 150 fields of sheet in single pdf page.

i couldnt able to upload the xlsx, xls in this topic .

so please create some sample excel file with more than 100 fields and do the conversion process.

kindly provide the sample code for the same.

based on the output , i can go for purchase the same by convincing my managements .

Already there is talk is happening for word to pdf conversion , i wanted to done the excel to pdf using same spire DLL

reply me ASAP

Regards,
Arafath

araafathmd
 
Posts: 3
Joined: Mon Mar 18, 2013 1:38 pm

Wed Mar 20, 2013 5:34 am

Dear Arafath,

Thanks for your inquiry.
We also received this issue from your e-mail. Please try the code snippet below to implement it.
Code: Select all

            byte[] data = File.ReadAllBytes(excelfile);
            using (MemoryStream stream = new MemoryStream(data))
            {
                using (Workbook wb = new Workbook())
                {
                    wb.LoadFromStream(stream, ExcelVersion.Version2010);
                    foreach (Worksheet sheet in wb.Worksheets)
                    {
                        if (sheet.Columns.Count() ==0)
                        { continue; }

                        int lastColumn = sheet.LastColumn;
                        int lastRow = sheet.LastRow;
                        while (lastColumn > 0)
                        {
                            CellRange range = sheet.Range[1, lastColumn, lastRow, lastColumn];
                            if (range.IsBlank)
                            {
                                lastColumn--;
                                sheet.SetLastColumn(lastColumn);
                                continue;
                            }
                            else
                            {
                                sheet.AutoFitColumn(lastColumn);
                                break;
                            }
                        }
                    }
                    using (var cvt = new Spire.Xls.Converter.PdfConverter(wb))
                    {
                        using (PdfDocument doc = cvt.Convert(new PdfConverterSettings
                        {
                            FitSheetToOnePage = FitToPageType.NoScale
                        }))
                        {
                            doc.SaveToFile("TestExcelToPDF.pdf");
                        }
                    }
                   
                }
            }
            System.Diagnostics.Process.Start("TestExcelToPDF.pdf");


If you still have this issue or any other issue, please tell us.

Best Regards,
AmyE
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Mon Apr 29, 2013 2:06 pm

this command
Spire.Pdf.PdfDocument doc = cvt.Convert(new Spire.Xls.Converter.PdfConverterSettings { FitSheetToOnePage = Spire.Xls.Converter.FitToPageType.NoScale });

return error "Specified argument was out of the range of valid values.
Parameter name: FirstRow"

can u help me

anggunperpatih18
 
Posts: 2
Joined: Mon Apr 29, 2013 7:50 am

Tue Apr 30, 2013 3:56 am

Hello anggunperpatih18,

Thanks for your inquiry.
The issue has not been reproduced, could you please provide us your excel file if convenience so that we can repro it and figure out the solution for you.

If there are any questions, welcome to get it back to us.

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Thu May 02, 2013 9:17 am

Hello anggunperpatih18,

Has the issue been resolved? Could you please provide us your excel file if convenience so that we can repro it and figure out the solution for you.

If there are any questions, welcome to get it back to us.

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Wed Oct 02, 2013 3:34 pm

amy.zhao wrote:Dear Arafath,

Thanks for your inquiry.
We also received this issue from your e-mail. Please try the code snippet below to implement it.
Code: Select all

            byte[] data = File.ReadAllBytes(excelfile);
            using (MemoryStream stream = new MemoryStream(data))
            {
                using (Workbook wb = new Workbook())
                {
                    wb.LoadFromStream(stream, ExcelVersion.Version2010);
                    foreach (Worksheet sheet in wb.Worksheets)
                    {
                        if (sheet.Columns.Count() ==0)
                        { continue; }

                        int lastColumn = sheet.LastColumn;
                        int lastRow = sheet.LastRow;
                        while (lastColumn > 0)
                        {
                            CellRange range = sheet.Range[1, lastColumn, lastRow, lastColumn];
                            if (range.IsBlank)
                            {
                                lastColumn--;
                                sheet.SetLastColumn(lastColumn);
                                continue;
                            }
                            else
                            {
                                sheet.AutoFitColumn(lastColumn);
                                break;
                            }
                        }
                    }
                    using (var cvt = new Spire.Xls.Converter.PdfConverter(wb))
                    {
                        using (PdfDocument doc = cvt.Convert(new PdfConverterSettings
                        {
                            FitSheetToOnePage = FitToPageType.NoScale
                        }))
                        {
                            doc.SaveToFile("TestExcelToPDF.pdf");
                        }
                    }
                   
                }
            }
            System.Diagnostics.Process.Start("TestExcelToPDF.pdf");


If you still have this issue or any other issue, please tell us.

Best Regards,
AmyE
E-iceblue support team


thanks this helped a lot!!!!!

Ive been having to use 3rd party and the pdf never opens
but after some fiddling with this code on spire im really converting them now and super fast :)

regards jon

TheHult
 
Posts: 1
Joined: Wed Oct 02, 2013 3:29 pm

Fri Oct 04, 2013 6:00 am

TheHult wrote:
amy.zhao wrote:Dear Arafath,

Thanks for your inquiry.
We also received this issue from your e-mail. Please try the code snippet below to implement it.
Code: Select all

            byte[] data = File.ReadAllBytes(excelfile);
            using (MemoryStream stream = new MemoryStream(data))
            {
                using (Workbook wb = new Workbook())
                {
                    wb.LoadFromStream(stream, ExcelVersion.Version2010);
                    foreach (Worksheet sheet in wb.Worksheets)
                    {
                        if (sheet.Columns.Count() ==0)
                        { continue; }

                        int lastColumn = sheet.LastColumn;
                        int lastRow = sheet.LastRow;
                        while (lastColumn > 0)
                        {
                            CellRange range = sheet.Range[1, lastColumn, lastRow, lastColumn];
                            if (range.IsBlank)
                            {
                                lastColumn--;
                                sheet.SetLastColumn(lastColumn);
                                continue;
                            }
                            else
                            {
                                sheet.AutoFitColumn(lastColumn);
                                break;
                            }
                        }
                    }
                    using (var cvt = new Spire.Xls.Converter.PdfConverter(wb))
                    {
                        using (PdfDocument doc = cvt.Convert(new PdfConverterSettings
                        {
                            FitSheetToOnePage = FitToPageType.NoScale
                        }))
                        {
                            doc.SaveToFile("TestExcelToPDF.pdf");
                        }
                    }
                   
                }
            }
            System.Diagnostics.Process.Start("TestExcelToPDF.pdf");


If you still have this issue or any other issue, please tell us.

Best Regards,
AmyE
E-iceblue support team


thanks this helped a lot!!!!!

Ive been having to use 3rd party and the pdf never opens
but after some fiddling with this code on spire im really converting them now and super fast :)

regards jon

You are welcome and we are so glad that our solution is helpful. If you have any question, please feel free to tell us.
Harry
Technical Support / Developer,
e-iceblue Support Team
User avatar

harry.support
 
Posts: 180
Joined: Mon Nov 08, 2010 3:11 pm

Fri Nov 01, 2013 2:51 am

Hi there
I have encountered the same question with you recently.I usually convert pdf files using a pdf processing program.But it can not convert excel to pdf files.It can only convert pdf to png or some other image formats.So i want to get a new pdf converter.It's difficult for me to covnert pdf files using a code.Is there any method which can convert pdf directly?Thanks a lot.

Donna111
 
Posts: 1
Joined: Fri Nov 01, 2013 2:42 am

Fri Nov 01, 2013 6:29 am

Hello,

Thanks for your inquiry.
Our Spire.PDFConverter can meet your need. It just is a converter tool without writing code. It can convert popular files to PDF format. It includes converting Excel to PDF, Word to PDF, HTML to PDF, Text to PDF and Images to PDF.
Welcome to download and test Spire.PDFConverter.
Downloading link: http://www.e-iceblue.com/Download/downl ... r-now.html

Please write to us freely if you have further inquiry.

Best regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Thu Nov 07, 2013 10:10 am

Hello,

Did you test Spire.PDFConverter? How did it work?

Thanks for your feedback.

Best regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.XLS