Commit 401aa224 authored by yanzg's avatar yanzg

接口文档的支持

parent 611d8c94
...@@ -67,6 +67,11 @@ public class ExcelConsole<T extends Object> implements DbRow<T> { ...@@ -67,6 +67,11 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
*/ */
private Map<String, ExcelMergerData> mergerGroupData; private Map<String, ExcelMergerData> mergerGroupData;
/**
* 最大字节长度
*/
private Map<Integer, Integer> columnBytes;
/** /**
* 控制台输出Excel * 控制台输出Excel
* *
...@@ -160,6 +165,7 @@ public class ExcelConsole<T extends Object> implements DbRow<T> { ...@@ -160,6 +165,7 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
// 创建合并对象数据检测 // 创建合并对象数据检测
mergerGroup = new HashMap<>(); mergerGroup = new HashMap<>();
mergerGroupData = new HashMap<>(); mergerGroupData = new HashMap<>();
columnBytes = new HashMap<>();
// 创建工作簿对象 // 创建工作簿对象
workbook = new XSSFWorkbook(); workbook = new XSSFWorkbook();
...@@ -293,7 +299,11 @@ public class ExcelConsole<T extends Object> implements DbRow<T> { ...@@ -293,7 +299,11 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
for (int columnPos = 0; columnPos < this.config.getColumns().size(); columnPos++) { for (int columnPos = 0; columnPos < this.config.getColumns().size(); columnPos++) {
ExportColumn column = this.config.getColumns().get(columnPos); ExportColumn column = this.config.getColumns().get(columnPos);
String columnName = column.getName(); String columnName = column.getName();
String value = rowHandle.get(t, columnName); String value = StringHelper.getFirst(rowHandle.get(t, columnName));
// 获取字节数、用于设置最大宽度
int maxBytes = Math.max(columnBytes.getOrDefault(columnPos, 0), value.getBytes().length);
columnBytes.put(columnPos, maxBytes);
// 当不需要合并历史记录时,则创建新的内容 // 当不需要合并历史记录时,则创建新的内容
Cell cell = createCell(row, columnPos, value); Cell cell = createCell(row, columnPos, value);
...@@ -334,7 +344,6 @@ public class ExcelConsole<T extends Object> implements DbRow<T> { ...@@ -334,7 +344,6 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
if (workbook == null) { if (workbook == null) {
return this; return this;
} }
// 合并数据配置 // 合并数据配置
for (int columnPos = 0; columnPos < this.config.getColumns().size(); columnPos++) { for (int columnPos = 0; columnPos < this.config.getColumns().size(); columnPos++) {
ExportColumn column = this.config.getColumns().get(columnPos); ExportColumn column = this.config.getColumns().get(columnPos);
...@@ -348,7 +357,9 @@ public class ExcelConsole<T extends Object> implements DbRow<T> { ...@@ -348,7 +357,9 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
} }
} }
if (column.getWidth() < 1) { if (column.getWidth() < 1) {
sheet.autoSizeColumn(columnPos); //设置单元格长度, 这里要乘上256
int maxBytes = columnBytes.get(columnPos);
sheet.setColumnWidth(columnPos, maxBytes * 256);
} else { } else {
sheet.setColumnWidth(columnPos, getUnit(column.getWidth())); sheet.setColumnWidth(columnPos, getUnit(column.getWidth()));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment