stream_cell.go 1.8 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 StreamCell
  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. // MakeStringStreamCell creates a new cell that holds string data, is of type string and uses general formatting
  21. func MakeStringStreamCell(cellData string) StreamCell {
  22. return NewStreamCell(cellData, Strings, CellTypeString)
  23. }
  24. // MakeStyledStringStreamCell creates a new cell that holds a string and is styled according to the given style
  25. func MakeStyledStringStreamCell(cellData string, cellStyle StreamStyle) StreamCell {
  26. return NewStreamCell(cellData, cellStyle, CellTypeString)
  27. }
  28. // MakeIntegerStreamCell 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 MakeIntegerStreamCell(cellData int) StreamCell {
  31. return NewStreamCell(strconv.Itoa(cellData), Integers, CellTypeNumeric)
  32. }
  33. // MakeStyledIntegerStreamCell creates a new cell that holds an integer value (represented as string)
  34. // and is styled according to the given style.
  35. func MakeStyledIntegerStreamCell(cellData int, cellStyle StreamStyle) StreamCell {
  36. return NewStreamCell(strconv.Itoa(cellData), cellStyle, CellTypeNumeric)
  37. }
  38. // MakeDateStreamCell creates a new cell that holds a date value and is formatted as dd-mm-yyyy and
  39. // and is of type numeric
  40. func MakeDateStreamCell(t time.Time) StreamCell {
  41. excelTime := TimeToExcelTime(t, false)
  42. return NewStreamCell(strconv.Itoa(int(excelTime)), Dates, CellTypeNumeric)
  43. }