Browse Source

Add basic support for reading freeze and split state out of worksheets.

Brian Smith 11 years ago
parent
commit
67dac2f125
4 changed files with 56 additions and 0 deletions
  1. 23 0
      lib.go
  2. 7 0
      lib_test.go
  3. 13 0
      sheet.go
  4. 13 0
      xmlWorksheet.go

+ 23 - 0
lib.go

@@ -459,6 +459,28 @@ type indexedSheet struct {
 	Error error
 }
 
+func readSheetViews(xSheetViews xlsxSheetViews) []SheetView {
+	if xSheetViews.SheetView == nil || len(xSheetViews.SheetView) == 0 {
+		return nil
+	}
+	sheetViews := []SheetView{}
+	for _, xSheetView := range xSheetViews.SheetView {
+		sheetView := SheetView{}
+		if xSheetView.Pane != nil {
+			xlsxPane := xSheetView.Pane
+			pane := &Pane{}
+			pane.XSplit = xlsxPane.XSplit
+			pane.YSplit = xlsxPane.YSplit
+			pane.TopLeftCell = xlsxPane.TopLeftCell
+			pane.ActivePane = xlsxPane.ActivePane
+			pane.State = xlsxPane.State
+			sheetView.Pane = pane
+		}
+		sheetViews = append(sheetViews, sheetView)
+	}
+	return sheetViews
+}
+
 // readSheetFromFile is the logic of converting a xlsxSheet struct
 // into a Sheet struct.  This work can be done in parallel and so
 // readSheetsFromZipFile will spawn an instance of this function per
@@ -475,6 +497,7 @@ func readSheetFromFile(sc chan *indexedSheet, index int, rsheet xlsxSheet, fi *F
 	sheet.File = fi
 	sheet.Rows, sheet.Cols, sheet.MaxCol, sheet.MaxRow = readRowsFromSheet(worksheet, fi)
 	sheet.Hidden = rsheet.State == sheetStateHidden || rsheet.State == sheetStateVeryHidden
+	sheet.SheetViews = readSheetViews(worksheet.SheetViews)
 	result.Sheet = sheet
 	sc <- result
 }

+ 7 - 0
lib_test.go

@@ -264,6 +264,7 @@ func (l *LibSuite) TestReadRowsFromSheet(c *C) {
   <sheetViews>
     <sheetView tabSelected="1" workbookViewId="0">
       <selection activeCell="C2" sqref="C2"/>
+	  <pane ySplit="1" topLeftCell="A2" activePane="bottomLeft" state="frozen"/>
     </sheetView>
   </sheetViews>
   <sheetFormatPr baseColWidth="10" defaultRowHeight="15"/>
@@ -312,6 +313,12 @@ func (l *LibSuite) TestReadRowsFromSheet(c *C) {
 	c.Assert(col.Min, Equals, 0)
 	c.Assert(col.Max, Equals, 0)
 	c.Assert(col.Hidden, Equals, false)
+	c.Assert(len(worksheet.SheetViews.SheetView), Equals, 1)
+	sheetView := worksheet.SheetViews.SheetView[0]
+	c.Assert(sheetView.Pane, NotNil)
+	pane := sheetView.Pane
+	c.Assert(pane.XSplit, Equals, 0)
+	c.Assert(pane.YSplit, Equals, 1)
 }
 
 func (l *LibSuite) TestReadRowsFromSheetWithLeadingEmptyRows(c *C) {

+ 13 - 0
sheet.go

@@ -15,6 +15,19 @@ type Sheet struct {
 	MaxRow int
 	MaxCol int
 	Hidden bool
+	SheetViews []SheetView
+}
+
+type SheetView struct {
+	Pane *Pane
+}
+
+type Pane struct {
+	XSplit      int
+	YSplit      int
+	TopLeftCell string
+	ActivePane  string
+	State       string // Either "split" or "frozen"
 }
 
 // Add a new Row to a Sheet

+ 13 - 0
xmlWorksheet.go

@@ -134,6 +134,7 @@ type xlsxSheetView struct {
 	ZoomScalePageLayoutView float64         `xml:"zoomScalePageLayoutView,attr"`
 	WorkbookViewId          int             `xml:"workbookViewId,attr"`
 	Selection               []xlsxSelection `xml:"selection"`
+	Pane                    *xlsxPane       `xml:"pane"`
 }
 
 // xlsxSelection directly maps the selection element in the namespace
@@ -147,6 +148,18 @@ type xlsxSelection struct {
 	SQRef        string `xml:"sqref,attr"`
 }
 
+// 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 xlsxPane struct {
+	XSplit      int    `xml:"xSplit,attr"`
+	YSplit      int    `xml:"ySplit,attr"`
+	TopLeftCell string `xml:"topLeftCell,attr"`
+	ActivePane  string `xml:"activePane,attr"`
+	State       string `xml:"state,attr"` // Either "split" or "frozen"
+}
+
 // xlsxSheetPr directly maps the sheetPr element in the namespace
 // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
 // currently I have not checked it for completeness - it does as much