col.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package xlsx
  2. // Default column width in excel
  3. const ColWidth = 9.5
  4. const Excel2006MaxRowIndex = 1048576
  5. const Excel2006MinRowIndex = 1
  6. type Col struct {
  7. Min int
  8. Max int
  9. Hidden bool
  10. Width float64
  11. Collapsed bool
  12. OutlineLevel uint8
  13. numFmt string
  14. parsedNumFmt *parsedNumberFormat
  15. style *Style
  16. DataValidation *xlsxCellDataValidation
  17. DataValidationStart int
  18. DataValidationEnd int
  19. }
  20. // SetType will set the format string of a column based on the type that you want to set it to.
  21. // This function does not really make a lot of sense.
  22. func (c *Col) SetType(cellType CellType) {
  23. switch cellType {
  24. case CellTypeString:
  25. c.numFmt = builtInNumFmt[builtInNumFmtIndex_STRING]
  26. case CellTypeNumeric:
  27. c.numFmt = builtInNumFmt[builtInNumFmtIndex_INT]
  28. case CellTypeBool:
  29. c.numFmt = builtInNumFmt[builtInNumFmtIndex_GENERAL] //TEMP
  30. case CellTypeInline:
  31. c.numFmt = builtInNumFmt[builtInNumFmtIndex_STRING]
  32. case CellTypeError:
  33. c.numFmt = builtInNumFmt[builtInNumFmtIndex_GENERAL] //TEMP
  34. case CellTypeDate:
  35. // Cells that are stored as dates are not properly supported in this library.
  36. // They should instead be stored as a Numeric with a date format.
  37. c.numFmt = builtInNumFmt[builtInNumFmtIndex_GENERAL]
  38. case CellTypeStringFormula:
  39. c.numFmt = builtInNumFmt[builtInNumFmtIndex_STRING]
  40. }
  41. }
  42. // GetStyle returns the Style associated with a Col
  43. func (c *Col) GetStyle() *Style {
  44. return c.style
  45. }
  46. // SetStyle sets the style of a Col
  47. func (c *Col) SetStyle(style *Style) {
  48. c.style = style
  49. }
  50. // SetDataValidation set data validation with start,end ; start or end = 0 equal all column
  51. func (c *Col) SetDataValidation(dd *xlsxCellDataValidation, start, end int) {
  52. //2006 excel all row 1048576
  53. if 0 == start {
  54. c.DataValidationStart = Excel2006MinRowIndex
  55. } else {
  56. c.DataValidationStart = start
  57. }
  58. if 0 == end || c.DataValidationEnd > Excel2006MaxRowIndex {
  59. c.DataValidationEnd = Excel2006MaxRowIndex
  60. } else {
  61. c.DataValidationEnd = end
  62. }
  63. c.DataValidation = dd
  64. }
  65. // SetDataValidationWithStart set data validation with start
  66. func (c *Col) SetDataValidationWithStart(dd *xlsxCellDataValidation, start int) {
  67. //2006 excel all row 1048576
  68. if 0 == start {
  69. c.DataValidationStart = Excel2006MinRowIndex
  70. } else {
  71. c.DataValidationStart = start
  72. }
  73. c.DataValidationEnd = Excel2006MaxRowIndex
  74. c.DataValidation = dd
  75. }