|
|
@@ -12,152 +12,7 @@ type LibSuite struct{}
|
|
|
|
|
|
var _ = Suite(&LibSuite{})
|
|
|
|
|
|
-// Test we can correctly open a XSLX file and return a xlsx.File
|
|
|
-// struct.
|
|
|
-func (l *LibSuite) TestOpenFile(c *C) {
|
|
|
- var xlsxFile *File
|
|
|
- var error error
|
|
|
-
|
|
|
- xlsxFile, error = OpenFile("testfile.xlsx")
|
|
|
- c.Assert(error, IsNil)
|
|
|
- c.Assert(xlsxFile, NotNil)
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-// Test we can create a File object from scratch
|
|
|
-func (l *LibSuite) TestCreateFile(c *C) {
|
|
|
- var xlsxFile *File
|
|
|
-
|
|
|
- xlsxFile = NewFile()
|
|
|
- c.Assert(xlsxFile, NotNil)
|
|
|
-}
|
|
|
-
|
|
|
-// Test that when we open a real XLSX file we create xlsx.Sheet
|
|
|
-// objects for the sheets inside the file and that these sheets are
|
|
|
-// themselves correct.
|
|
|
-func (l *LibSuite) TestCreateSheet(c *C) {
|
|
|
- var xlsxFile *File
|
|
|
- var err error
|
|
|
- var sheet *Sheet
|
|
|
- var row *Row
|
|
|
- xlsxFile, err = OpenFile("testfile.xlsx")
|
|
|
- c.Assert(err, IsNil)
|
|
|
- c.Assert(xlsxFile, NotNil)
|
|
|
- sheetLen := len(xlsxFile.Sheets)
|
|
|
- c.Assert(sheetLen, Equals, 3)
|
|
|
- sheet = xlsxFile.Sheets[0]
|
|
|
- rowLen := len(sheet.Rows)
|
|
|
- c.Assert(rowLen, Equals, 2)
|
|
|
- row = sheet.Rows[0]
|
|
|
- c.Assert(len(row.Cells), Equals, 2)
|
|
|
- cell := row.Cells[0]
|
|
|
- cellstring := cell.String()
|
|
|
- c.Assert(cellstring, Equals, "Foo")
|
|
|
-}
|
|
|
-
|
|
|
-// Test that we can add a sheet to a File
|
|
|
-func (l *LibSuite) TestAddSheet(c *C) {
|
|
|
- var f *File
|
|
|
- f = NewFile()
|
|
|
- sheet := f.AddSheet("MySheet")
|
|
|
- c.Assert(sheet, NotNil)
|
|
|
- c.Assert(len(f.Sheets), Equals, 1)
|
|
|
- c.Assert(f.Sheets[0], Equals, sheet)
|
|
|
- c.Assert(len(f.Sheet), Equals, 1)
|
|
|
- c.Assert(f.Sheet["MySheet"], Equals, sheet)
|
|
|
-}
|
|
|
-
|
|
|
-// Test we can add a Row to a Sheet
|
|
|
-func (l *LibSuite) TestAddRow(c *C) {
|
|
|
- var f *File
|
|
|
- f = NewFile()
|
|
|
- sheet := f.AddSheet("MySheet")
|
|
|
- row := sheet.AddRow()
|
|
|
- c.Assert(row, NotNil)
|
|
|
- c.Assert(len(sheet.Rows), Equals, 1)
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-// Test that GetStyle correctly converts the xlsxStyle.Fonts.
|
|
|
-func (l *LibSuite) TestGetStyleWithFonts(c *C) {
|
|
|
- var cell *Cell
|
|
|
- var style *Style
|
|
|
- var xStyles *xlsxStyles
|
|
|
- var fonts []xlsxFont
|
|
|
- var cellXfs []xlsxXf
|
|
|
-
|
|
|
- fonts = make([]xlsxFont, 1)
|
|
|
- fonts[0] = xlsxFont{
|
|
|
- Sz: xlsxVal{Val: "10"},
|
|
|
- Name: xlsxVal{Val: "Calibra"}}
|
|
|
|
|
|
- cellXfs = make([]xlsxXf, 1)
|
|
|
- cellXfs[0] = xlsxXf{ApplyFont: true, FontId: 0}
|
|
|
-
|
|
|
- xStyles = &xlsxStyles{Fonts: fonts, CellXfs: cellXfs}
|
|
|
-
|
|
|
- cell = &Cell{Value: "123", styleIndex: 1, styles: xStyles}
|
|
|
- style = cell.GetStyle()
|
|
|
- c.Assert(style, NotNil)
|
|
|
- c.Assert(style.Font.Size, Equals, 10)
|
|
|
- c.Assert(style.Font.Name, Equals, "Calibra")
|
|
|
-}
|
|
|
-
|
|
|
-// Test that GetStyle correctly converts the xlsxStyle.Fills.
|
|
|
-func (l *LibSuite) TestGetStyleWithFills(c *C) {
|
|
|
- var cell *Cell
|
|
|
- var style *Style
|
|
|
- var xStyles *xlsxStyles
|
|
|
- var fills []xlsxFill
|
|
|
- var cellXfs []xlsxXf
|
|
|
-
|
|
|
- fills = make([]xlsxFill, 1)
|
|
|
- fills[0] = xlsxFill{
|
|
|
- PatternFill: xlsxPatternFill{
|
|
|
- PatternType: "solid",
|
|
|
- FgColor: xlsxColor{RGB: "FF000000"},
|
|
|
- BgColor: xlsxColor{RGB: "00FF0000"}}}
|
|
|
- cellXfs = make([]xlsxXf, 1)
|
|
|
- cellXfs[0] = xlsxXf{ApplyFill: true, FillId: 0}
|
|
|
-
|
|
|
- xStyles = &xlsxStyles{Fills: fills, CellXfs: cellXfs}
|
|
|
-
|
|
|
- cell = &Cell{Value: "123", styleIndex: 1, styles: xStyles}
|
|
|
- style = cell.GetStyle()
|
|
|
- fill := style.Fill
|
|
|
- c.Assert(fill.PatternType, Equals, "solid")
|
|
|
- c.Assert(fill.BgColor, Equals, "00FF0000")
|
|
|
- c.Assert(fill.FgColor, Equals, "FF000000")
|
|
|
-}
|
|
|
-
|
|
|
-// Test that GetStyle correctly converts the xlsxStyle.Borders.
|
|
|
-func (l *LibSuite) TestGetStyleWithBorders(c *C) {
|
|
|
- var cell *Cell
|
|
|
- var style *Style
|
|
|
- var xStyles *xlsxStyles
|
|
|
- var borders []xlsxBorder
|
|
|
- var cellXfs []xlsxXf
|
|
|
-
|
|
|
- borders = make([]xlsxBorder, 1)
|
|
|
- borders[0] = xlsxBorder{
|
|
|
- Left: xlsxLine{Style: "thin"},
|
|
|
- Right: xlsxLine{Style: "thin"},
|
|
|
- Top: xlsxLine{Style: "thin"},
|
|
|
- Bottom: xlsxLine{Style: "thin"}}
|
|
|
-
|
|
|
- cellXfs = make([]xlsxXf, 1)
|
|
|
- cellXfs[0] = xlsxXf{ApplyBorder: true, BorderId: 0}
|
|
|
-
|
|
|
- xStyles = &xlsxStyles{Borders: borders, CellXfs: cellXfs}
|
|
|
-
|
|
|
- cell = &Cell{Value: "123", styleIndex: 1, styles: xStyles}
|
|
|
- style = cell.GetStyle()
|
|
|
- border := style.Border
|
|
|
- c.Assert(border.Left, Equals, "thin")
|
|
|
- c.Assert(border.Right, Equals, "thin")
|
|
|
- c.Assert(border.Top, Equals, "thin")
|
|
|
- c.Assert(border.Bottom, Equals, "thin")
|
|
|
-}
|
|
|
|
|
|
// Test that we can correctly extract a reference table from the
|
|
|
// sharedStrings.xml file embedded in the XLSX file and return a
|