setTableColumns provides a function to set cells value in header row for the table.
(sheet string, showHeaderRow bool, x1, y1, x2 int, tbl *xlsxTable)
| 271 | // setTableColumns provides a function to set cells value in header row for the |
| 272 | // table. |
| 273 | func (f *File) setTableColumns(sheet string, showHeaderRow bool, x1, y1, x2 int, tbl *xlsxTable) error { |
| 274 | var ( |
| 275 | idx int |
| 276 | header []string |
| 277 | tableColumns []*xlsxTableColumn |
| 278 | getTableColumn = func(name string) *xlsxTableColumn { |
| 279 | if tbl != nil && tbl.TableColumns != nil { |
| 280 | for _, column := range tbl.TableColumns.TableColumn { |
| 281 | if column.Name == name { |
| 282 | return column |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | return nil |
| 287 | } |
| 288 | ) |
| 289 | for i := x1; i <= x2; i++ { |
| 290 | idx++ |
| 291 | cell, err := CoordinatesToCellName(i, y1) |
| 292 | if err != nil { |
| 293 | return err |
| 294 | } |
| 295 | name, _ := f.GetCellValue(sheet, cell, Options{RawCellValue: true}) |
| 296 | if _, err := strconv.Atoi(name); err == nil { |
| 297 | if showHeaderRow { |
| 298 | _ = f.SetCellStr(sheet, cell, name) |
| 299 | } |
| 300 | } |
| 301 | if name == "" || inStrSlice(header, name, true) != -1 { |
| 302 | name = "Column" + strconv.Itoa(idx) |
| 303 | if showHeaderRow { |
| 304 | _ = f.SetCellStr(sheet, cell, name) |
| 305 | } |
| 306 | } |
| 307 | header = append(header, name) |
| 308 | if column := getTableColumn(name); column != nil { |
| 309 | column.ID, column.DataDxfID, column.QueryTableFieldID = idx, 0, 0 |
| 310 | tableColumns = append(tableColumns, column) |
| 311 | continue |
| 312 | } |
| 313 | tableColumns = append(tableColumns, &xlsxTableColumn{ |
| 314 | ID: idx, |
| 315 | Name: name, |
| 316 | }) |
| 317 | } |
| 318 | tbl.TableColumns = &xlsxTableColumns{ |
| 319 | Count: len(tableColumns), |
| 320 | TableColumn: tableColumns, |
| 321 | } |
| 322 | return nil |
| 323 | } |
| 324 | |
| 325 | // checkDefinedName check whether there are illegal characters in the defined |
| 326 | // name or table name. Verify that the name: |