easyexcel 添加超链接
程序员文章站
2024-01-08 13:57:16
...
easyexcel 添加超链接
***********************
相关类与接口
AbstractCellWriteHandler
public abstract class AbstractCellWriteHandler implements CellWriteHandler {
@Override
public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row,
Head head, Integer columnIndex, Integer relativeRowIndex, Boolean isHead) {
}
@Override
public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell,
Head head, Integer relativeRowIndex, Boolean isHead) {
}
@Override
public void afterCellDataConverted(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder,
CellData cellData, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
}
@Override
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder,
List<CellData> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
}
}
CellWriteHandler
public interface CellWriteHandler extends WriteHandler {
void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Head head,
Integer columnIndex, Integer relativeRowIndex, Boolean isHead);
void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell, Head head,
Integer relativeRowIndex, Boolean isHead);
void afterCellDataConverted(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, CellData cellData,
Cell cell, Head head, Integer relativeRowIndex, Boolean isHead);
void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder,
List<CellData> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead);
}
WriteHandler
public interface WriteHandler extends Handler {
}
Handler
public interface Handler {
}
Cell
public interface Cell {
int getColumnIndex();
int getRowIndex();
Sheet getSheet();
Row getRow();
void setCellType(CellType var1);
void setCellStyle(CellStyle var1);
@Removal(version = "4.2")
CellType getCellTypeEnum();
CellStyle getCellStyle();
void setCellValue(double var1);
void setCellValue(RichTextString var1);
void setCellValue(String var1);
void setCellValue(boolean var1);
void setCellValue(Date var1);
void setCellValue(Calendar var1);
void setCellErrorValue(byte var1);
void setCellFormula(String var1) throws FormulaParseException;
double getNumericCellValue();
RichTextString getRichStringCellValue();
String getStringCellValue();
boolean getBooleanCellValue();
Date getDateCellValue();
byte getErrorCellValue();
String getCellFormula();
void setAsActiveCell();
CellAddress getAddress();
void setCellComment(Comment var1);
Comment getCellComment();
void removeCellComment();
Hyperlink getHyperlink();
void setHyperlink(Hyperlink var1);
void removeHyperlink();
CellRangeAddress getArrayFormulaRange();
boolean isPartOfArrayFormulaGroup();
CellType getCachedFormulaResultTypeEnum();
}
CreationHelper
public interface CreationHelper {
RichTextString createRichTextString(String var1);
DataFormat createDataFormat();
Hyperlink createHyperlink(HyperlinkType var1); //创建超链接
FormulaEvaluator createFormulaEvaluator();
ExtendedColor createExtendedColor();
ClientAnchor createClientAnchor();
AreaReference createAreaReference(String var1);
AreaReference createAreaReference(CellReference var1, CellReference var2);
}
HyperLinkType
public enum HyperlinkType {
@Internal
NONE(-1),
URL(1),
DOCUMENT(2),
EMAIL(3),
FILE(4);
***********************
示例
Test
@Data
class Student{
private Integer id;
private String name;
private Integer age;
}
class CustomCellWriteHandler extends AbstractCellWriteHandler{
@Override
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<CellData> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
if (cell.getRowIndex()==2&&cell.getColumnIndex()==1){
//第2行、第1列添加超链接(从0开始)
CreationHelper helper=writeSheetHolder.getSheet().getWorkbook().getCreationHelper();
Hyperlink hyperlink=helper.createHyperlink(HyperlinkType.URL);
hyperlink.setAddress("http://www.baidu.com");
cell.setHyperlink(hyperlink);
}
}
}
public class Test8 {
private static final String write_path="e:"+ File.separator+"java"+File.separator+"easyexcel"+File.separator+"write3.xlsx";
public static void main(String[] args){
List<Student> list=new ArrayList<>();
for (int i=0;i<5;i++){
Student student=new Student();
student.setId(i);
student.setName("瓜田李下 "+i);
student.setAge(20+i);
list.add(student);
}
EasyExcel.write(write_path,Student.class)
.registerWriteHandler(new CustomCellWriteHandler())
.sheet().doWrite(list);
}
}
*****************
使用测试
点击超链接、跳转到百度首页
推荐阅读
-
easyexcel 添加超链接
-
如何给一个开发好的网页添加黑白滤镜?_html/css_WEB-ITnose
-
【EasyExcel】十分钟入门 EasyExcel
-
利用js动态添加删除table行的示例代码_javascript技巧
-
springboot使用easyexcel导出excel(使用converter转换Integer成String)
-
JAVA解析Excel工具easyexcel之深入源代码解密原理
-
easyexcel之深入体会2
-
easyexcel 列宽、行高、样式
-
使用EasyExcel上传下载excel
-
办公软件下载office2003官方免费下载 PHP简单系统数据添加以及数据删除模块源文件下载