1

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();
   }
  • Where did you get `Workbook.PICTURE_TYPE_JPEG` from? As you've posted below this wants a PictureType enum. – Rup Jan 06 '20 at 01:32
  • And you're mixing HSSF (=xls) and XSSF (=xlsx) classes here in a way I'd guess won't work. Which one do you want? – Rup Jan 06 '20 at 01:33

1 Answers1

1

You need to use XSSFWorkbook instead of Workbook

int picInd = workbook.AddPicture(data, XSSFWorkbook.PICTURE_TYPE_JPEG);
Roman Marusyk
  • 23,328
  • 24
  • 73
  • 116