|
@@ -26,7 +26,7 @@ func (e *XLSXReaderError) Error() string {
|
|
|
// Cell is a high level structure intended to provide user access to
|
|
// Cell is a high level structure intended to provide user access to
|
|
|
// the contents of Cell within an xlsx.Row.
|
|
// the contents of Cell within an xlsx.Row.
|
|
|
type Cell struct {
|
|
type Cell struct {
|
|
|
- data string
|
|
|
|
|
|
|
+ Value string
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// CellInterface defines the public API of the Cell.
|
|
// CellInterface defines the public API of the Cell.
|
|
@@ -35,7 +35,7 @@ type CellInterface interface {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (c *Cell) String() string {
|
|
func (c *Cell) String() string {
|
|
|
- return c.data
|
|
|
|
|
|
|
+ return c.Value
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Row is a high level structure indended to provide user access to a
|
|
// Row is a high level structure indended to provide user access to a
|
|
@@ -48,6 +48,8 @@ type Row struct {
|
|
|
// the contents of a particular sheet within an XLSX file.
|
|
// the contents of a particular sheet within an XLSX file.
|
|
|
type Sheet struct {
|
|
type Sheet struct {
|
|
|
Rows []*Row
|
|
Rows []*Row
|
|
|
|
|
+ MaxRow int
|
|
|
|
|
+ MaxCol int
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// File is a high level structure providing a slice of Sheet structs
|
|
// File is a high level structure providing a slice of Sheet structs
|
|
@@ -194,7 +196,7 @@ func makeRowFromSpan(spans string) *Row {
|
|
|
row.Cells = make([]*Cell, upper)
|
|
row.Cells = make([]*Cell, upper)
|
|
|
for i := 0; i < upper; i++ {
|
|
for i := 0; i < upper; i++ {
|
|
|
cell = new(Cell)
|
|
cell = new(Cell)
|
|
|
- cell.data = ""
|
|
|
|
|
|
|
+ cell.Value = ""
|
|
|
row.Cells[i] = cell
|
|
row.Cells[i] = cell
|
|
|
}
|
|
}
|
|
|
return row
|
|
return row
|
|
@@ -223,7 +225,7 @@ func makeRowFromRaw(rawrow xlsxRow) *Row {
|
|
|
row.Cells = make([]*Cell, upper)
|
|
row.Cells = make([]*Cell, upper)
|
|
|
for i := 0; i < upper; i++ {
|
|
for i := 0; i < upper; i++ {
|
|
|
cell = new(Cell)
|
|
cell = new(Cell)
|
|
|
- cell.data = ""
|
|
|
|
|
|
|
+ cell.Value = ""
|
|
|
row.Cells[i] = cell
|
|
row.Cells[i] = cell
|
|
|
}
|
|
}
|
|
|
return row
|
|
return row
|
|
@@ -252,11 +254,13 @@ func getValueFromCellData(rawcell xlsxC, reftable []string) string {
|
|
|
// readRowsFromSheet is an internal helper function that extracts the
|
|
// readRowsFromSheet is an internal helper function that extracts the
|
|
|
// rows from a XSLXWorksheet, poulates them with Cells and resolves
|
|
// rows from a XSLXWorksheet, poulates them with Cells and resolves
|
|
|
// the value references from the reference table and stores them in
|
|
// the value references from the reference table and stores them in
|
|
|
-func readRowsFromSheet(Worksheet *xlsxWorksheet, reftable []string) []*Row {
|
|
|
|
|
|
|
+func readRowsFromSheet(Worksheet *xlsxWorksheet, reftable []string) ([]*Row ,int) {
|
|
|
var rows []*Row
|
|
var rows []*Row
|
|
|
var row *Row
|
|
var row *Row
|
|
|
|
|
+ var maxCol int
|
|
|
|
|
|
|
|
rows = make([]*Row, len(Worksheet.SheetData.Row))
|
|
rows = make([]*Row, len(Worksheet.SheetData.Row))
|
|
|
|
|
+ maxCol = 0
|
|
|
for i, rawrow := range Worksheet.SheetData.Row {
|
|
for i, rawrow := range Worksheet.SheetData.Row {
|
|
|
// range is not empty
|
|
// range is not empty
|
|
|
if len(rawrow.Spans) != 0 {
|
|
if len(rawrow.Spans) != 0 {
|
|
@@ -269,11 +273,14 @@ func readRowsFromSheet(Worksheet *xlsxWorksheet, reftable []string) []*Row {
|
|
|
if error != nil {
|
|
if error != nil {
|
|
|
panic(fmt.Sprintf("Invalid Cell Coord, %s\n", rawcell.R))
|
|
panic(fmt.Sprintf("Invalid Cell Coord, %s\n", rawcell.R))
|
|
|
}
|
|
}
|
|
|
- row.Cells[x].data = getValueFromCellData(rawcell, reftable)
|
|
|
|
|
|
|
+ if x > maxCol {
|
|
|
|
|
+ maxCol = x
|
|
|
|
|
+ }
|
|
|
|
|
+ row.Cells[x].Value = getValueFromCellData(rawcell, reftable)
|
|
|
}
|
|
}
|
|
|
rows[i] = row
|
|
rows[i] = row
|
|
|
}
|
|
}
|
|
|
- return rows
|
|
|
|
|
|
|
+ return rows,maxCol
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// readSheetsFromZipFile is an internal helper function that loops
|
|
// readSheetsFromZipFile is an internal helper function that loops
|
|
@@ -302,8 +309,9 @@ func readSheetsFromZipFile(f *zip.File, file *File) ([]*Sheet, []string, error)
|
|
|
return nil, nil, error
|
|
return nil, nil, error
|
|
|
}
|
|
}
|
|
|
sheet := new(Sheet)
|
|
sheet := new(Sheet)
|
|
|
- sheet.Rows = readRowsFromSheet(worksheet, file.referenceTable)
|
|
|
|
|
|
|
+ sheet.Rows,sheet.MaxCol = readRowsFromSheet(worksheet, file.referenceTable)
|
|
|
sheets[i] = sheet
|
|
sheets[i] = sheet
|
|
|
|
|
+ sheet.MaxRow = len(sheet.Rows)
|
|
|
names[i] = rawsheet.Name
|
|
names[i] = rawsheet.Name
|
|
|
}
|
|
}
|
|
|
return sheets, names, nil
|
|
return sheets, names, nil
|