接口 Excel._Application 的 QueryInterface 失败。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidCastException: 接口 Excel._Application 的 QueryInterface 失败。
源错误:行 125: colIndex = 0
行 126:
行 127: xlBook = xlApp.Workbooks().Add
行 128:
行 129: xlSheet = xlBook.Worksheets("sheet1")
源文件: D:\Contract\Components\ToExcel.vb 行: 127 怎么解决阿???在权限dcomcnfg中设置权限不起作用阿!!!
各位兄弟,帮帮我1!!!
万分谢谢!!!!!!!!!!!!!!!!!Public Function WriteExcel(ByVal inputTable As System.Data.DataTable, ByVal strFileName As String) As String
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet xlApp = New Excel.Application
xlBook = xlApp.Workbooks.Add
xlSheet = xlBook.Worksheets.Add xlSheet.Name = strFileName Dim OneRow As DataRow, OneCol As DataColumn
Dim I, J As Integer For Each OneRow In inputTable.Rows
I += 1
J = 0
For Each OneCol In inputTable.Columns
J += 1
xlSheet.Cells(I, J).Value = OneRow(OneCol)
Next
Next xlSheet.Range("A1").AutoFilter(Field:=1) Dim xlsFileName As String = strFileName & ".xls"
xlSheet.SaveAs(ConfigurationSettings.AppSettings("ExcelDir") & xlsFileName)
'ConfigurationSettings.AppSettings("ExcelDir")
xlBook.Close()
xlApp.Quit() xlSheet = Nothing
xlBook = Nothing
xlApp = Nothing Return xlsFileName
End Function
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidCastException: 接口 Excel._Application 的 QueryInterface 失败。
源错误:行 125: colIndex = 0
行 126:
行 127: xlBook = xlApp.Workbooks().Add
行 128:
行 129: xlSheet = xlBook.Worksheets("sheet1")
源文件: D:\Contract\Components\ToExcel.vb 行: 127 怎么解决阿???在权限dcomcnfg中设置权限不起作用阿!!!
各位兄弟,帮帮我1!!!
万分谢谢!!!!!!!!!!!!!!!!!Public Function WriteExcel(ByVal inputTable As System.Data.DataTable, ByVal strFileName As String) As String
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet xlApp = New Excel.Application
xlBook = xlApp.Workbooks.Add
xlSheet = xlBook.Worksheets.Add xlSheet.Name = strFileName Dim OneRow As DataRow, OneCol As DataColumn
Dim I, J As Integer For Each OneRow In inputTable.Rows
I += 1
J = 0
For Each OneCol In inputTable.Columns
J += 1
xlSheet.Cells(I, J).Value = OneRow(OneCol)
Next
Next xlSheet.Range("A1").AutoFilter(Field:=1) Dim xlsFileName As String = strFileName & ".xls"
xlSheet.SaveAs(ConfigurationSettings.AppSettings("ExcelDir") & xlsFileName)
'ConfigurationSettings.AppSettings("ExcelDir")
xlBook.Close()
xlApp.Quit() xlSheet = Nothing
xlBook = Nothing
xlApp = Nothing Return xlsFileName
End Function
//导入excel中
private void excel_btn_Click(object sender, System.EventArgs e)
{
Response.Clear();
Response.Buffer= true;
Response.Charset="GB2312";
string str =star_text.Text.Trim()+"--"+end_text.Text.Trim(); //设置文件名
Response.AppendHeader("Content-Disposition","attachment;filename="+str+".xls");
Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN",true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
MyDataGrid.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}