相关疑难解决方法(0)

如果未安装Excel,如何创建Excel实例

在我的C#应用​​程序中,在Excel Interop dll(作为参考)的帮助下,我正在读/写excel文件.如果我把这个程序移动到没有安装office/excel的系统(想想干净的机器),我就会遇到以下错误.

System.Runtime.InteropServices.COMException(0x80040154):由于以下错误,检索CLSID为{00024500-0000-0000-C000-000000000046}的组件的COM类工厂失败:80040154未注册类(HRESULT异常:0x80040154(REGDB_E_CLASSNOTREG) )).

由于目标机器没有优秀,因此预计会出现上述错误.
我的问题是,除了在目标机器上注册Interop dll之外,还有其他方法可以使用我的程序吗?

c# excel interop comexception

20
推荐指数
2
解决办法
6万
查看次数

尝试使用EPPlus读取.xls文件时出错

以下代码适用于.xlsx,但它不适用于.xls.我收到此错误消息

无法打开包裹.包是一个OLE复合文档.如果这是加密包,请提供密码

string filepath = txtBrowse.Text;

FileStream stream = System.IO.File.Open(filepath, FileMode.Open, FileAccess.ReadWrite);
//1. Reading from a binary Excel file ('97-2003 format; *.xls)
IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);

FileInfo newFile = new FileInfo(filepath);

using (ExcelPackage package = new ExcelPackage(newFile))
{
    string sheetName = System.DateTime.Now.ToShortDateString();

    foreach (OfficeOpenXml.ExcelWorksheet sheet in package.Workbook.Worksheets)
    {
        // Check the name of the current sheet
        if (sheet.Name == sheetName)
        {
            package.Workbook.Worksheets.Delete(sheetName);
            break; // Exit the loop now
        }
    }

    ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(System.DateTime.Now.ToShortDateString());
}
Run Code Online (Sandbox Code Playgroud)

我该怎么做呢?

c# excel epplus

11
推荐指数
2
解决办法
3万
查看次数

标签 统计

c# ×2

excel ×2

comexception ×1

epplus ×1

interop ×1