excel插入复选框 亲测有效

发布于:2025-08-06 ⋅ 阅读:(20) ⋅ 点赞:(0)

特别说明

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博客


网站公告

今日签到

点亮在社区的每一天
去签到