Browse Source

Add hidden cell property and rudimentary column support

Andrew Schwartz 11 years ago
parent
commit
b05cadc8a8
6 changed files with 31 additions and 4 deletions
  1. 1 0
      cell.go
  2. 5 0
      col.go
  3. 1 0
      col_test.go
  4. 9 0
      lib.go
  5. 2 1
      row.go
  6. 13 3
      worksheet.go

+ 1 - 0
cell.go

@@ -59,6 +59,7 @@ type Cell struct {
 	styles         *xlsxStyles
 	numFmtRefTable map[int]xlsxNumFmt
 	date1904       bool
+	Hidden         bool
 }
 
 // CellInterface defines the public API of the Cell.

+ 5 - 0
col.go

@@ -0,0 +1,5 @@
+package xlsx
+
+type Col struct {
+	Hidden bool
+}

+ 1 - 0
col_test.go

@@ -0,0 +1 @@
+package xlsx

+ 9 - 0
lib.go

@@ -334,6 +334,7 @@ func getValueFromCellData(rawcell xlsxC, reftable *RefTable) string {
 // the value references from the reference table and stores them in
 func readRowsFromSheet(Worksheet *xlsxWorksheet, file *File) ([]*Row, int, int) {
 	var rows []*Row
+	var cols []*Col
 	var row *Row
 	var minCol, maxCol, minRow, maxRow, colCount, rowCount int
 	var reftable *RefTable
@@ -355,7 +356,14 @@ func readRowsFromSheet(Worksheet *xlsxWorksheet, file *File) ([]*Row, int, int)
 	rowCount = (maxRow - minRow) + 1
 	colCount = (maxCol - minCol) + 1
 	rows = make([]*Row, rowCount)
+	cols = make([]*Col, len(Worksheet.Cols.Col))
 	insertRowIndex = minRow
+	for colIndex := 0; colIndex < len(Worksheet.Cols.Col); colIndex++ {
+		rawcol := Worksheet.Cols.Col[colIndex]
+		cols[colIndex] = &Col{
+			Hidden: rawcol.Hidden,
+		}
+	}
 	for rowIndex := 0; rowIndex < len(Worksheet.SheetData.Row); rowIndex++ {
 		rawrow := Worksheet.SheetData.Row[rowIndex]
 		// Some spreadsheets will omit blank rows from the
@@ -389,6 +397,7 @@ func readRowsFromSheet(Worksheet *xlsxWorksheet, file *File) ([]*Row, int, int)
 			row.Cells[cellX].styles = file.styles
 			row.Cells[cellX].numFmtRefTable = file.numFmtRefTable
 			row.Cells[cellX].date1904 = file.Date1904
+			row.Cells[cellX].Hidden = rawrow.Hidden || cols[cellX].Hidden
 			insertColIndex++
 		}
 		if len(rows) > insertRowIndex-minRow {

+ 2 - 1
row.go

@@ -1,7 +1,8 @@
 package xlsx
 
 type Row struct {
-	Cells []*Cell
+	Cells  []*Cell
+	Hidden bool
 }
 
 func (r *Row) AddCell() *Cell {

+ 13 - 3
worksheet.go

@@ -11,9 +11,18 @@ import (
 type xlsxWorksheet struct {
 	XMLName   xml.Name      `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main worksheet"`
 	Dimension xlsxDimension `xml:"dimension"`
+	Cols      xslxCols      `xml:"cols"`
 	SheetData xlsxSheetData `xml:"sheetData"`
 }
 
+type xslxCols struct {
+	Col []xlsxCol `xml:"col"`
+}
+
+type xlsxCol struct {
+	Hidden bool `xml:"hidden,attr,omitempty"`
+}
+
 // xlsxDimension directly maps the dimension element in the namespace
 // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
 // currently I have not checked it for completeness - it does as much
@@ -36,9 +45,10 @@ type xlsxSheetData struct {
 // currently I have not checked it for completeness - it does as much
 // as I need.
 type xlsxRow struct {
-	R     int     `xml:"r,attr"`
-	Spans string  `xml:"spans,attr,omitempty"`
-	C     []xlsxC `xml:"c"`
+	R      int     `xml:"r,attr"`
+	Spans  string  `xml:"spans,attr,omitempty"`
+	Hidden bool    `xml:"hidden,attr,omitempty"`
+	C      []xlsxC `xml:"c"`
 }
 
 // xlsxC directly maps the c element in the namespace