I need to put a check symbol in this cell if the condition met. Here's my sample code:
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);}
I already used
UTF-16 - feff2713
UTF-16BE - 2713
UTF-16LE - 1327
UTF-8 - e29c93
click here for sample output SAMPLE EXPECTED OUTPUT
Area | MOB Target | Area Result | MOB > Area
City | 85% | 80% | ✔
There is no method setCellValue
which takes a char
. Try using a String
there.
The following works for me:
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();
}
}
}
Result: