feat(table): 设置默认表格样式并更新配置颜色

- 在 FsApiUtil 中调用 FsTableUtil 设置默认表格样式
- 新增 getDefaultTableStyle 方法用于构建默认样式
- 修改 MapSheetConfig 中表头背景色和字体颜色默认值
- 引入 TableConf 和 MapSheetConfig 类以支持样式配置
This commit is contained in:
liushuang 2025-11-05 14:24:57 +08:00
parent 9ab953992a
commit 34c68b7619
3 changed files with 24 additions and 3 deletions

@ -21,12 +21,12 @@ public class MapSheetConfig extends MapTableConfig {
/**
* 表头字体颜色十六进制 #ffffff
*/
private String headFontColor = "#ffffff";
private String headFontColor = "#000000";
/**
* 表头背景颜色十六进制 #000000
*/
private String headBackColor = "#000000";
private String headBackColor = "#cccccc";
/**
* 是否将单元格设置为纯文本格式

@ -5,7 +5,9 @@ import cn.isliu.core.Reply;
import cn.isliu.core.Sheet;
import cn.isliu.core.SheetMeta;
import cn.isliu.core.ValuesBatch;
import cn.isliu.core.annotation.TableConf;
import cn.isliu.core.client.FeishuClient;
import cn.isliu.core.config.MapSheetConfig;
import cn.isliu.core.exception.FsHelperException;
import cn.isliu.core.logging.FsLogger;
import cn.isliu.core.pojo.ApiResponse;
@ -440,7 +442,16 @@ public class FsApiUtil {
batchPutValuesBuilder.addRange(sheetId + "!A" + titleRow + ":" + position + titleRow);
batchPutValuesBuilder.addRow(headers.toArray());
return FsApiUtil.putValues(spreadsheetToken, batchPutValuesBuilder.build(), client);
Object putValues = FsApiUtil.putValues(spreadsheetToken, batchPutValuesBuilder.build(), client);
String[] positionArr = {"A" + titleRow, position + titleRow};
MapSheetConfig config = MapSheetConfig.createDefault();
CustomCellService.StyleCellsBatchBuilder defaultTableStyle = FsTableUtil.getDefaultTableStyle(sheetId, positionArr,
config.getHeadBackColor(), config.getHeadFontColor());
FsApiUtil.setTableStyle(defaultTableStyle, client, spreadsheetToken);
return putValues;
}
/**

@ -831,6 +831,16 @@ public class FsTableUtil {
return styleCellsBatchBuilder;
}
public static CustomCellService.StyleCellsBatchBuilder getDefaultTableStyle(String sheetId, String[] position,
String backColor, String foreColor) {
CustomCellService.StyleCellsBatchBuilder styleCellsBatchBuilder = CustomCellService.CellRequest.styleCellsBatch()
.addRange(sheetId, position[0], position[1])
.backColor(backColor)
.foreColor(foreColor);
return styleCellsBatchBuilder;
}
public static Map<String, String[]> calculateGroupPositions(List<String> headers, List<String> groupFields) {
Map<String, String[]> positions = new HashMap<>();
int index = 0;