0

我试图在每次成功更新后使用 ExcelDataReader 将记录的结果写入 Excel 文件。目前,该功能在我通过 Visual Studio 运行的机器上运行良好,但是,一旦从我们的 Web 服务器执行相同的功能,就会出现以下错误:

错误:检索具有 CLSID {00024500-0000-0000-C000-000000000046} 的组件的 COM 类工厂失败,原因是以下错误:80040154 未注册类(来自 HRESULT 的异常:0x80040154 (REGDB_E_CLASSNOTREG))。

目前,我不确定如何解决此错误。请帮忙。

我的执行代码的代码隐藏如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BL.WebUserProvider;
using VO.WebUserProvider;
using System.Data;
using Excel;

    private void ExportDataSetToExcel(DataSet ds)
        {

            // Export Data into EXCEL Sheet
            ApplicationClass ExcelApp = new ApplicationClass();
            ExcelApp.Application.Workbooks.Add(Type.Missing);

            // Write data into excel sheet cells
            for (int i = 1; i < ds.Tables[0].Rows.Count + 2; i++) // Row Count accounts for "Column" row and itteration starting at index 1 (Confusing...I know)
            {
                for (int j = 1; j < ds.Tables[0].Columns.Count + 1; j++)
                {
                    if (i == 1)
                        ExcelApp.Cells[i, j] = ds.Tables[0].Columns[j - 1].ToString();
                    else
                        ExcelApp.Cells[i, j] = ds.Tables[0].Rows[i - 2][j - 1].ToString();
                }
            }

            // save excel file 
            ExcelApp.ActiveWorkbook.SaveCopyAs(string.Format("{0}-{1}-{2}  {3}.{4}.{5} - {6} records.xlsx",
                DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, ds.Tables[0].Rows.Count));

            ExcelApp.ActiveWorkbook.Saved = true;
            ExcelApp.Quit();
        }
4

0 回答 0