timetoquitcoding
timetoquitcoding

Reputation: 45

C# NPOI library missing?

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

Upvotes: 1

Views: 1607

Answers (1)

Roman Marusyk
Roman Marusyk

Reputation: 24569

You need to use XSSFWorkbook instead of Workbook

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

Upvotes: 1

Related Questions