相关类与接口
Sheet(部分方法)
public interface Sheet extends Iterable {
Drawing> createDrawingPatriarch();
Drawing> getDrawingPatriarch();
}
Cell(部分方法)
public interface Cell {
void setCellComment(Comment var1);
Comment getCellComment();
void removeCellComment();
}
Comment
public interface Comment {
int getRow();
void setRow(int var1);
int getColumn();
void setColumn(int var1);
void setVisible(boolean var1);
boolean isVisible();
CellAddress getAddress();
void setAddress(CellAddress var1);
void setAddress(int var1, int var2);
String getAuthor();
void setAuthor(String var1);
RichTextString getString();
void setString(RichTextString var1);
ClientAnchor getClientAnchor();
}
RichTextString
public interface RichTextString {
void applyFont(int var1, int var2, short var3);
void applyFont(int var1, int var2, Font var3);
void applyFont(Font var1);
void applyFont(short var1);
void clearFormatting();
String getString();
int length();
int numFormattingRuns();
int getIndexOfFormattingRun(int var1);
}
XSSFRichTextString
public class XSSFRichTextString implements RichTextString {
private static final Pattern utfPtrn = Pattern.compile("_x([0-9A-Fa-f]{4})_");
private CTRst st;
private StylesTable styles;
**********
构造方法
public XSSFRichTextString(String str) {
public XSSFRichTextString() {
public XSSFRichTextString(CTRst st) {
**********
普通方法
public void applyFont(int startIndex, int endIndex, short fontIndex) {
public void applyFont(int startIndex, int endIndex, Font font) {
public void applyFont(Font font) {
public void applyFont(short fontIndex) {
public void append(String text, XSSFFont font) {
public void append(String text) {
public String getString() {
public void setString(String s) {
public int length() {
public int numFormattingRuns() {
public int getLengthOfFormattingRun(int index) {
public int getIndexOfFormattingRun(int index) {
public boolean hasFormatting() {
public void clearFormatting() {
public XSSFFont getFontOfFormattingRun(int index) {
public XSSFFont getFontAtIndex(int index) {
@Internal
public CTRst getCTRst() {
protected void setStylesTableReference(StylesTable tbl) {
protected static CTFont toCTFont(CTRPrElt pr) {
protected static void preserveSpaces(STXstring xs) {
static String utfDecode(String value) {
void applyFont(TreeMap formats, int startIndex, int endIndex, CTRPrElt fmt) {
public String toString() {
TreeMap getFormatMap(CTRst entry) {
CTRst buildCTRst(String text, TreeMap formats) {
private ThemesTable getThemesTable() {
private void setRunAttributes(CTFont ctFont, CTRPrElt pr) {
XSSFClientAnchor
public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
private static final CTMarker EMPTY_MARKER = Factory.newInstance();
private AnchorType anchorType;
private CTMarker cell1;
private CTMarker cell2;
private CTPositiveSize2D size;
private CTPoint2D position;
private XSSFSheet sheet;
public XSSFClientAnchor() {
public XSSFClientAnchor(int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2) {
protected XSSFClientAnchor(CTMarker cell1, CTMarker cell2) {
protected XSSFClientAnchor(XSSFSheet sheet, CTMarker cell1, CTPositiveSize2D size) {
protected XSSFClientAnchor(XSSFSheet sheet, CTPoint2D position, CTPositiveSize2D size) {
示例
Test
@Data
class Book{
private Integer id;
private String name;
private Double price;
}
class CustomCellWriteHandler extends AbstractCellWriteHandler{
@Override
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
if (isHead){
Drawing> drawing=writeSheetHolder.getSheet().createDrawingPatriarch();
switch (cell.getColumnIndex()){
case 1: {
Comment comment=drawing.createCellComment(new XSSFClientAnchor(0,0,0,0,1,0,2,0));
comment.setString(new XSSFRichTextString("书名"));
cell.setCellComment(comment);
} break;
case 2: {
Comment comment=drawing.createCellComment(new XSSFClientAnchor(0,0,0,0,2,0,3,0));
comment.setString(new XSSFRichTextString("价格"));
cell.setCellComment(comment);
} break;
}
}
}
}
public class Test {
private static final String write_path="e:"+ File.separator+"java"+File.separator+"easyexcel"+File.separator+"write5.xlsx";
public static void write(){
EasyExcel.write(write_path,Book.class).registerWriteHandler(new CustomCellWriteHandler())
.sheet().doWrite(data());
}
private static List data(){
List list=new ArrayList<>();
for (int i=0;i<5;i++){
Book book=new Book();
book.setId(i);
book.setName("海贼王"+i);
book.setPrice((double)(5+i));
list.add(book);
}
return list;
}
public static void main(String[] args){
write();
}
}
************
使用测试