tmgc200705 2023-08-29 10:05 采纳率: 0%
浏览 37

C#与EXCEL交互出现问题

学习CAD二开需要与EXCEL交互,从Nuget下了netOffice库。
学习到以下代码,但是总是出错,不知道怎么处理,错误在
“Excel.Worksheet sheet =(Excel.Worksheet) book.Worksheets[1];”这一行,
错误的原因:NetOffice.NetOfficeException:“Factory is not initialized with NetOffice assemblies.”


using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Excel = NetOffice.ExcelApi;

namespace _02创建图形
{
    public  class ExcelDemo
    {
        [CommandMethod("ExtToExcelDemo")]
        public void ExtToExcelDemo()
        {            
            Excel.Application excelApp = new Excel.Application();
            Excel.Workbook book = excelApp.Workbooks.Add();
            Excel.Worksheet sheet =(Excel.Worksheet) book.Worksheets[1];
            sheet.Cells[1, 1].Value = "吸湿性";
            book.Save();
            excelApp.Quit();
            excelApp.Dispose();
        }
    }
}

  • 写回答

2条回答 默认 最新

  • 赵4老师 2023-08-29 14:50
    关注

    百度搜“NetOffice.NetOfficeException:“Factory is not initialized with NetOffice assemblies.””

    评论

报告相同问题?

问题事件

  • 创建了问题 8月29日