6

I have an xlsx file that includes charts each in sheets. I want to save it as pdf file.

I made a sample using excel.interop:

Application excelApplication = new Application();
Workbook wkb = excelApplication.Workbooks.Open(oSlideMaster._FILE_PATH, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, Microsoft.Office.Interop.Excel.XlCorruptLoad.xlNormalLoad);

var basePath = HttpRuntime.AppDomainAppPath;
wkb.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, ExportExcelToPdfFullPathWithoutExt);

This code works on visual studio but it doesnt work on server without ms office 2007 or higher version installed.

Question is:

How can i convert (FREE) excel to pdf(include charts) without using excel.interop library. Because i dont want to install ms office on server side.

The point is that also: I tried some dll to convert excel to pdf, but i couldnt convert CHARTS only text i could convert successfully.

Thanks.

Download file.

Sample excel data

2
  • give your sample excel i have some code if working mean i will give you my answer.. Commented Feb 16, 2016 at 11:05
  • I am looking for a decent free version of this .... any updates on this? Commented Mar 28, 2018 at 15:36

3 Answers 3

0

Try with this following piece of code.

 excelworkBook.SaveAs(saveAsLocation);
 excelworkBook.Close();
 excel.Quit();
 bool flag=SaveAsPdf(saveAsLocation);

In this the saveAsLocation is the full path of the execelworkBook.After that it is converted into pdf using library Spire.Xls.For that add the reference Spire.Xls,which can be added to your project using Manage Nuget Packages.

private bool SaveAsPdf(string saveAsLocation)
  {
    string saveas = (saveAsLocation.Split('.')[0]) + ".pdf";
      try
        {
          Workbook workbook = new Workbook();
          workbook.LoadFromFile(saveAsLocation);

          //Save the document in PDF format

          workbook.SaveToFile(saveas, Spire.Xls.FileFormat.PDF);
          return true;
        }
       catch (Exception ex)
         {
           MessageBox.Show(ex.Message);
           return false;
         }
  }
Sign up to request clarification or add additional context in comments.

7 Comments

@Mennan: Yes.You can install it using Manage Nuget Packages.
thx also for xlsx is last version: nuget.org/packages/FreeSpire.XLS/7.8.0
Is this realy, absolutely free? Or is there any limits?
@VVN According to the license on nuget and the website linked to it, it's not free, it's limited and only the commercial version will go past the restrictions? Can you comment on that?
I've just tried it and got next message in my converted PDF document: "Free version is limited to 5 sheets per workbook and 200 rows per sheet. This limition is enforced during reading or writing XLSX, XLS or PDF files. When converting Excel files to PDF files, you can only get the first 3 pages of PDF file." Charts from the xlsx document haven't been converted as well. So, it's not the solution for a lot of cases.
|
0

download dll from http://www.gemboxsoftware.com/Spreadsheet/downloads

add reference and code

using System;
using System.Drawing;
using System.Text;
using GemBox.Spreadsheet;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");

        ExcelFile ef = ExcelFile.Load("test.xlsx");

        ef.Save("Convert.pdf");
    }
}

3 Comments

it works for only first sheet but i need free library
The Spreadsheet component from GemBox Software is not free. The trial version is limited to 150 rows. gemboxsoftware.com/spreadsheet/free-version
If you want to test it with an Excel file that exceeds the trial limits you need to add the following line after setting the license to prevent the crash: SpreadsheetInfo.FreeLimitReached += (sender, e) => e.FreeLimitReachedAction = FreeLimitReachedAction.ContinueAsTrial;
-1

You may consider Aspose.Cells for the task. See the sample .NET code for your reference:

e.g.

Sample code:

// Open an Excel file 
Workbook workbook = new Workbook("Book1.xlsx"); 
// Save the document in PDF format 
workbook.Save("output.pdf", SaveFormat.Pdf);

Also, see the document for your reference.

PS. I am working as Support developer/ Evangelist at Aspose.

1 Comment

The OP Clearly asks for a FREE option. It is NOT an invitation for everyone to use this post as Ad-Space to hock their subscription services (especially those that are thousands of dollars per dev, per year).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.