f
This commit is contained in:
@@ -11,10 +11,11 @@ import (
|
||||
|
||||
// ExportConfig 定义了导出所需的配置
|
||||
type ExportConfig struct {
|
||||
SheetName string // 工作表名称
|
||||
Headers []string // 表头
|
||||
Data [][]interface{} // 导出数据
|
||||
ColumnWidths []float64 // 列宽
|
||||
SheetName string // 工作表名称
|
||||
Headers []string // 表头
|
||||
Data [][]interface{} // 导出数据
|
||||
ColumnWidths []float64 // 列宽
|
||||
MergedRegions [][]int // 合并单元格配置 [[startRow, startCol, endRow, endCol], ...]
|
||||
}
|
||||
|
||||
// ExportManager 负责管理不同格式的导出
|
||||
@@ -95,6 +96,30 @@ func (m *ExportManager) generateExcel(ctx context.Context, config *ExportConfig)
|
||||
}
|
||||
}
|
||||
|
||||
// 合并单元格
|
||||
if len(config.MergedRegions) > 0 {
|
||||
for _, region := range config.MergedRegions {
|
||||
startRow := region[0]
|
||||
startCol := region[1]
|
||||
endRow := region[2]
|
||||
endCol := region[3]
|
||||
|
||||
startCell, err := excelize.CoordinatesToCellName(startCol+1, startRow+1)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("生成合并区域起始单元格坐标失败: %v", err)
|
||||
}
|
||||
endCell, err := excelize.CoordinatesToCellName(endCol+1, endRow+1)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("生成合并区域结束单元格坐标失败: %v", err)
|
||||
}
|
||||
|
||||
err = f.MergeCell(sheetName, startCell, endCell)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("合并单元格失败: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 设置列宽
|
||||
for i, width := range config.ColumnWidths {
|
||||
col, err := excelize.ColumnNumberToName(i + 1)
|
||||
|
||||
@@ -11,10 +11,11 @@ import (
|
||||
|
||||
// ExportConfig 定义了导出所需的配置
|
||||
type ExportConfig struct {
|
||||
SheetName string // 工作表名称
|
||||
Headers []string // 表头
|
||||
Data [][]interface{} // 导出数据
|
||||
ColumnWidths []float64 // 列宽
|
||||
SheetName string // 工作表名称
|
||||
Headers []string // 表头
|
||||
Data [][]interface{} // 导出数据
|
||||
ColumnWidths []float64 // 列宽
|
||||
MergedRegions [][]int // 合并单元格配置 [[startRow, startCol, endRow, endCol], ...]
|
||||
}
|
||||
|
||||
// ExportManager 负责管理不同格式的导出
|
||||
|
||||
Reference in New Issue
Block a user