【问题标题】:NPOI SetCellValue plote nothing on the excelNPOI SetCellValue 在 excel 上没有绘制任何内容
【发布时间】:2019-03-21 20:20:15
【问题描述】:

我刚刚开始使用 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"))

【问题讨论】:

    标签: java excel vb.net npoi


    【解决方案1】:

    好吧,问题是插入一个文本,你必须指定正确的单元格索引,即使单元格被合并,而不是当你想要插入图像时,你只增加单元格索引(不合逻辑但它有效) 对于我的情况,索引是 1,但它必须是 2,在写完我的文本后,要插入下一张图像(红色),索引必须是 3 索引: 0 2 3

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-02
      • 1970-01-01
      • 1970-01-01
      • 2015-11-22
      • 1970-01-01
      • 2021-03-14
      相关资源
      最近更新 更多