forked from github/easyexcel
Jiaju Zhuang
5 years ago
5 changed files with 63 additions and 3 deletions
@ -0,0 +1,37 @@
|
||||
package com.alibaba.easyexcel.test.demo.write; |
||||
|
||||
import org.apache.poi.ss.usermodel.Comment; |
||||
import org.apache.poi.ss.usermodel.Drawing; |
||||
import org.apache.poi.ss.usermodel.Row; |
||||
import org.apache.poi.ss.usermodel.Sheet; |
||||
import org.apache.poi.xssf.usermodel.XSSFClientAnchor; |
||||
import org.apache.poi.xssf.usermodel.XSSFRichTextString; |
||||
|
||||
import com.alibaba.excel.write.handler.AbstractRowWriteHandler; |
||||
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; |
||||
import com.alibaba.excel.write.metadata.holder.WriteTableHolder; |
||||
|
||||
/** |
||||
* 自定义拦截器.新增注释,第一行头加批注 |
||||
* |
||||
* @author Jiaju Zhuang |
||||
*/ |
||||
public class CommentWriteHandler extends AbstractRowWriteHandler { |
||||
|
||||
@Override |
||||
public void afterRowDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, |
||||
Integer relativeRowIndex, Boolean isHead) { |
||||
if (isHead) { |
||||
Sheet sheet = writeSheetHolder.getSheet(); |
||||
Drawing<?> drawingPatriarch = sheet.createDrawingPatriarch(); |
||||
// 在第一行 第二列创建一个批注
|
||||
Comment comment = |
||||
drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short)1, 0, (short)2, 1)); |
||||
// 输入批注信息
|
||||
comment.setString(new XSSFRichTextString("创建批注!")); |
||||
// 将批注添加到单元格对象中
|
||||
sheet.getRow(0).getCell(1).setCellComment(comment); |
||||
} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue