mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-21 02:04:26 +08:00
fix incorrect column count when importing mscfb excel file
This commit is contained in:
@@ -86,7 +86,7 @@ func (t *ExcelMSCFBFileBasicDataTable) DataRowIterator() datatable.BasicDataTabl
|
|||||||
// ColumnCount returns the total count of column in this data row
|
// ColumnCount returns the total count of column in this data row
|
||||||
func (r *ExcelMSCFBFileBasicDataTableRow) ColumnCount() int {
|
func (r *ExcelMSCFBFileBasicDataTableRow) ColumnCount() int {
|
||||||
row := r.sheet.Row(r.rowIndex)
|
row := r.sheet.Row(r.rowIndex)
|
||||||
return row.LastCol() + 1
|
return row.LastCol()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetData returns the data in the specified column index
|
// GetData returns the data in the specified column index
|
||||||
@@ -195,7 +195,10 @@ func CreateNewExcelMSCFBFileBasicDataTable(data []byte, hasTitleLine bool) (data
|
|||||||
}
|
}
|
||||||
|
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
for j := 0; j <= row.LastCol(); j++ {
|
// row.LastCol() returns "colMac" in the "Row" struct, that is an unsigned integer that specifies the one-based index of the last column.
|
||||||
|
// But row.FirstCol() returns "colMic" in the "Row" struct, that is an unsigned integer that specifies the zero-based index of the first column.
|
||||||
|
// Reference: https://learn.microsoft.com/en-us/openspecs/office_file_formats/ms-xls/4aab09eb-49ed-4d01-a3b1-1d726247d3c2
|
||||||
|
for j := 0; j < row.LastCol(); j++ {
|
||||||
headerItem := row.Col(j)
|
headerItem := row.Col(j)
|
||||||
|
|
||||||
if headerItem == "" {
|
if headerItem == "" {
|
||||||
@@ -205,7 +208,7 @@ func CreateNewExcelMSCFBFileBasicDataTable(data []byte, hasTitleLine bool) (data
|
|||||||
firstRowItems = append(firstRowItems, headerItem)
|
firstRowItems = append(firstRowItems, headerItem)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for j := 0; j <= min(row.LastCol(), len(firstRowItems)-1); j++ {
|
for j := 0; j < min(row.LastCol(), len(firstRowItems)); j++ {
|
||||||
headerItem := row.Col(j)
|
headerItem := row.Col(j)
|
||||||
|
|
||||||
if headerItem != firstRowItems[j] {
|
if headerItem != firstRowItems[j] {
|
||||||
|
|||||||
@@ -300,10 +300,10 @@ func TestExcelMSCFBFileBasicDataRowColumnCount(t *testing.T) {
|
|||||||
iterator := datatable.DataRowIterator()
|
iterator := datatable.DataRowIterator()
|
||||||
|
|
||||||
row1 := iterator.Next()
|
row1 := iterator.Next()
|
||||||
assert.EqualValues(t, 4, row1.ColumnCount())
|
assert.EqualValues(t, 3, row1.ColumnCount())
|
||||||
|
|
||||||
row2 := iterator.Next()
|
row2 := iterator.Next()
|
||||||
assert.EqualValues(t, 4, row2.ColumnCount())
|
assert.EqualValues(t, 3, row2.ColumnCount())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExcelMSCFBFileBasicDataRowGetData(t *testing.T) {
|
func TestExcelMSCFBFileBasicDataRowGetData(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user