1. 程式人生 > >解決NPOI批註設定不成功(在已存在的workbook中設定)

解決NPOI批註設定不成功(在已存在的workbook中設定)

                   FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate,FileAccess.ReadWrite);

                    HSSFWorkbook workbook = new HSSFWorkbook(fs);

                    HSSFSheet sheet1 = workbook.GetSheetAt(0) as HSSFSheet;

                    HSSFPatriarch patr = sheet1.CreateDrawingPatriarch() as HSSFPatriarch;


                    HSSFComment comment = patr.CreateCellComment(new HSSFClientAnchor(0, 0, 0, 0, 2, 3, 3, 4)) as HSSFComment;

                    comment.String = new HSSFRichTextString("Test Comment");
                    comment.Author = "Kibon";
                    comment.Visible = true;

                    sheet1.CreateRow(5).CreateCell(2).SetCellValue("set value");

                    MemoryStream ms = new MemoryStream();
                    workbook.Write(ms);
                    byte[] data = ms.ToArray();

                    fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
                    fs.Write(data, 0, data.Length);

                    ms.Dispose();
                    ms = null;

                    fs.Close();
                    fs = null;