package xlsx import ( "bytes" "encoding/xml" . "gopkg.in/check.v1" ) type WorksheetSuite struct{} var _ = Suite(&WorksheetSuite{}) // Test we can succesfully unmarshal the sheetN.xml files within and // XLSX file into an xlsxWorksheet struct (and it's related children). func (w *WorksheetSuite) TestUnmarshallWorksheet(c *C) { var sheetxml = bytes.NewBufferString( ` `) worksheet := new(xlsxWorksheet) err := xml.NewDecoder(sheetxml).Decode(worksheet) c.Assert(err, IsNil) c.Assert(worksheet.Dimension.Ref, Equals, "A1:B2") c.Assert(worksheet.SheetData.Row, HasLen, 2) c.Assert(worksheet.SheetFormatPr.DefaultRowHeight, Equals, 15.0) c.Assert(worksheet.SheetFormatPr.DefaultColWidth, Equals, 8.0) row := worksheet.SheetData.Row[0] c.Assert(row.R, Equals, 1) c.Assert(row.C, HasLen, 2) cell := row.C[0] c.Assert(cell.R, Equals, "A1") c.Assert(cell.T, Equals, "s") c.Assert(cell.V, Equals, "0") c.Assert(worksheet.AutoFilter, NotNil) c.Assert(worksheet.AutoFilter.Ref, Equals, "A1:Z4") } // MergeCells information is correctly read from the worksheet. func (w *WorksheetSuite) TestUnmarshallWorksheetWithMergeCells(c *C) { var sheetxml = bytes.NewBufferString( ` 0 1 2 `) worksheet := new(xlsxWorksheet) err := xml.NewDecoder(sheetxml).Decode(worksheet) c.Assert(err, IsNil) c.Assert(worksheet.MergeCells, NotNil) c.Assert(worksheet.MergeCells.Count, Equals, 1) mergeCell := worksheet.MergeCells.Cells[0] c.Assert(mergeCell.Ref, Equals, "A1:B1") } // MergeCells.getExtents returns the horizontal and vertical extent of // a merge that begins at a given reference. func (w *WorksheetSuite) TestMergeCellsGetExtent(c *C) { mc := xlsxMergeCells{Count: 2} mc.Cells = make([]xlsxMergeCell, 2) mc.Cells[0] = xlsxMergeCell{Ref: "A11:A12"} mc.Cells[1] = xlsxMergeCell{Ref: "A1:C5"} h, v, err := mc.getExtent("A1") c.Assert(err, IsNil) c.Assert(h, Equals, 2) c.Assert(v, Equals, 4) h, v, err = mc.getExtent("A11") c.Assert(err, IsNil) c.Assert(h, Equals, 0) c.Assert(v, Equals, 1) }