How to add check symbol in excel cell SXSSFSheet java

0 votes

I need to put a check symbol in this cell if the condition is 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);}
Nov 13, 2022 in Others by Kithuzzz
• 38,000 points
776 views

1 answer to this question.

0 votes

Try this:

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:

enter image description here

answered Nov 13, 2022 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
1 answer

How to stick an embedded document in a specific cell of an excel

Solution Select the documents (you can use the ...READ MORE

answered Oct 18, 2022 in Others by narikkadan
• 63,600 points
709 views
0 votes
1 answer

Add a shape to a specific cell in Excel

When you use SORT() or data->sort on ...READ MORE

answered Oct 24, 2022 in Others by narikkadan
• 63,600 points
1,438 views
0 votes
1 answer

How to add Conditional Formatting in Excel for a Range of Values

Three distinct rules are required, one for ...READ MORE

answered Oct 24, 2022 in Others by narikkadan
• 63,600 points
1,135 views
0 votes
1 answer

Excel VBA : HOW TO PRINT THE TEXT IN A CELL (like Wrap Text)

Use a LineFeed character to create a ...READ MORE

answered Oct 27, 2022 in Others by narikkadan
• 63,600 points
1,032 views
0 votes
1 answer
0 votes
1 answer

What is the better API to Reading Excel sheets in java - JXL or Apache POI

Here are the things where both APIs ...READ MORE

answered Oct 9, 2022 in Others by narikkadan
• 63,600 points
3,401 views
0 votes
1 answer

How to get columns from Excel files using Apache POI?

The only way to see all the ...READ MORE

answered Oct 18, 2022 in Others by narikkadan
• 63,600 points
5,248 views
0 votes
1 answer

Excel-VBA - How to identify Target range (more than 1 cell) is deleted in a Worksheet_Change function?

You misunderstand the purpose of the function ...READ MORE

answered Sep 23, 2022 in Others by narikkadan
• 63,600 points
3,726 views
0 votes
1 answer

How to express absolute cell references in Excel R1C1-style formulas?

If the formulas are in Column K ...READ MORE

answered Oct 15, 2022 in Others by narikkadan
• 63,600 points
1,025 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP