stream_cell.go 1.8 KB

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