NPOI SetCellValue在excel上没有任何内容

问题描述 投票:0回答:1

我刚刚开始使用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个回答
0
投票

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

Image Of NPOI Result

© www.soinside.com 2019 - 2024. All rights reserved.