|
@@ -30,8 +30,6 @@ public class ExcelWriter extends ExcelExport {
|
|
|
|
|
|
private XSSFCellStyle style;
|
|
|
|
|
|
- private XSSFCellStyle style2;
|
|
|
-
|
|
|
public ExcelWriter() {
|
|
|
workbook = new XSSFWorkbook();
|
|
|
}
|
|
@@ -58,7 +56,7 @@ public class ExcelWriter extends ExcelExport {
|
|
|
|
|
|
private List<ColumnSetting> createColumnSettings() {
|
|
|
List<ColumnSetting> columnSettings = this.getColumnSettings();
|
|
|
- // 产生表格标题行
|
|
|
+ /* 产生表格标题行 */
|
|
|
row = sheet.createRow(0);
|
|
|
style = workbook.createCellStyle();
|
|
|
ExcelHeaderStyle excelHeaderStyle = this.getDataClass().getAnnotation(ExcelHeaderStyle.class);
|
|
@@ -135,15 +133,20 @@ public class ExcelWriter extends ExcelExport {
|
|
|
List<ColumnSetting> columnSettings = this.createColumnSettings();
|
|
|
int index = 0;
|
|
|
if (Objects.nonNull(dataset) && dataset.size() > 0) {
|
|
|
+ CellStyle style = workbook.createCellStyle();
|
|
|
+ Font font = workbook.createFont();
|
|
|
+ font.setFontHeightInPoints((short) 10);
|
|
|
+ font.setFontName("宋体");
|
|
|
+ font.setColor(IndexedColors.BLACK1.getIndex());
|
|
|
+ style.setFont(font);
|
|
|
for (Object obj : dataset) {
|
|
|
index++;
|
|
|
row = sheet.createRow(index);// 创建行
|
|
|
// 利用反射,根据javabean属性的先后顺序,动态调用getXxx()方法得到属性值
|
|
|
for (short i = 0; i < columnSettings.size(); i++) {
|
|
|
cell = row.createCell(i);// 创建列
|
|
|
- Field field = columnSettings.get(i).getField();
|
|
|
-
|
|
|
- cell.setCellStyle(this.getCellStyle(workbook.createCellStyle(), field));
|
|
|
+// Field field = columnSettings.get(i).getField();
|
|
|
+ cell.setCellStyle(style);
|
|
|
String methodName = columnSettings.get(i).getGetMethodName();
|
|
|
Method method = this.getDataClass().getMethod(methodName, new Class[]{});
|
|
|
Object value = method.invoke(obj, new Object[]{});
|
|
@@ -169,13 +172,19 @@ public class ExcelWriter extends ExcelExport {
|
|
|
List<ColumnSetting> columnSettings = this.createColumnSettings(sheet);
|
|
|
int index = 0;
|
|
|
if (Objects.nonNull(dataset) && dataset.size() > 0) {
|
|
|
+ CellStyle style = workbook.createCellStyle();
|
|
|
+ Font font = workbook.createFont();
|
|
|
+ font.setFontHeightInPoints((short) 10);
|
|
|
+ font.setFontName("宋体");
|
|
|
+ font.setColor(IndexedColors.BLACK1.getIndex());
|
|
|
+ style.setFont(font);
|
|
|
for (Object obj : dataset) {
|
|
|
index++;
|
|
|
row = sheet.createRow(index);// 创建行
|
|
|
// 利用反射,根据javabean属性的先后顺序,动态调用getXxx()方法得到属性值
|
|
|
for (short i = 0; i < columnSettings.size(); i++) {
|
|
|
cell = row.createCell(i);// 创建列
|
|
|
- cell.setCellStyle(style2);
|
|
|
+ cell.setCellStyle(style);
|
|
|
String methodName = columnSettings.get(i).getGetMethodName();
|
|
|
Method method = this.getDataClass().getMethod(methodName, new Class[]{});
|
|
|
Object value = method.invoke(obj, new Object[]{});
|