Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Excel file and save as PDF. [closed]

Tags:

c#

excel

pdf

I have an Xlsx file that I want to open, populate it with data from back-end and then save it as PDF on the client. The process would create about a 100 files at a time.

I searched around the web and realize that it is not possible to use Excel Interop any more. Do I have to use XML SDK?

I cannot use any third-party products or APIs. It is either using Interop or XML but just looking for coding suggestions. I do have Adobe pro license and have used in Office Automation to save Excel files as PDF.

What are my options? Any recommendation would be greatly appreciated.

like image 571
user3150378 Avatar asked Jan 01 '14 23:01

user3150378


1 Answers

What do you mean with: "it is not possible to use Excel Interop any more"?

Office 2013 still have Interop library and it works perfectly fine under .NET 4.5.1 Just add Microsoft.Office.Interop.Excel assembly to your references and you are ready to go.

using System;
using Microsoft.Office.Interop.Excel;

namespace officeInterop
{
    class Program
    {
        static void Main(string[] args)
        {
            Application app = new Application();
            Workbook wkb = app.Workbooks.Open("d:\\x.xlsx");
            wkb.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, "d:\\x.pdf");
        }
    }
}
like image 161
PTwr Avatar answered Oct 13 '22 10:10

PTwr