Commit 401aa224 authored by yanzg's avatar yanzg

接口文档的支持

parent 611d8c94
......@@ -67,6 +67,11 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
*/
private Map<String, ExcelMergerData> mergerGroupData;
/**
* 最大字节长度
*/
private Map<Integer, Integer> columnBytes;
/**
* 控制台输出Excel
*
......@@ -160,6 +165,7 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
// 创建合并对象数据检测
mergerGroup = new HashMap<>();
mergerGroupData = new HashMap<>();
columnBytes = new HashMap<>();
// 创建工作簿对象
workbook = new XSSFWorkbook();
......@@ -293,7 +299,11 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
for (int columnPos = 0; columnPos < this.config.getColumns().size(); columnPos++) {
ExportColumn column = this.config.getColumns().get(columnPos);
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);
......@@ -334,7 +344,6 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
if (workbook == null) {
return this;
}
// 合并数据配置
for (int columnPos = 0; columnPos < this.config.getColumns().size(); columnPos++) {
ExportColumn column = this.config.getColumns().get(columnPos);
......@@ -348,7 +357,9 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
}
}
if (column.getWidth() < 1) {
sheet.autoSizeColumn(columnPos);
//设置单元格长度, 这里要乘上256
int maxBytes = columnBytes.get(columnPos);
sheet.setColumnWidth(columnPos, maxBytes * 256);
} else {
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