NPOI SetCellValue在Excel上没有任何内容

时间:2019-03-21 10:41:45

标签: java excel vb.net npoi

我刚刚开始使用NPOI生成xls文件,但是当我尝试SetCellValue时,我在excel上什么也没写。 我的代码是:

            CellsCombined = New CellRangeAddress(0, 4, 2, 4)
            hoja.AddMergedRegion(CellsCombined)
            HSSFRegionUtil.SetBorderBottom(BorderStyle.Thin, CellsCombined, hoja, wb)
            HSSFRegionUtil.SetBorderLeft(BorderStyle.Thin, CellsCombined, hoja, wb)
            HSSFRegionUtil.SetBorderTop(BorderStyle.Thin, CellsCombined, hoja, wb)
            HSSFRegionUtil.SetBorderRight(BorderStyle.Thin, CellsCombined, hoja, wb)

            Dim boldFontTitulo As IFont = wb.CreateFont()
            boldFontTitulo.Boldweight = FontBoldWeight.Bold
            Dim boldTitulo As ICellStyle = wb.CreateCellStyle()
            boldTitulo.SetFont(boldFontTitulo)
            boldTitulo.Alignment = HorizontalAlignment.Left

            newCell = newRow.CreateCell(idxCell)
            newCell.SetCellType(CellType.String)

            newCell.CellStyle = boldTitulo
            newCell.SetCellValue(New HSSFRichTextString("My Text Here"))

首次编辑

idxCell = 1,因为在此单元格之前,我已经在第一个单元格中成功插入了图像

第二次修改 我只尝试了此操作而没有合并,但是什么也没合并

newRow.CreateCell(idxCell, CellType.String).SetCellValue(New HSSFRichTextString("My text"))

1 个答案:

答案 0 :(得分:0)

好吧,问题是要插入文本,即使合并了单元格,也必须指定正确的单元格索引,这与您要插入图像时不同,只是增加了单元格索引(illogic,但它确实有效) 在我的情况下,索引为1,但必须为2,在写完文字之后,要插入下一张图片(红色),索引必须为3 指标: 0 2 3

Image Of NPOI Result