using MSExcel = Microsoft.Office.Interop.Excel;
private bool exceltoPDF(string sourcePath, string targetPath)
{
bool result;
object missing = Type.Missing;
MSExcel.ApplicationClass application = null;
MSExcel.Workbook workBook = null;
try
{
application = new MSExcel.ApplicationClass();
object target = targetPath;
workBook = application.Workbooks.Open(sourcePath, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing, missing);
workBook.ExportAsFixedFormat(MSExcel.XlFixedFormatType.xlTypePDF, target, MSExcel.XlFixedFormatQuality.xlQualityStandard
, true, false, missing, missing, missing, missing);
result = true;
}
catch
{
result = false;
}
finally
{
if (workBook != null)
{
workBook.Close(true, missing, missing);
workBook = null;
}
if (application != null)
{
application.Quit();
application = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
}
return result;
}
c# excel 转 pdf
于 2019-09-12 08:54:00 首次发布