SetRow writes an array to stream rows by giving starting cell reference and a pointer to an array of values. Note that you must call the 'Flush' function to end the streaming writing process. As a special case, if Cell is used as a value, then the Cell.StyleID will be applied to that cell.
(cell string, values []interface{}, opts ...RowOpts)
| 386 | // As a special case, if Cell is used as a value, then the Cell.StyleID will be |
| 387 | // applied to that cell. |
| 388 | func (sw *StreamWriter) SetRow(cell string, values []interface{}, opts ...RowOpts) error { |
| 389 | col, row, err := CellNameToCoordinates(cell) |
| 390 | if err != nil { |
| 391 | return err |
| 392 | } |
| 393 | if row <= sw.rows { |
| 394 | return newStreamSetRowError(row) |
| 395 | } |
| 396 | sw.rows = row |
| 397 | sw.writeSheetData() |
| 398 | options := parseRowOpts(opts...) |
| 399 | attrs, err := options.marshalAttrs() |
| 400 | if err != nil { |
| 401 | return err |
| 402 | } |
| 403 | _, _ = sw.rawData.WriteString(`<row r="`) |
| 404 | _, _ = sw.rawData.WriteString(strconv.Itoa(row)) |
| 405 | _, _ = sw.rawData.WriteString(`"`) |
| 406 | _, _ = sw.rawData.WriteString(attrs.String()) |
| 407 | _, _ = sw.rawData.WriteString(`>`) |
| 408 | for i, val := range values { |
| 409 | if val == nil { |
| 410 | continue |
| 411 | } |
| 412 | ref, err := CoordinatesToCellName(col+i, row) |
| 413 | if err != nil { |
| 414 | return err |
| 415 | } |
| 416 | c := xlsxC{R: ref, S: sw.worksheet.prepareCellStyle(col+i, row, options.StyleID)} |
| 417 | var s int |
| 418 | if v, ok := val.(Cell); ok { |
| 419 | s, val = v.StyleID, v.Value |
| 420 | setCellFormula(&c, v.Formula) |
| 421 | } else if v, ok := val.(*Cell); ok && v != nil { |
| 422 | s, val = v.StyleID, v.Value |
| 423 | setCellFormula(&c, v.Formula) |
| 424 | } |
| 425 | if s > 0 { |
| 426 | c.S = s |
| 427 | } |
| 428 | if err = sw.setCellValFunc(&c, val); err != nil { |
| 429 | _, _ = sw.rawData.WriteString(`</row>`) |
| 430 | return err |
| 431 | } |
| 432 | writeCell(&sw.rawData, c) |
| 433 | } |
| 434 | _, _ = sw.rawData.WriteString(`</row>`) |
| 435 | return sw.rawData.Sync() |
| 436 | } |
| 437 | |
| 438 | // SetColVisible provides a function set the visibility of a single column or |
| 439 | // multiple columns for the StreamWriter. Note that you must call the |