stream_cell.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package xlsx
  2. import (
  3. "strconv"
  4. "time"
  5. )
  6. // StreamCell holds the data, style and type of cell for streaming.
  7. type StreamCell struct {
  8. cellData string
  9. cellStyle StreamStyle
  10. cellType CellType
  11. }
  12. // NewStreamCell creates a new cell containing the given data with the given style and type.
  13. func NewStreamCell(cellData string, cellStyle StreamStyle, cellType CellType) StreamCell {
  14. return StreamCell{
  15. cellData: cellData,
  16. cellStyle: cellStyle,
  17. cellType: cellType,
  18. }
  19. }
  20. // NewStringStreamCell creates a new cell that holds string data, is of type string and uses general formatting.
  21. func NewStringStreamCell(cellData string) StreamCell {
  22. return NewStreamCell(cellData, StreamStyleDefaultString, CellTypeString)
  23. }
  24. // NewStyledStringStreamCell creates a new cell that holds a string and is styled according to the given style.
  25. func NewStyledStringStreamCell(cellData string, cellStyle StreamStyle) StreamCell {
  26. return NewStreamCell(cellData, cellStyle, CellTypeString)
  27. }
  28. // NewIntegerStreamCell creates a new cell that holds an integer value (represented as string),
  29. // is formatted as a standard integer and is of type numeric.
  30. func NewIntegerStreamCell(cellData int) StreamCell {
  31. return NewStreamCell(strconv.Itoa(cellData), StreamStyleDefaultInteger, CellTypeNumeric)
  32. }
  33. // NewStyledIntegerStreamCell creates a new cell that holds an integer value (represented as string)
  34. // and is styled according to the given style.
  35. func NewStyledIntegerStreamCell(cellData int, cellStyle StreamStyle) StreamCell {
  36. return NewStreamCell(strconv.Itoa(cellData), cellStyle, CellTypeNumeric)
  37. }
  38. // NewDateStreamCell creates a new cell that holds a date value and is formatted as dd-mm-yyyy
  39. // and is of type numeric.
  40. func NewDateStreamCell(t time.Time) StreamCell {
  41. excelTime := TimeToExcelTime(t, false)
  42. return NewStreamCell(strconv.Itoa(int(excelTime)), StreamStyleDefaultDate, CellTypeNumeric)
  43. }