POI 给单元格添加批注

图中红框框是处理单元格内容和批注的地方。
参考:https://blog.csdn.net/qq_38974638/article/details/114837631
//SXSSFWorkbook
public static void createExcelMergeSetCellColor1(SXSSFWorkbook workbook, SXSSFSheet sheet, String title,
final String[] headers, List<List<String>> dataset, boolean isSortDataSet, final Integer[] mergeBasis,
final Integer[] mergeCells, final Integer[] sumCells, final Integer[] timeCells)
{
sheet.setDefaultColumnWidth(15); // 设置表格默认列宽度为15个字节
sheet.setDefaultRowHeight((short)20);
sheet.setDefaultRowHeightInPoints(20);
CellStyle headStyle = createHeadStyle(workbook); // 生成头部样式
CellStyle commonDataStyle = createCommonDataStyle(workbook); // 生成一般数据样式
commonDataStyle.setWrapText(true);
CellStyle commonDataStyleRed = createCommonDataStyleRed(workbook);//生成红色文本样式
commonDataStyleRed.setWrapText(true);
CellStyle numStyle = createNumStyle(workbook); //生成数字类型保留两位小数样式
CellStyle sumRowStyle = createSumRowStyle(workbook); //生成合计行样式 if (headers == null || headers.length <= 0)
{
return;
} SXSSFDrawing drawing = sheet.createDrawingPatriarch();
SXSSFRow row = sheet.createRow(0); // 产生表格标题行
row.setHeightInPoints(30); //标题行的行高为25 for (int index = 0; index < headers.length; index++)
{
SXSSFCell cell = row.createCell(index);
cell.setCellStyle(headStyle);
XSSFRichTextString text = new XSSFRichTextString(headers[index]);
cell.setCellValue(text);
String str = text.toString();
if(str.contains("雇员唯一号") || str.contains("雇员姓名") || str.contains("证件号")
|| str.contains("缴金地") || str.contains("社保额"))
{
Comment comment = drawing.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, cell.getColumnIndex(), cell.getRowIndex(),
cell.getColumnIndex() + 5, cell.getRowIndex() + 6));
comment.setString(new XSSFRichTextString("必填项"));
cell.setCellComment(comment);
}
else if(str.contains("证件类型"))
{
Comment comment = drawing.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, cell.getColumnIndex(), cell.getRowIndex(),
cell.getColumnIndex() + 5, cell.getRowIndex() + 6));
comment.setString(new XSSFRichTextString("必填项,证件类型只支持 身份证"));
cell.setCellComment(comment);
}
else if(str.contains("账单年月"))
{
Comment comment = drawing.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, cell.getColumnIndex(), cell.getRowIndex(),
cell.getColumnIndex() + 5, cell.getRowIndex() + 6));
comment.setString(new XSSFRichTextString("必填项,日期格式:\n" + "202109\n"));
cell.setCellComment(comment);
}
} // 遍历集合数据,产生数据行
Iterator<List<String>> it = dataset.iterator();
int index = 0;
while (it.hasNext())
{
index++;
row = sheet.createRow(index);
row.setHeightInPoints(20); //一般数据的行高为20
List<String> dataSources = it.next();
for (int i = 0; i < dataSources.size(); i++)
{
SXSSFCell cell = row.createCell(i);
cell.setCellStyle(commonDataStyle);
cell.setCellValue(dataSources.get(i));
}
} }
POI 给单元格添加批注的更多相关文章
- java poi给sheet表格中的某个单元格添加批注
Label l = , , "A cell with a comment"); WritableCellFeatures cellFeatures = new WritableCe ...
- POI单元格添加公式以及读取公式结果的值
POI提供了为单元格添加条件样式的方法,但是我并没有找到获取单元格改变后样式的方法,获取到样式依旧是没有改变之前的. 比如为单元格添加条件样式用于监听单元格值是否被修改,如果单元格值被修改那么字体颜色 ...
- java excel给单元格增加批注(包含SXSSF)
package javatest; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi ...
- 在Excel里用vba给合并的单元格添加注释
Excel里使用VBA对已经合并的单元格添加注释,直接使用AddComment会报: 运行时错误 '1004':应用程序定义或者对象定义错误 找了很多文章都没找到怎么解决,最后发现在AddCommen ...
- java poi 合并单元格后边框问题
在项目中用poi合并单元格,但发现边框会有不显示的问题. 在网上搜集了答案,来记录一下. 解决方法: 将每个没用到的单元格都设空值. 例如: HSSFCell cell = row.createCel ...
- poi合并单元格同时导出excel
poi合并单元格同时导出excel POI进行跨行需要用到对象HSSFSheet对象,现在就当我们程序已经定义了一个HSSFSheet对象sheet. 跨第1行第1个到第2个单元格的操作为 sheet ...
- poi 升级至4.x 的问题总结(POI Excel 单元格内容类型判断并取值)
POI Excel 单元格内容类型判断并取值 以前用 cell.getCachedFormulaResultType() 得到 type 升级到4后获取不到了 换为:cell.getCellType( ...
- java poi 合并单元格
java poi 合并单元格 2017年03月29日 16:39:01 翠烟你懊恼 阅读数:26561 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.n ...
- 关于POI 中单元格背景色设置(转)
关于POI 中单元格背景色设置(转) csdn 中找到了用Apache POI 实现单元格背景色的小例子 我用了JDK6 + POI 3.17 ,调试中报错 最终将 CellStyle.SOLID ...
随机推荐
- Java语言学习day27--8月02日
今日内容介绍1.Eclipse常用快捷键操作2.Eclipse文档注释导出帮助文档3.Eclipse项目的jar包导出与使用jar包4.不同修饰符混合使用细节5.辨析何时定义变量为成员变量6.类.抽象 ...
- node.js - 路由、中间件、mysql
这几天天天搞到这么晚,我看今天的内容看起不多啊,不知道为什么学着学着就到了这么晚.今天的内容还是有点多哈,有点自我矛盾了,再次一一道来. 1. 首先今天先看到路由的概念,什么叫做路由? 路由就是映射关 ...
- javascript中的Ajax基础(一)
一.手写一个ajax 1 const xhr = new xmlHttpRequest() 2 3 xhr.open(请求方式:post get, 请求地址, 同步或者异步) 4 5 xhr.onre ...
- for & while &迭代器
for (int i = 0; i < 10; i++) { System.out.println("hello"); } int a=100; for (;a<110 ...
- [AcWing 87] 把字符串转换成整数
点击查看代码 class Solution { public: int strToInt(string str) { int k = 0; while (k < str.size() & ...
- Pytorch Linear ()简单推导
pytorch,nn.Linear 下图中的A是权重矩阵,b是偏置. in_features输入样本的张量大小 out_features输出样本的张量大小 bias是偏置 # 测试代码 # batch ...
- 离谱的 CSS!从表盘刻度到艺术剪纸
某日,群里有这样一个问题,如何实现这样的表盘刻度: 这其实是个挺有意思的问题,方法也有很多. 单标签,使用 conic-gradient 实现表盘刻度 最简单便捷的方式,就是利用角向渐变的方式 con ...
- 详解计算miou的代码以及混淆矩阵的意义
详解计算miou的代码以及混淆矩阵的意义 miou的定义 ''' Mean Intersection over Union(MIoU,均交并比):为语义分割的标准度量.其计算两个集合的交集和并集之比. ...
- this-2
读起来使你有新认识或可以使你离更确切的定义更近时的文章不应该被忽略.thisthis既不指向函数自身,也不指向函数的词法作用域(ES6中箭头函数采用词法作用域).this实际上是函数被调用时才发生绑定 ...
- xrdp出现xrdp vnc error problem connecting解决办法
# generate a file called .xsession in your home directory, and set default desktop echo "xfce4- ...