调用WPS实现WORD转PDF、EXCEL转PDF,需安装WPS 2012,即所谓的v9版本。
ET._Application app = null;
ET._Workbook xls = null;
try
{
app = new ET.Application();
app.set_Visible(false);
xls = app.get_Workbooks().Open(source);
xls.ExportPdf(target);
xls.Close(false);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return;
}
finally
{
if (xls != null)
{
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xls);
}
if (app != null)
{
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(app);
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
try
{
File.Delete(source);
}
catch { }
}
评论