@@ -140,9 +140,24 @@ func (f *File) UnmergeCell(sheet, topLeftCell, bottomRightCell string) error {
140
140
}
141
141
142
142
// GetMergeCells provides a function to get all merged cells from a specific
143
- // worksheet.
144
- func (f * File ) GetMergeCells (sheet string ) ([]MergeCell , error ) {
145
- var mergeCells []MergeCell
143
+ // worksheet. If the `withoutValues` parameter is set to true, it will not
144
+ // return the cell values of merged cells, only the range reference will be
145
+ // returned. For example get all merged cells on Sheet1:
146
+ //
147
+ // mergeCells, err := f.GetMergeCells("Sheet1")
148
+ //
149
+ // If you want to get merged cells without cell values, you can use the
150
+ // following code:
151
+ //
152
+ // mergeCells, err := f.GetMergeCells("Sheet1", true)
153
+ func (f * File ) GetMergeCells (sheet string , withoutValues ... bool ) ([]MergeCell , error ) {
154
+ var (
155
+ mergeCells []MergeCell
156
+ withoutVal bool
157
+ )
158
+ if len (withoutValues ) > 0 {
159
+ withoutVal = withoutValues [0 ]
160
+ }
146
161
ws , err := f .workSheetReader (sheet )
147
162
if err != nil {
148
163
return mergeCells , err
@@ -153,9 +168,11 @@ func (f *File) GetMergeCells(sheet string) ([]MergeCell, error) {
153
168
}
154
169
mergeCells = make ([]MergeCell , 0 , len (ws .MergeCells .Cells ))
155
170
for i := range ws .MergeCells .Cells {
156
- ref := ws .MergeCells .Cells [i ].Ref
157
- cell := strings .Split (ref , ":" )[0 ]
158
- val , _ := f .GetCellValue (sheet , cell )
171
+ ref , val := ws .MergeCells .Cells [i ].Ref , ""
172
+ if ! withoutVal {
173
+ cell := strings .Split (ref , ":" )[0 ]
174
+ val , _ = f .GetCellValue (sheet , cell )
175
+ }
159
176
mergeCells = append (mergeCells , []string {ref , val })
160
177
}
161
178
}
0 commit comments