C# NPOI 库丢失了吗?

C# NPOI library missing?

我无法理解用什么替换工作簿,因为它不断收到错误“在当前上下文中不存在”。我不确定这是否与我缺少库或粗心有关.

using NPOI.HSSF.UserModel;
using NPOI.HSSF.Util;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;

        private void Exportbtn_Click(object sender, EventArgs e)
    {
        IWorkbook workbook = new HSSFWorkbook();
        ISheet sheet = workbook.CreateSheet("Job Applicant Data");

        byte[] data = File.ReadAllBytes("image.jpeg");
        int picInd = workbook.AddPicture(data, Workbook.PICTURE_TYPE_JPEG);   //The name 'Workbook' does not exist in the current context
        XSSFCreationHelper helper = workbook.GetCreationHelper() as XSSFCreationHelper;
        XSSFDrawing drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing;
        XSSFClientAnchor anchor = helper.CreateClientAnchor() as XSSFClientAnchor;
        anchor.Col1 = 0;
        anchor.Row1 = 0;
        XSSFPicture pict = drawing.CreatePicture(anchor, picInd) as XSSFPicture;
        pict.Resize();
   }

您需要使用 XSSFWorkbook 而不是 Workbook

int picInd = workbook.AddPicture(data, XSSFWorkbook.PICTURE_TYPE_JPEG);