[C#] Convert Excel to PDF

 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Spire.Xls;

namespace ToPDF
{
    class Program
    {
        static void Main(string[] args)
        {
            string tempPath = HttpRuntime.AppDomainAppPath.ToString() + "\\Report\\";
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(tempPath + "Sample.xlsx", ExcelVersion.Version2010);
            for(int i = 0; i < workbook.Worksheets.Count; i++)
            {
                workbook.Worksheets[i].PageSetup.Orientation = PageOrientationType.Landscape;
                workbook.Worksheets[i].PageSetup.IsFitToPage = true;
            }
            workbook.SaveToFile(tempPath + "result.pdf", Spire.Xls.FileFormat.PDF);
         }
    }
}

參考網址
By Hao★

留言

熱門文章

[C#] 將DataTable轉換成Html格式表格

[MS SQL] 查詢所有Procedure