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