特別說明
1.開始位置是0
2.\u0052是勾選對號
3.\u25A1是不勾選
4.\u0052長度是1
5.\u25A1長度是1
6.漢字長度是1
7.起止位置不能超過索引位置(比如整體長度是6,截止位置最大填寫5)
?
示例代碼
package com.zycfc.xz.Util.excel;import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFSimpleShape;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Objects;public class ExcelCheckboxExample {public static void main(String[] args) {Workbook workbook = new HSSFWorkbook();Sheet sheet = workbook.createSheet("Checkbox Example");Row row = sheet.createRow(0);Cell cell = row.createCell(0);RichTextString richTextString;// font是通過workbook創建出來的,是不能new的Font font = workbook.createFont();// 設置字體名稱font.setFontName("Wingdings 2");richTextString = new HSSFRichTextString("新的一天否哈哈哈\u0052 \u25A1");richTextString.applyFont(1, 11, font);cell.setCellValue(richTextString);FileOutputStream fileOut;try {fileOut = new FileOutputStream("checkbox_example.xlsx");workbook.write(fileOut);fileOut.close();workbook.close();} catch (IOException e) {e.printStackTrace();}}
}
參考文章:java poi框架導出excel如何插入特殊字符(復選框勾選)_java導出excel復選按鈕-CSDN博客