Browse Source

Remove some unused information from the low level struct definitions to simplify things a little.

Geoffrey J. Teale 12 years ago
parent
commit
8ef999590e
2 changed files with 51 additions and 75 deletions
  1. 8 46
      worksheet.go
  2. 43 29
      worksheet_test.go

+ 8 - 46
worksheet.go

@@ -5,55 +5,25 @@ package xlsx
 // currently I have not checked it for completeness - it does as much
 // as I need.
 type xlsxWorksheet struct {
-	Dimension     xlsxDimension     `xml:"dimension"`
-	SheetViews    xlsxSheetViews    `xml:"sheetViews"`
-	SheetFormatPr xlsxSheetFormatPr `xml:"sheetFormatPr"`
+	Cols          xlsxCols          `xml:"cols"`
 	SheetData     xlsxSheetData     `xml:"sheetData"`
 }
 
-// xlsxDimension directly maps the dimension element in the namespace
+// xlsxCols directly maps the cols element in the namespace
 // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
 // currently I have not checked it for completeness - it does as much
 // as I need.
-type xlsxDimension struct {
-	Ref string `xml:"ref,attr"`
+type xlsxCols struct {
+	Col []xlsxCol `xml:"col"`
 }
 
-// xlsxSheetViews directly maps the sheetViews element in the namespace
+// xlsxCol directly maps the col element in the namespace
 // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
 // currently I have not checked it for completeness - it does as much
 // as I need.
-type xlsxSheetViews struct {
-	SheetView []xlsxSheetView `xml:"sheetView"`
-}
-
-// xlsxSheetView directly maps the sheetView element in the namespace
-// http://schemas.openxmlformats.org/spreadsheetml/2006/main -
-// currently I have not checked it for completeness - it does as much
-// as I need.
-type xlsxSheetView struct {
-	TabSelected    string        `xml:"tabSelected,attr"`
-	WorkbookViewID string        `xml:"workbookViewId,attr"`
-	Selection      xlsxSelection `xml:"selection"`
-}
-
-// xlsxSelection directly maps the selection element in the namespace
-// http://schemas.openxmlformats.org/spreadsheetml/2006/main -
-// currently I have not checked it for completeness - it does as much
-// as I need.
-
-type xlsxSelection struct {
-	ActiveCell string `xml:"activeCell,attr"`
-	SQRef      string `xml:"sqref,attr"`
-}
-
-// xlsxSheetFormatPr directly maps the sheetFormatPr element in the namespace
-// http://schemas.openxmlformats.org/spreadsheetml/2006/main -
-// currently I have not checked it for completeness - it does as much
-// as I need.
-type xlsxSheetFormatPr struct {
-	BaseColWidth     string `xml:"baseColWidth,attr"`
-	DefaultRowHeight string `xml:"defaultRowHeight,attr"`
+type xlsxCol struct {
+	Max       int     `xml:"max,attr"`
+	Min       int     `xml:"min,attr"`
 }
 
 // xlsxSheetData directly maps the sheetData element in the namespace
@@ -85,14 +55,6 @@ type xlsxC struct {
 	V string `xml:"v"`
 }
 
-// xlsxV directly maps the v element in the namespace
-// http://schemas.openxmlformats.org/spreadsheetml/2006/main -
-// currently I have not checked it for completeness - it does as much
-// as I need.
-// type xlsxV struct {
-// 	Data string `xml:"chardata"`
-// }
-
 // get cell
 func (sh *Sheet) Cell(row, col int) *Cell {
 

+ 43 - 29
worksheet_test.go

@@ -11,38 +11,55 @@ import (
 // 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 xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
+  <sheetPr filterMode="false">
+    <pageSetUpPr fitToPage="false"/>
+  </sheetPr>
+  <dimension ref="A1:B2"/>
+  <sheetViews>
+    <sheetView colorId="64" defaultGridColor="true" rightToLeft="false" showFormulas="false" showGridLines="true" showOutlineSymbols="true" showRowColHeaders="true" showZeros="true" tabSelected="true" topLeftCell="A1" view="normal" windowProtection="false" workbookViewId="0" zoomScale="100" zoomScaleNormal="100" zoomScalePageLayoutView="100">
+      <selection activeCell="B2" activeCellId="0" pane="topLeft" sqref="B2"/>
+    </sheetView>
+  </sheetViews>
+  <sheetFormatPr defaultRowHeight="15">
+  </sheetFormatPr>
+  <cols>
+    <col collapsed="false" hidden="false" max="1025" min="1" style="0" width="10.5748987854251"/>
+  </cols>
+  <sheetData>
+    <row collapsed="false" customFormat="false" customHeight="false" hidden="false" ht="14.9" outlineLevel="0" r="1">
+      <c r="A1" s="1" t="s">
+        <v>0</v>
+      </c>
+      <c r="B1" s="0" t="s">
+        <v>1</v>
+      </c>
+    </row>
+    <row collapsed="false" customFormat="false" customHeight="false" hidden="false" ht="14.9" outlineLevel="0" r="2">
+      <c r="A2" s="0" t="s">
+        <v>2</v>
+      </c>
+      <c r="B2" s="2" t="s">
+        <v>3</v>
+      </c>
+    </row>
+  </sheetData>
+  <printOptions headings="false" gridLines="false" gridLinesSet="true" horizontalCentered="false" verticalCentered="false"/>
+  <pageMargins left="0.7" right="0.7" top="0.7875" bottom="0.7875" header="0.511805555555555" footer="0.511805555555555"/>
+  <pageSetup blackAndWhite="false" cellComments="none" copies="1" draft="false" firstPageNumber="0" fitToHeight="1" fitToWidth="1" horizontalDpi="300" orientation="portrait" pageOrder="downThenOver" paperSize="9" scale="100" useFirstPageNumber="false" usePrinterDefaults="false" verticalDpi="300"/>
+  <headerFooter differentFirst="false" differentOddEven="false">
+    <oddHeader>
+    </oddHeader>
+    <oddFooter>
+    </oddFooter>
+  </headerFooter>
+</worksheet>`)
 	worksheet := new(xlsxWorksheet)
 	error := xml.NewDecoder(sheetxml).Decode(worksheet)
 	if error != nil {
 		t.Error(error.Error())
 		return
 	}
-	if worksheet.Dimension.Ref != "A1:B2" {
-		t.Error(fmt.Sprintf("Expected worksheet.Dimension.Ref == 'A1:B2', got %s", worksheet.Dimension.Ref))
-	}
-	if len(worksheet.SheetViews.SheetView) == 0 {
-		t.Error(fmt.Sprintf("Expected len(worksheet.SheetViews.SheetView) == 1, got %d", len(worksheet.SheetViews.SheetView)))
-	}
-	sheetview := worksheet.SheetViews.SheetView[0]
-	if sheetview.TabSelected != "1" {
-		t.Error(fmt.Sprintf("Expected sheetview.TabSelected == '1', got %s", sheetview.TabSelected))
-	}
-	if sheetview.WorkbookViewID != "0" {
-		t.Error(fmt.Sprintf("Expected sheetview.WorkbookViewID == '0', got %s", sheetview.WorkbookViewID))
-	}
-	if sheetview.Selection.ActiveCell != "C2" {
-		t.Error(fmt.Sprintf("Expeceted sheetview.Selection.ActiveCell == 'C2', got %s", sheetview.Selection.ActiveCell))
-	}
-	if sheetview.Selection.SQRef != "C2" {
-		t.Error(fmt.Sprintf("Expected sheetview.Selection.SQRef == 'C2', got %s", sheetview.Selection.SQRef))
-	}
-	if worksheet.SheetFormatPr.BaseColWidth != "10" {
-		t.Error(fmt.Sprintf("Expected worksheet.SheetFormatPr.BaseColWidth == '10', got %s", worksheet.SheetFormatPr.BaseColWidth))
-	}
-	if worksheet.SheetFormatPr.DefaultRowHeight != "15" {
-		t.Error(fmt.Sprintf("Expected worksheet.SheetFormatPr.DefaultRowHeight == '15', got %s", worksheet.SheetFormatPr.DefaultRowHeight))
-	}
 	if len(worksheet.SheetData.Row) == 0 {
 		t.Error(fmt.Sprintf("Expected len(worksheet.SheetData.Row) == '2', got %d", worksheet.SheetData.Row))
 	}
@@ -50,9 +67,6 @@ func TestUnmarshallWorksheet(t *testing.T) {
 	if row.R != "1" {
 		t.Error(fmt.Sprintf("Expected row.r == '1', got %s", row.R))
 	}
-	if row.Spans != "1:2" {
-		t.Error(fmt.Sprintf("Expected row.Spans == '1:2', got %s", row.Spans))
-	}
 	if len(row.C) != 2 {
 		t.Error(fmt.Sprintf("Expected len(row.C) == 2, got %s", row.C))
 	}