C#EXCEL转PDF

 Microsoft.Office.Interop.Excel.Application lobjExcelApp = null;
            Microsoft.Office.Interop.Excel.Workbooks lobjExcelWorkBooks = null;
            Microsoft.Office.Interop.Excel.Workbook lobjExcelWorkBook = null;


            string lstrTemp = string.Empty;
            object lobjMissing = System.Reflection.Missing.Value;


            try
            {
                lobjExcelApp = new Microsoft.Office.Interop.Excel.Application();
                lobjExcelApp.Visible = true;
                lobjExcelWorkBooks = lobjExcelApp.Workbooks;
                lobjExcelWorkBook = lobjExcelWorkBooks.Open(@"C:\Users\Administrator\Desktop\1.xlsx", true, true, lobjMissing, lobjMissing, lobjMissing, true,
                    lobjMissing, lobjMissing, lobjMissing, lobjMissing, lobjMissing, false, lobjMissing, lobjMissing);


                //Microsoft.Office.Interop.Excel 12.0.0.0之后才有这函数              
                //lstrTemp = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".xls"; //+ (lobjExcelWorkBook.HasVBProject ? 'm' : 'x');
                //lstrTemp = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".xls";  
                lobjExcelWorkBook.SaveAs(@"C:\Users\Administrator\Desktop\2.xlsx");
                //输出为PDF 第一个选项指定转出为PDF,还可以指定为XPS格式  
                lobjExcelWorkBook.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF, @"C:\Users\Administrator\Desktop\1.pdf");//, Microsoft.Office.Interop.Excel.XlFixedFormatQuality.xlQualityStandard, Type.Missing, false, Type.Missing, Type.Missing, false, Type.Missing);
                //lobjExcelWorkBooks.Close();
                //lobjExcelApp.Quit();

你可能感兴趣的:(C#)