| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package xlsx
- import (
- "bytes"
- "testing"
- "xml"
- )
- // Test we can succesfully unmarshal the sheetN.xml files within and
- // XLSX file into an XLSXWorksheet struct (and it's related children).
- func TestUnmarshallWorksheet(t *testing.T) {
- var sheetxml = bytes.NewBufferString(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
- <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><dimension ref="A1:B2"/><sheetViews><sheetView tabSelected="1" workbookViewId="0"><selection activeCell="C2" sqref="C2"/></sheetView></sheetViews><sheetFormatPr baseColWidth="10" defaultRowHeight="15"/><sheetData><row r="1" spans="1:2"><c r="A1" t="s"><v>0</v></c><c r="B1" t="s"><v>1</v></c></row><row r="2" spans="1:2"><c r="A2" t="s"><v>2</v></c><c r="B2" t="s"><v>3</v></c></row></sheetData><pageMargins left="0.7" right="0.7" top="0.78740157499999996" bottom="0.78740157499999996" header="0.3" footer="0.3"/></worksheet>`)
- worksheet := new(XLSXWorksheet)
- error := xml.Unmarshal(sheetxml, worksheet)
- if error != nil {
- t.Error(error.String())
- return
- }
- if worksheet.Dimension.Ref != "A1:B2" {
- t.Error("Expected worksheet.Dimension.Ref == 'A1:B2'")
- }
- if len(worksheet.SheetViews.SheetView) == 0 {
- t.Error("Expected len(worksheet.SheetViews.SheetView) == 1")
- }
- sheetview := worksheet.SheetViews.SheetView[0]
- if sheetview.TabSelected != "1" {
- t.Error("Expected sheetview.TabSelected == '1'")
- }
- if sheetview.WorkbookViewID != "0" {
- t.Error("Expected sheetview.WorkbookViewID == '0'")
- }
- if sheetview.Selection.ActiveCell != "C2" {
- t.Error("Expeceted sheetview.Selection.ActiveCell == 'C2'")
- }
- if sheetview.Selection.SQRef != "C2" {
- t.Error("Expected sheetview.Selection.SQRef == 'C2'")
- }
- if worksheet.SheetFormatPr.BaseColWidth != "10" {
- t.Error("Expected worksheet.SheetFormatPr.BaseColWidth == '10'")
- }
- if worksheet.SheetFormatPr.DefaultRowHeight != "15" {
- t.Error("Expected worksheet.SheetFormatPr.DefaultRowHeight == '15'")
- }
- if len(worksheet.SheetData.Row) == 0 {
- t.Error("Expected len(worksheet.SheetData.Row) == '2'")
- }
- row := worksheet.SheetData.Row[0]
- if row.R != "1" {
- t.Error("Expected row.r == '1'")
- }
- if row.Spans != "1:2" {
- t.Error("Expected row.Spans == '1:2'")
- }
- if len(row.C) != 2 {
- t.Error("Expected len(row.C) == 2")
- }
- c := row.C[0]
- if c.R != "A1" {
- t.Error("Expected c.R == 'A1'")
- }
- if c.T != "s" {
- t.Error("Expected c.T == 's'")
- }
- if c.V.Data != "0" {
- t.Error("Expected c.V.Data == '0'")
- }
- }
|