我写了个Excel转PDF的DLL(其中包含Acrobat Professional 6.0的引用),ASP.NET调用
但报以下错:System.Runtime.InteropServices.COMException: 服务器运行失败代码:
private static ACRODISTXLib.PdfDistiller6Class oDistiller = new ACRODISTXLib.PdfDistiller6Class();
private static Excel.Application msExcel = new Excel.ApplicationClass(); public bool ExcelToPDF()
{
string PostScriptFilePath;
string PDFFilePath;
try
{
PostScriptFilePath = "C:\\a.ps";
PDFFilePath = "C:\\a.pdf";
Excel.Workbook xBook = msExcel.Workbooks.Open("C:\\a.xls",Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value);
xBook.PrintOut(Missing.Value,Missing.Value,Missing.Value,Missing.Value,"Acrobat Distiller", true, false, PostScriptFilePath);
while (!System.IO.File.Exists(PostScriptFilePath))
{
}
xBook.Close(false,Missing.Value,Missing.Value);
xBook = null;
msExcel.Quit();
oDistiller.FileToPDF(PostScriptFilePath, PDFFilePath, "Print");
System.IO.File.Delete(PostScriptFilePath);
}
catch
{
msExcel.Quit();
return false;
}
return true;
}
但报以下错:System.Runtime.InteropServices.COMException: 服务器运行失败代码:
private static ACRODISTXLib.PdfDistiller6Class oDistiller = new ACRODISTXLib.PdfDistiller6Class();
private static Excel.Application msExcel = new Excel.ApplicationClass(); public bool ExcelToPDF()
{
string PostScriptFilePath;
string PDFFilePath;
try
{
PostScriptFilePath = "C:\\a.ps";
PDFFilePath = "C:\\a.pdf";
Excel.Workbook xBook = msExcel.Workbooks.Open("C:\\a.xls",Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value);
xBook.PrintOut(Missing.Value,Missing.Value,Missing.Value,Missing.Value,"Acrobat Distiller", true, false, PostScriptFilePath);
while (!System.IO.File.Exists(PostScriptFilePath))
{
}
xBook.Close(false,Missing.Value,Missing.Value);
xBook = null;
msExcel.Quit();
oDistiller.FileToPDF(PostScriptFilePath, PDFFilePath, "Print");
System.IO.File.Delete(PostScriptFilePath);
}
catch
{
msExcel.Quit();
return false;
}
return true;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货