Support
Quality
Security
License
Reuse
kandi has reviewed easyexcel and discovered the below as its top functions. This is intended to give you an instant insight into easyexcel implemented functionality, and help decide if they suit your requirements.
快速、简洁、解决大文件内存溢出的java处理Excel工具
default
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.0.1</version>
</dependency>
why the easy excel set cell style did not work
api group: 'com.alibaba', name: 'easyexcel', version: '2.2.11'
QUESTION
why the easy excel set cell style did not work
Asked 2022-Feb-14 at 12:07I am using easy excel api group: 'com.alibaba', name: 'easyexcel', version: '3.0.3'
to set the cell color, this is the main.java
code:
public class AppStarter {
public static void main(String[] args) {
SparkUserExcelRequest request = new SparkUserExcelRequest();
request.setNickname("test");
String writePathName = "/Users/dolphin/source/dabai/microservice/soa-zhuolian-org/";
String fullPathName = writePathName + "a.xlsx";
if (!new File(writePathName).exists()) {
new File(writePathName).mkdirs();
}
ExcelWriterBuilder writerBuilder = EasyExcel.write(fullPathName, SparkUserExcelRequest.class);
writerBuilder.excelType(ExcelTypeEnum.XLSX);
writerBuilder.registerWriteHandler(new CellStyleWriteHandler());
ExcelWriter writer = writerBuilder.build();
WriteSheet writeSheet = new WriteSheet();
writeSheet.setSheetName("mark");
writer.write(Arrays.asList(request), writeSheet);
writer.finish();
}
}
this is the class which change the cell color:
public class CellStyleWriteHandler extends AbstractCellStyleStrategy {
@Override
protected void setContentCellStyle(Cell cell, Head head, Integer relativeRowIndex) {
Workbook workbook = cell.getSheet().getWorkbook();
CellStyle cellStyle = workbook.createCellStyle();
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cellStyle.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex());
cell.setCellStyle(cellStyle);
}
}
and this is the entity class:
@Data
@ExcelIgnoreUnannotated
public class SparkUserExcelRequest implements Serializable {
@ExcelProperty("user name")
private String nickname;
}
when I run this code, this cell color did not changed to light blue, why the cell color set failed? what should I do to fix this problem? I want the test cell color changed to blue.
ANSWER
Answered 2022-Feb-14 at 12:07I tried your code, and the color did not change. Tried to downgrade your easyexcel version to 2.2.11 should fix this problem.You could add an issue to make sure is it a bug.
api group: 'com.alibaba', name: 'easyexcel', version: '2.2.11'
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Explore Related Topics
Save this library and start creating your kit