2015-01-20 1 views
0

누구든지 Excel에서 PDF로 변환하는 것을 도와주세요. Microsoft Office 2003이 서버에 설치되었습니다. Microsoft Office 2010에서 작동하는 코드가 있습니다. XlFixedFormatType은 2003에서 지원되지 않으므로 여기서 실패하고 있습니다.Office 2003을 사용하여 C#으로 Excel을 PDF로 변환

도움을 주시면 대단히 감사하겠습니다.

감사합니다. Praveen.

답변

0
using System; 
using System.IO; 
using UDC; 
using Excel = Microsoft.Office.Interop.Excel; //using Excel; in VS2003 

namespace ExcelToPDF 
{ 
class Program 
{ 
    static void PrintExcelToPDF(string ExcelFilePath) 
    { 
     //Create a UDC object and get its interfaces 
     IUDC objUDC = new APIWrapper(); 
     IUDCPrinter Printer = objUDC.get_Printers("Universal Document Converter"); 
     IProfile Profile = Printer.Profile; 

     //Use Universal Document Converter API to change settings of converterd document 
     Profile.PageSetup.ResolutionX = 600; 
     Profile.PageSetup.ResolutionY = 600; 

     Profile.FileFormat.ActualFormat = FormatID.FMT_PDF; 

     Profile.FileFormat.PDF.ColorSpace = ColorSpaceID.CS_TRUECOLOR; 
     Profile.FileFormat.PDF.Multipage = MultipageModeID.MM_MULTI; 

     Profile.OutputLocation.Mode = LocationModeID.LM_PREDEFINED; 
     Profile.OutputLocation.FolderPath = @"c:\UDC Output Files"; 
     Profile.OutputLocation.FileName = @"&[DocName(0)] -- &[Date(0)] -- &[Time(0)].&[ImageType]"; 
     Profile.OutputLocation.OverwriteExistingFile = false; 

     Profile.PostProcessing.Mode = PostProcessingModeID.PP_OPEN_FOLDER; 

     //Create a Excel's Application object 
     Excel.Application ExcelApp = new Excel.ApplicationClass(); 

     Object ReadOnly = true; 
     Object Missing = Type.Missing; //This will be passed when ever we don’t want to pass value 

     //If you run an English version of Excel on a computer with the regional settings are configured for a non-English language, you must set the CultureInfo prior calling Excel methods. 
     System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); 
     //Open the document from a file 
     Excel.Workbook Workbook = ExcelApp.Workbooks.Open(ExcelFilePath, Missing, ReadOnly, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing); 

     //Change active worksheet settings and print it 
     Excel.Worksheet Worksheet = (Excel.Worksheet)Workbook.ActiveSheet; 
     Excel.PageSetup PageSetup = Worksheet.PageSetup; 

     PageSetup.Orientation = Excel.XlPageOrientation.xlLandscape; 

     Object Preview = false; 
     Worksheet.PrintOut(Missing, Missing, Missing, Preview, "Universal Document Converter", Missing, Missing, Missing); 

     //Close the spreadsheet without saving changes 
     Object SaveChanges = false; 
     Workbook.Close(SaveChanges, Missing, Missing); 

     //Close Microsoft Excel 
     ExcelApp.Quit(); 
    } 

    static void Main(string[] args) 
    { 
     string TestFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFile.xls"); 
     PrintExcelToPDF(TestFilePath); 
    } 
    } 
} 

Microsoft Excel 97 이상, Microsoft Visual Studio 2003 이상이 필요합니다. 이것은 MSDN입니다.

+0

감사합니다. 이것에 대해 살펴 보겠습니다. :) – praveen

관련 문제