Browse Source

Use min max ranges for columns

Andrew Schwartz 11 years ago
parent
commit
7de83dea2b
2 changed files with 9 additions and 5 deletions
  1. 5 3
      lib.go
  2. 4 2
      worksheet.go

+ 5 - 3
lib.go

@@ -356,12 +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))
+	cols = make([]*Col, colCount)
 	insertRowIndex = minRow
 	for colIndex := 0; colIndex < len(Worksheet.Cols.Col); colIndex++ {
 		rawcol := Worksheet.Cols.Col[colIndex]
-		cols[colIndex] = &Col{
-			Hidden: rawcol.Hidden,
+		for c := rawcol.Min - 1; c < colCount && c < rawcol.Max; c++ {
+			cols[c] = &Col{
+				Hidden: rawcol.Hidden,
+			}
 		}
 	}
 	for rowIndex := 0; rowIndex < len(Worksheet.SheetData.Row); rowIndex++ {

+ 4 - 2
worksheet.go

@@ -11,15 +11,17 @@ import (
 type xlsxWorksheet struct {
 	XMLName   xml.Name      `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main worksheet"`
 	Dimension xlsxDimension `xml:"dimension"`
-	Cols      xslxCols      `xml:"cols,omitempty"`
+	Cols      xslxCols      `xml:"cols"`
 	SheetData xlsxSheetData `xml:"sheetData"`
 }
 
 type xslxCols struct {
-	Col []xlsxCol `xml:"col,omitempty"`
+	Col []xlsxCol `xml:"col"`
 }
 
 type xlsxCol struct {
+	Min    int  `xml:"min,attr"`
+	Max    int  `xml:"max,attr"`
 	Hidden bool `xml:"hidden,attr,omitempty"`
 }