cell_test.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package xlsx
  2. import (
  3. . "gopkg.in/check.v1"
  4. )
  5. type CellSuite struct {}
  6. var _ = Suite(&CellSuite{})
  7. // Test that we can set and get a Value from a Cell
  8. func (s *CellSuite) TestValueSet(c *C) {
  9. // Note, this test is fairly pointless, it serves mostly to
  10. // reinforce that this functionality is important, and should
  11. // the mechanics of this all change at some point, to remind
  12. // us not to lose this.
  13. cell := Cell{}
  14. cell.Value = "A string"
  15. c.Assert(cell.Value, Equals, "A string")
  16. }
  17. // Test that GetStyle correctly converts the xlsxStyle.Fonts.
  18. func (s *CellSuite) TestGetStyleWithFonts(c *C) {
  19. var cell *Cell
  20. var style *Style
  21. var xStyles *xlsxStyles
  22. var fonts []xlsxFont
  23. var cellXfs []xlsxXf
  24. fonts = make([]xlsxFont, 1)
  25. fonts[0] = xlsxFont{
  26. Sz: xlsxVal{Val: "10"},
  27. Name: xlsxVal{Val: "Calibra"}}
  28. cellXfs = make([]xlsxXf, 1)
  29. cellXfs[0] = xlsxXf{ApplyFont: true, FontId: 0}
  30. xStyles = &xlsxStyles{Fonts: fonts, CellXfs: cellXfs}
  31. cell = &Cell{Value: "123", styleIndex: 1, styles: xStyles}
  32. style = cell.GetStyle()
  33. c.Assert(style, NotNil)
  34. c.Assert(style.Font.Size, Equals, 10)
  35. c.Assert(style.Font.Name, Equals, "Calibra")
  36. }
  37. // Test that GetStyle correctly converts the xlsxStyle.Fills.
  38. func (s *CellSuite) TestGetStyleWithFills(c *C) {
  39. var cell *Cell
  40. var style *Style
  41. var xStyles *xlsxStyles
  42. var fills []xlsxFill
  43. var cellXfs []xlsxXf
  44. fills = make([]xlsxFill, 1)
  45. fills[0] = xlsxFill{
  46. PatternFill: xlsxPatternFill{
  47. PatternType: "solid",
  48. FgColor: xlsxColor{RGB: "FF000000"},
  49. BgColor: xlsxColor{RGB: "00FF0000"}}}
  50. cellXfs = make([]xlsxXf, 1)
  51. cellXfs[0] = xlsxXf{ApplyFill: true, FillId: 0}
  52. xStyles = &xlsxStyles{Fills: fills, CellXfs: cellXfs}
  53. cell = &Cell{Value: "123", styleIndex: 1, styles: xStyles}
  54. style = cell.GetStyle()
  55. fill := style.Fill
  56. c.Assert(fill.PatternType, Equals, "solid")
  57. c.Assert(fill.BgColor, Equals, "00FF0000")
  58. c.Assert(fill.FgColor, Equals, "FF000000")
  59. }
  60. // Test that GetStyle correctly converts the xlsxStyle.Borders.
  61. func (s *CellSuite) TestGetStyleWithBorders(c *C) {
  62. var cell *Cell
  63. var style *Style
  64. var xStyles *xlsxStyles
  65. var borders []xlsxBorder
  66. var cellXfs []xlsxXf
  67. borders = make([]xlsxBorder, 1)
  68. borders[0] = xlsxBorder{
  69. Left: xlsxLine{Style: "thin"},
  70. Right: xlsxLine{Style: "thin"},
  71. Top: xlsxLine{Style: "thin"},
  72. Bottom: xlsxLine{Style: "thin"}}
  73. cellXfs = make([]xlsxXf, 1)
  74. cellXfs[0] = xlsxXf{ApplyBorder: true, BorderId: 0}
  75. xStyles = &xlsxStyles{Borders: borders, CellXfs: cellXfs}
  76. cell = &Cell{Value: "123", styleIndex: 1, styles: xStyles}
  77. style = cell.GetStyle()
  78. border := style.Border
  79. c.Assert(border.Left, Equals, "thin")
  80. c.Assert(border.Right, Equals, "thin")
  81. c.Assert(border.Top, Equals, "thin")
  82. c.Assert(border.Bottom, Equals, "thin")
  83. }