Jelajahi Sumber

Copy in column definitions from XLSX files, expanding them into one definition
per row as we go. Also exclude definitions for columns outside the dimensions
of the spreadsheet.

Geoffrey J. Teale 11 tahun lalu
induk
melakukan
1580d57bdc
1 mengubah file dengan 13 tambahan dan 4 penghapusan
  1. 13 4
      lib.go

+ 13 - 4
lib.go

@@ -357,11 +357,20 @@ func readRowsFromSheet(Worksheet *xlsxWorksheet, file *File) ([]*Row, []*Col, in
 			Hidden: false,
 		}
 	}
+
+	// Columns can apply to a range, for convenience we expand the
+	// ranges out into individual column definitions.
 	for _, rawcol := range Worksheet.Cols.Col {
-		cols = append(cols, &Col{
-			Min:    rawcol.Min,
-			Max:    rawcol.Max,
-			Hidden: rawcol.Hidden})
+		// Note, below, that sometimes column definitions can
+		// exist outside the defined dimensions of the
+		// spreadsheet - we deliberately exclude these
+		// columns.
+		for i := rawcol.Min; i <= rawcol.Max && i <= colCount; i++ {
+			cols[i-1] = &Col{
+				Min:    rawcol.Min,
+				Max:    rawcol.Max,
+				Hidden: rawcol.Hidden}
+		}
 	}
 
 	for rowIndex := 0; rowIndex < len(Worksheet.SheetData.Row); rowIndex++ {