MCPcopy
hub / github.com/qax-os/excelize / SetRow

Method SetRow

stream.go:388–436  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

386// As a special case, if Cell is used as a value, then the Cell.StyleID will be
387// applied to that cell.
388func (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

Callers 14

TestZip64Function · 0.95
BenchmarkStreamWriterFunction · 0.95
TestStreamWriterFunction · 0.95
TestStreamSetColVisibleFunction · 0.95
TestStreamSetColStyleFunction · 0.95
TestStreamSetColWidthFunction · 0.95
TestStreamSetPanesFunction · 0.95
TestStreamTableFunction · 0.95
TestStreamSetRowFunction · 0.95

Calls 13

writeSheetDataMethod · 0.95
setCellValFuncMethod · 0.95
CellNameToCoordinatesFunction · 0.85
newStreamSetRowErrorFunction · 0.85
parseRowOptsFunction · 0.85
CoordinatesToCellNameFunction · 0.85
setCellFormulaFunction · 0.85
writeCellFunction · 0.85
marshalAttrsMethod · 0.80
WriteStringMethod · 0.80
StringMethod · 0.80
prepareCellStyleMethod · 0.80

Tested by 14

TestZip64Function · 0.76
BenchmarkStreamWriterFunction · 0.76
TestStreamWriterFunction · 0.76
TestStreamSetColVisibleFunction · 0.76
TestStreamSetColStyleFunction · 0.76
TestStreamSetColWidthFunction · 0.76
TestStreamSetPanesFunction · 0.76
TestStreamTableFunction · 0.76
TestStreamSetRowFunction · 0.76