通过NPOI将图像插入单元格

时间:2012-03-07 08:33:33

标签: asp.net image excel npoi

我正在使用NPOI生成excel文件。我的要求是将图像插入单元格。但是我有一个问题。如何使用NPOI在一个单元格中插入图像?有没有人之前解决过这个问题?

  protected void Button1_Click(object sender, EventArgs e)
    {
        InitializeWorkbook();
        ISheet sheet1 = hssfworkbook.CreateSheet("PictureSheet");


        HSSFPatriarch patriarch = (HSSFPatriarch)sheet1.CreateDrawingPatriarch();

        //create the anchor
        HSSFClientAnchor anchor;
        anchor = new HSSFClientAnchor(0, 0, 0, 255, 2, 2, 4, 6);
        anchor.AnchorType = 0;




        picture.LineStyle = HSSFPicture.OBJECT_TYPE_LINE;
        WriteToFile();
    }

    private  int LoadImage(string path, HSSFWorkbook wb)
    {

        FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read);
        byte[] buffer = new byte[file.Length];
        file.Read(buffer, 0, (int)file.Length);
        return wb.AddPicture(buffer, PictureType.JPEG);

    }

0 个答案:

没有答案