我想在 Excel 工作簿的工作表中插入图像。我插入图像的代码在这里:
ISheet sheet = templateWorkbook.GetSheet(sheetName);
HSSFPatriarch patriarch = (HSSFPatriarch)sheet.CreateDrawingPatriarch();
//IDrawing patriarch = (IDrawing)sheet.CreateDrawingPatriarch();
//HSSFPatriarch patriarch = sheet1.CreateDrawingPatriarch();
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0,
start.Col, start.Row, end.Col, end.Row);
anchor.AnchorType = 2;
int pictureIdx = 0;
using (FileStream fs = new FileStream(f.GetServerPathOfFile(imagePath), FileMode.Open))
{
byte[] bytes = new byte[fs.Length];
fs.Write(bytes, 0, (int)fs.Length);
pictureIdx = templateWorkbook.AddPicture(bytes, PictureType.JPEG);
}
IPicture picture = patriarch.CreatePicture(anchor, pictureIdx);
我不知道我在哪里弄错了。代码运行良好,没有任何错误/异常。