Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
@NoArgsConstructor
public class ColorDemoData {

@ExcelProperty("姓名")
@ExcelProperty("Name")
private String name;

@ExcelProperty("年龄")
@ExcelProperty("Age")
@HeadFontStyle(color = Font.COLOR_RED)
private Integer age;

@ExcelProperty("性别")
@ExcelProperty("Sex")
private String sex;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.apache.poi.xssf.usermodel.XSSFRichTextString;

/**
* 自定义拦截器.新增注释,第一行头加批注
* Custom handler. Add comment to the header of the first row.
*
*
*/
Expand All @@ -42,12 +42,12 @@ public void afterRowDispose(RowWriteHandlerContext context) {
if (BooleanUtils.isTrue(context.getHead())) {
Sheet sheet = context.getWriteSheetHolder().getSheet();
Drawing<?> drawingPatriarch = sheet.createDrawingPatriarch();
// 在第一行 第二列创建一个批注
// Create a comment in the first row, second column
Comment comment =
drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 1, 0, (short) 2, 1));
// 输入批注信息
comment.setString(new XSSFRichTextString("创建批注!"));
// 将批注添加到单元格对象中
// Input comment information
comment.setString(new XSSFRichTextString("Create comment!"));
// Add comment to cell object
sheet.getRow(0).getCell(1).setCellComment(comment);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@
import org.apache.fesod.sheet.annotation.ExcelProperty;

/**
* 复杂头数据.这里最终效果是第一行就一个主标题,第二行分类
* Complex header data. The final effect is a main title on the first row, and categories on the second row.
*
*
**/
@Getter
@Setter
@EqualsAndHashCode
public class ComplexHeadData {
@ExcelProperty({"主标题", "字符串标题"})
@ExcelProperty({"Main Title", "String Title"})
private String string;

@ExcelProperty({"主标题", "日期标题"})
@ExcelProperty({"Main Title", "Date Title"})
private Date date;

@ExcelProperty({"主标题", "数字标题"})
@ExcelProperty({"Main Title", "Double Title"})
private Double doubleData;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.apache.fesod.sheet.annotation.format.NumberFormat;

/**
* 基础数据类.这里的排序和excel里面的排序一致
* Basic data class. The sorting here is consistent with the sorting in Excel.
*
*
**/
Expand All @@ -37,20 +37,20 @@
@EqualsAndHashCode
public class ConverterData {
/**
* 我想所有的 字符串起前面加上"自定义:"三个字
* I want to add "Custom:" to the beginning of all strings.
*/
@ExcelProperty(value = "字符串标题", converter = CustomStringStringConverter.class)
@ExcelProperty(value = "String Title", converter = CustomStringStringConverter.class)
private String string;
/**
* 我想写到excel 用年月日的格式
* I want to write to Excel using the format "yyyy-MM-dd HH:mm:ss"
*/
@DateTimeFormat("yyyy年MM月dd日HH时mm分ss秒")
@ExcelProperty("日期标题")
@DateTimeFormat("yyyy-MM-dd HH:mm:ss")
@ExcelProperty("Date Title")
private Date date;
/**
* 我想写到excel 用百分比表示
* I want to write to Excel using percentage format.
*/
@NumberFormat("#.##%")
@ExcelProperty(value = "数字标题")
@ExcelProperty(value = "Double Title")
private Double doubleData;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.apache.poi.ss.usermodel.Hyperlink;

/**
* 自定义拦截器
* Custom handler
*
*
*/
Expand All @@ -39,8 +39,8 @@ public class CustomCellWriteHandler implements CellWriteHandler {
@Override
public void afterCellDispose(CellWriteHandlerContext context) {
Cell cell = context.getCell();
// 这里可以对cell进行任何操作
log.info("第{}行,第{}列写入完成。", cell.getRowIndex(), cell.getColumnIndex());
// Can perform any operation on the cell here
log.info("Finished writing row {}, column {}", cell.getRowIndex(), cell.getColumnIndex());
if (BooleanUtils.isTrue(context.getHead()) && cell.getColumnIndex() == 0) {
CreationHelper createHelper =
context.getWriteSheetHolder().getSheet().getWorkbook().getCreationHelper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.apache.poi.ss.util.CellRangeAddressList;

/**
* 自定义拦截器.对第一列第一行和第二行的数据新增下拉框,显示 测试1 测试2
* Custom handler. Add dropdown to first column of first and second data rows, displaying "Test1", "Test2"
*
*
*/
Expand All @@ -37,12 +37,13 @@ public class CustomSheetWriteHandler implements SheetWriteHandler {

@Override
public void afterSheetCreate(SheetWriteHandlerContext context) {
log.info("第{}个Sheet写入成功。", context.getWriteSheetHolder().getSheetNo());
log.info("Sheet {} write success.", context.getWriteSheetHolder().getSheetNo());

// 区间设置 第一列第一行和第二行的数据。由于第一行是头,所以第一、二行的数据实际上是第二三行
// Set range for first column, first and second data rows. Since the first row is head, the data is actually in
// the 2nd and 3rd rows.
CellRangeAddressList cellRangeAddressList = new CellRangeAddressList(1, 2, 0, 0);
DataValidationHelper helper = context.getWriteSheetHolder().getSheet().getDataValidationHelper();
DataValidationConstraint constraint = helper.createExplicitListConstraint(new String[] {"测试1", "测试2"});
DataValidationConstraint constraint = helper.createExplicitListConstraint(new String[] {"Test1", "Test2"});
DataValidation dataValidation = helper.createValidation(constraint, cellRangeAddressList);
context.getWriteSheetHolder().getSheet().addValidationData(dataValidation);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@
import org.apache.fesod.sheet.annotation.write.style.ContentLoopMerge;

/**
* 样式的数据类
* Style data class
*
*
**/
@Getter
@Setter
@EqualsAndHashCode
// 将第6-7行的2-3列合并成一个单元格
// Merge columns 2-3 of rows 6-7 into one cell
// @OnceAbsoluteMerge(firstRowIndex = 5, lastRowIndex = 6, firstColumnIndex = 1, lastColumnIndex = 2)
public class DemoMergeData {
// 这一列 每隔2行 合并单元格
// Merge this column every 2 rows
@ContentLoopMerge(eachRow = 2)
@ExcelProperty("字符串标题")
@ExcelProperty("String Title")
private String string;

@ExcelProperty("日期标题")
@ExcelProperty("Date Title")
private Date date;

@ExcelProperty("数字标题")
@ExcelProperty("Double Title")
private Double doubleData;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,36 @@
import org.apache.fesod.sheet.enums.poi.FillPatternTypeEnum;

/**
* 样式的数据类
* Style data class
*
*
**/
@Getter
@Setter
@EqualsAndHashCode
// 头背景设置成红色 IndexedColors.RED.getIndex()
// Head background red
@HeadStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 10)
// 头字体设置成20
// Head font size 20
@HeadFontStyle(fontHeightInPoints = 20)
// 内容的背景设置成绿色 IndexedColors.GREEN.getIndex()
// Content background green
@ContentStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 17)
// 内容字体设置成20
// Content font size 20
@ContentFontStyle(fontHeightInPoints = 20)
public class DemoStyleData {
// 字符串的头背景设置成粉红 IndexedColors.PINK.getIndex()
// String head background pink
@HeadStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 14)
// 字符串的头字体设置成20
// String head font size 30
@HeadFontStyle(fontHeightInPoints = 30)
// 字符串的内容的背景设置成天蓝 IndexedColors.SKY_BLUE.getIndex()
// String content background sky blue
@ContentStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 40)
// 字符串的内容字体设置成20
// String content font size 30
@ContentFontStyle(fontHeightInPoints = 30)
@ExcelProperty("字符串标题")
@ExcelProperty("String Title")
private String string;

@ExcelProperty("日期标题")
@ExcelProperty("Date Title")
private Date date;

@ExcelProperty("数字标题")
@ExcelProperty("Double Title")
private Double doubleData;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.apache.fesod.sheet.metadata.data.WriteCellData;

/**
* 图片导出类
* Image export class
*/
@Getter
@Setter
Expand All @@ -43,19 +43,23 @@ public class ImageDemoData {
private File file;
private InputStream inputStream;
/**
* 如果string类型 必须指定转换器,string默认转换成string
* If it is a String type, a converter must be specified; String is converted to String by default.
*/
@ExcelProperty(converter = StringImageConverter.class)
private String string;

private byte[] byteArray;
/**
* 根据url导出
* Export by URL
*
* @since 2.1.1
*/
private URL url;

/**
* 根据文件导出 并设置导出的位置。
* Export by file and set the export location.
*
* @since 3.0.0-beta1
*/
private WriteCellData<Void> writeCellDataFile;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@
import org.apache.fesod.sheet.annotation.ExcelProperty;

/**
* 基础数据类
* Basic data class
*
*
**/
@Getter
@Setter
@EqualsAndHashCode
public class IndexData {
@ExcelProperty(value = "字符串标题", index = 0)
@ExcelProperty(value = "String Title", index = 0)
private String string;

@ExcelProperty(value = "日期标题", index = 1)
@ExcelProperty(value = "Date Title", index = 1)
private Date date;
/**
* 这里设置3 会导致第二列空的
* Setting index to 3 will result in the second column being empty.
*/
@ExcelProperty(value = "数字标题", index = 3)
@ExcelProperty(value = "Double Title", index = 3)
private Double doubleData;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@
import org.apache.fesod.sheet.annotation.ExcelProperty;

/**
* 基础数据类
* Basic data class
*
*
**/
@Getter
@Setter
@EqualsAndHashCode
public class LongestMatchColumnWidthData {
@ExcelProperty("字符串标题")
@ExcelProperty("String Title")
private String string;

@ExcelProperty("日期标题很长日期标题很长日期标题很长很长")
@ExcelProperty("Date Title is very long Date Title is very long")
private Date date;

@ExcelProperty("数字")
@ExcelProperty("Double")
private Double doubleData;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.apache.fesod.sheet.annotation.write.style.HeadRowHeight;

/**
* 基础数据类
* Basic data class
*
*
**/
Expand All @@ -40,15 +40,15 @@
@HeadRowHeight(20)
@ColumnWidth(25)
public class WidthAndHeightData {
@ExcelProperty("字符串标题")
@ExcelProperty("String Title")
private String string;

@ExcelProperty("日期标题")
@ExcelProperty("Date Title")
private Date date;
/**
* 宽度为50
* Width is 50
*/
@ColumnWidth(50)
@ExcelProperty("数字标题")
@ExcelProperty("Double Title")
private Double doubleData;
}
Loading