我有我的asp項目(C#)的問題。asp excel錯誤80040154
我有以下錯誤:檢索COM類工廠CLSID {00024500-0000-0000-C000-000000000046}失敗,原因是以下錯誤組件:80040154拋出當我嘗試生成Excel來自服務器的文件。我已經看到一些關於它的帖子,我不知道它們是否適用於我,也不能解決我的問題。讓我告訴你我的代碼並解釋。
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
private Excel.Application oXL;
private Excel._Workbook oWB;
private ExcelFile f;
protected void bExcel_Click(object sender, EventArgs e)
{
if (Session["mode"] == null)
Response.Redirect(accueil);
// Set the values
oXL = new Excel.Application();
oWB = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
f = new ExcelFile((Excel._Worksheet)oWB.ActiveSheet);
oXL.Visible = true;
/* displaying data from a gridview, non revelant here (?) */
oXL.Visible = true;
f = null;
oXL = null;
oWB = null;
}
和錯誤的解釋(線225):
Erreur source:
Ligne 224 : // Set the values
Ligne 225 : oXL = new Excel.Application();
Ligne 226 : oWB = (Excel._Workbook) oXL.Workbooks.Add(Missing.Value));
Ligne 227 : f = new ExcelFile((Excel._Worksheet)oWB.ActiveSheet);
好了,所以我有這個問題時,我嘗試生成從服務器Excel文件,但不是我使用本地版本運行debbugging模式(代碼有效)。我公司的所有工作站都在計算機上安裝了MS Office Excel,但沒有安裝我正在使用的服務器,而我的問題是是否有解決方案,無需在服務器上安裝Excell?
我試圖避免在服務器上安裝Excel,因爲服務器不是來自我的服務,所以我想避免它(但如果它是唯一的(也是最好的/安全的)解決方案,我會這樣做)如果我能。 我試圖複製服務器上的程序集文件夾中的庫(因爲所有的工作站都是一樣的,引用應該工作嗎?)但我找不到允許從服務器訪問庫的權限(我希望我不會解釋它太糟糕)。
由於提前,
編輯:有,我不明白一件事,那就是在已經寫在上面的代碼,Excel應用程序可以推出這樣的:
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=registrationData.xls");
// Pour les caractères spéciaux (é, à, etc...)
Response.ContentEncoding = System.Text.Encoding.Unicode;
Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
using (StringWriter sw = new StringWriter())
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
Table table = new Table();
TableRow tRow = new TableRow();
/* Adding each information of the grid using tRow.Cells.Add() */
table.RenderControl(htw);
// Response needs the Htmlwriter
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
}
這是工作,沒有安裝Excel,因爲(我不知道)它只調用Excel應用程序,填充緩衝區(StringWriter)。但我不想使用表格,因爲表格使用起來很無聊,而且我已經使用Interop製作了該文件... 如果我能找到使用安裝在服務器上的程序集的權限,站有Excel,我應該能夠使用它的代碼使用方式?
IME您必須將應用程序的COM接口安裝在託管應用程序的計算機上。 –
否;沒有Excel就不能使用Excel。而且,在服務器上使用Excel是一個非常糟糕的主意。 – SLaks