gpt4 book ai didi

java - 如何在Excel单元格SXSSFSheet java中添加复选符号

转载 作者:行者123 更新时间:2023-12-02 01:04:06 24 4
gpt4 key购买 nike

如果满足条件,我需要在此单元格中放置一个复选符号。这是我的示例代码:

private SXSSFWorkbook RepWkBook = null;
private SXSSFSheet RepSheet = null;
private int RepRowNum = 0;
private ResultSet RepResult = null;
private Row RepRow = null;

RepSheet = RepWkBook.createSheet(reportType);
RepRowNum = 0;
Row row = RepSheet.createRow(RepRowNum++);
CellStyle cellStyle = RepWkBook.createCellStyle();
Font font = RepWkBook.createFont();
font.setBold(true);
cellStyle.setFont(font);cell = RepRow.createCell(col++);

boolean isMOBhigherThanArea = RepResult.getString("IS_MOB_HIGHER_THAN_AREA").equalsIgnoreCase("1");

char st = '\u2713';

if(isMOBhigherThanArea && (!areaStr.equalsIgnoreCase("No Data") || !mobStr.equalsIgnoreCase("No Data"))) {
cell.setCellValue(st);}

我已经用过

UTF-16 - feff2713

UTF-16BE - 2713

UTF-16LE - 1327

UTF-8 - e29c93

click here for sample output预期输出示例

区域 | MOB目标|面积结果 | MOB > 区域

城市 | 85% | 80% | ✔

最佳答案

没有采用 char 的方法 setCellValue。尝试在那里使用String

以下内容对我有用:

import java.io.FileOutputStream;
import org.apache.poi.xssf.streaming.*;

class CreateSXSSFUnicode {

public static void main(String[] args) throws Exception {

char st = '\u2713';
String[] headers = new String[] {"Area", "MOB Target", "Area Result", "MOB > Area"};

try (SXSSFWorkbook workbook = new SXSSFWorkbook();
FileOutputStream fileout = new FileOutputStream("Excel.xlsx") ) {

SXSSFSheet sheet = workbook.createSheet();
SXSSFRow row;

int rowNum = 0;
row = sheet.createRow(rowNum++);
for (int c = 0; c < headers.length; c++) {
row.createCell(c).setCellValue(headers[c]);
}
row = sheet.createRow(rowNum++);
int c = 0;
row.createCell(c++).setCellValue("City");
row.createCell(c++).setCellValue("85%");
row.createCell(c++).setCellValue("80%");
//row.createCell(c++).setCellValue(st); // does not work as st is a char
row.createCell(c++).setCellValue(String.valueOf(st)); // this works

workbook.write(fileout);
workbook.dispose();
}
}
}

结果:

enter image description here

关于java - 如何在Excel单元格SXSSFSheet java中添加复选符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60269329/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com