C# NPOI library missing?

1.3k views Asked by At

I'm having trouble with understanding what to replace Workbook with as it keeps getting the error "doesn't exist in the current context. I'm not sure if it has to do with me missing a library or carelessness.

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();
   }
1

There are 1 answers

3
Roman Marusyk On BEST ANSWER

You need to use XSSFWorkbook instead of Workbook

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