modify struct name
This commit is contained in:
+20
-20
@@ -10,27 +10,27 @@ import (
|
||||
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
||||
)
|
||||
|
||||
// ExcelFileImportedDataTable defines the structure of excel file data table
|
||||
type ExcelFileImportedDataTable struct {
|
||||
// ExcelMSCFBFileImportedDataTable defines the structure of excel (microsoft compound file binary) file data table
|
||||
type ExcelMSCFBFileImportedDataTable struct {
|
||||
workbook *xls.WorkBook
|
||||
headerLineColumnNames []string
|
||||
}
|
||||
|
||||
// ExcelFileDataRow defines the structure of excel file data table row
|
||||
type ExcelFileDataRow struct {
|
||||
// ExcelMSCFBFileDataRow defines the structure of excel (microsoft compound file binary) file data table row
|
||||
type ExcelMSCFBFileDataRow struct {
|
||||
sheet *xls.WorkSheet
|
||||
rowIndex int
|
||||
}
|
||||
|
||||
// ExcelFileDataRowIterator defines the structure of excel file data table row iterator
|
||||
type ExcelFileDataRowIterator struct {
|
||||
dataTable *ExcelFileImportedDataTable
|
||||
// ExcelMSCFBFileDataRowIterator defines the structure of excel (microsoft compound file binary) file data table row iterator
|
||||
type ExcelMSCFBFileDataRowIterator struct {
|
||||
dataTable *ExcelMSCFBFileImportedDataTable
|
||||
currentSheetIndex int
|
||||
currentRowIndexInSheet uint16
|
||||
}
|
||||
|
||||
// DataRowCount returns the total count of data row
|
||||
func (t *ExcelFileImportedDataTable) DataRowCount() int {
|
||||
func (t *ExcelMSCFBFileImportedDataTable) DataRowCount() int {
|
||||
totalDataRowCount := 0
|
||||
|
||||
for i := 0; i < t.workbook.NumSheets(); i++ {
|
||||
@@ -47,13 +47,13 @@ func (t *ExcelFileImportedDataTable) DataRowCount() int {
|
||||
}
|
||||
|
||||
// HeaderColumnNames returns the header column name list
|
||||
func (t *ExcelFileImportedDataTable) HeaderColumnNames() []string {
|
||||
func (t *ExcelMSCFBFileImportedDataTable) HeaderColumnNames() []string {
|
||||
return t.headerLineColumnNames
|
||||
}
|
||||
|
||||
// DataRowIterator returns the iterator of data row
|
||||
func (t *ExcelFileImportedDataTable) DataRowIterator() datatable.ImportedDataRowIterator {
|
||||
return &ExcelFileDataRowIterator{
|
||||
func (t *ExcelMSCFBFileImportedDataTable) DataRowIterator() datatable.ImportedDataRowIterator {
|
||||
return &ExcelMSCFBFileDataRowIterator{
|
||||
dataTable: t,
|
||||
currentSheetIndex: 0,
|
||||
currentRowIndexInSheet: 0,
|
||||
@@ -61,19 +61,19 @@ func (t *ExcelFileImportedDataTable) DataRowIterator() datatable.ImportedDataRow
|
||||
}
|
||||
|
||||
// ColumnCount returns the total count of column in this data row
|
||||
func (r *ExcelFileDataRow) ColumnCount() int {
|
||||
func (r *ExcelMSCFBFileDataRow) ColumnCount() int {
|
||||
row := r.sheet.Row(r.rowIndex)
|
||||
return row.LastCol() + 1
|
||||
}
|
||||
|
||||
// GetData returns the data in the specified column index
|
||||
func (r *ExcelFileDataRow) GetData(columnIndex int) string {
|
||||
func (r *ExcelMSCFBFileDataRow) GetData(columnIndex int) string {
|
||||
row := r.sheet.Row(r.rowIndex)
|
||||
return row.Col(columnIndex)
|
||||
}
|
||||
|
||||
// HasNext returns whether the iterator does not reach the end
|
||||
func (t *ExcelFileDataRowIterator) HasNext() bool {
|
||||
func (t *ExcelMSCFBFileDataRowIterator) HasNext() bool {
|
||||
workbook := t.dataTable.workbook
|
||||
|
||||
if t.currentSheetIndex >= workbook.NumSheets() {
|
||||
@@ -100,12 +100,12 @@ func (t *ExcelFileDataRowIterator) HasNext() bool {
|
||||
}
|
||||
|
||||
// CurrentRowId returns current index
|
||||
func (t *ExcelFileDataRowIterator) CurrentRowId() string {
|
||||
func (t *ExcelMSCFBFileDataRowIterator) CurrentRowId() string {
|
||||
return fmt.Sprintf("table#%d-row#%d", t.currentSheetIndex, t.currentRowIndexInSheet)
|
||||
}
|
||||
|
||||
// Next returns the next imported data row
|
||||
func (t *ExcelFileDataRowIterator) Next() datatable.ImportedDataRow {
|
||||
func (t *ExcelMSCFBFileDataRowIterator) Next() datatable.ImportedDataRow {
|
||||
workbook := t.dataTable.workbook
|
||||
currentRowIndexInTable := t.currentRowIndexInSheet
|
||||
|
||||
@@ -133,14 +133,14 @@ func (t *ExcelFileDataRowIterator) Next() datatable.ImportedDataRow {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &ExcelFileDataRow{
|
||||
return &ExcelMSCFBFileDataRow{
|
||||
sheet: currentSheet,
|
||||
rowIndex: int(t.currentRowIndexInSheet),
|
||||
}
|
||||
}
|
||||
|
||||
// CreateNewExcelFileImportedDataTable returns excel xls data table by file binary data
|
||||
func CreateNewExcelFileImportedDataTable(data []byte) (*ExcelFileImportedDataTable, error) {
|
||||
// CreateNewExcelMSCFBFileImportedDataTable returns excel (microsoft compound file binary) data table by file binary data
|
||||
func CreateNewExcelMSCFBFileImportedDataTable(data []byte) (*ExcelMSCFBFileImportedDataTable, error) {
|
||||
reader := bytes.NewReader(data)
|
||||
workbook, err := xls.OpenReader(reader, "")
|
||||
|
||||
@@ -184,7 +184,7 @@ func CreateNewExcelFileImportedDataTable(data []byte) (*ExcelFileImportedDataTab
|
||||
}
|
||||
}
|
||||
|
||||
return &ExcelFileImportedDataTable{
|
||||
return &ExcelMSCFBFileImportedDataTable{
|
||||
workbook: workbook,
|
||||
headerLineColumnNames: headerRowItems,
|
||||
}, nil
|
||||
+30
-30
@@ -9,63 +9,63 @@ import (
|
||||
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
||||
)
|
||||
|
||||
func TestExcelFileImportedDataTableDataRowCount(t *testing.T) {
|
||||
func TestExcelMSCFBFileImportedDataTableDataRowCount(t *testing.T) {
|
||||
testdata, err := os.ReadFile("../../../testdata/simple_excel_file.xls")
|
||||
assert.Nil(t, err)
|
||||
|
||||
datatable, err := CreateNewExcelFileImportedDataTable(testdata)
|
||||
datatable, err := CreateNewExcelMSCFBFileImportedDataTable(testdata)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 2, datatable.DataRowCount())
|
||||
}
|
||||
|
||||
func TestExcelFileImportedDataTableDataRowCount_MultipleSheets(t *testing.T) {
|
||||
func TestExcelMSCFBFileImportedDataTableDataRowCount_MultipleSheets(t *testing.T) {
|
||||
testdata, err := os.ReadFile("../../../testdata/multiple_sheets_excel_file.xls")
|
||||
assert.Nil(t, err)
|
||||
|
||||
datatable, err := CreateNewExcelFileImportedDataTable(testdata)
|
||||
datatable, err := CreateNewExcelMSCFBFileImportedDataTable(testdata)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 5, datatable.DataRowCount())
|
||||
}
|
||||
|
||||
func TestExcelFileImportedDataTableDataRowCount_OnlyHeaderLine(t *testing.T) {
|
||||
func TestExcelMSCFBFileImportedDataTableDataRowCount_OnlyHeaderLine(t *testing.T) {
|
||||
testdata, err := os.ReadFile("../../../testdata/only_one_row_excel_file.xls")
|
||||
assert.Nil(t, err)
|
||||
|
||||
datatable, err := CreateNewExcelFileImportedDataTable(testdata)
|
||||
datatable, err := CreateNewExcelMSCFBFileImportedDataTable(testdata)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 0, datatable.DataRowCount())
|
||||
}
|
||||
|
||||
func TestExcelFileImportedDataTableDataRowCount_EmptyContent(t *testing.T) {
|
||||
func TestExcelMSCFBFileImportedDataTableDataRowCount_EmptyContent(t *testing.T) {
|
||||
testdata, err := os.ReadFile("../../../testdata/empty_excel_file.xls")
|
||||
assert.Nil(t, err)
|
||||
|
||||
datatable, err := CreateNewExcelFileImportedDataTable(testdata)
|
||||
datatable, err := CreateNewExcelMSCFBFileImportedDataTable(testdata)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 0, datatable.DataRowCount())
|
||||
}
|
||||
|
||||
func TestExcelFileImportedDataTableHeaderColumnNames(t *testing.T) {
|
||||
func TestExcelMSCFBFileImportedDataTableHeaderColumnNames(t *testing.T) {
|
||||
testdata, err := os.ReadFile("../../../testdata/simple_excel_file.xls")
|
||||
assert.Nil(t, err)
|
||||
|
||||
datatable, err := CreateNewExcelFileImportedDataTable(testdata)
|
||||
datatable, err := CreateNewExcelMSCFBFileImportedDataTable(testdata)
|
||||
assert.EqualValues(t, []string{"A1", "B1", "C1"}, datatable.HeaderColumnNames())
|
||||
}
|
||||
|
||||
func TestExcelFileImportedDataTableHeaderColumnNames_EmptyContent(t *testing.T) {
|
||||
func TestExcelMSCFBFileImportedDataTableHeaderColumnNames_EmptyContent(t *testing.T) {
|
||||
testdata, err := os.ReadFile("../../../testdata/empty_excel_file.xls")
|
||||
assert.Nil(t, err)
|
||||
|
||||
datatable, err := CreateNewExcelFileImportedDataTable(testdata)
|
||||
datatable, err := CreateNewExcelMSCFBFileImportedDataTable(testdata)
|
||||
assert.Nil(t, datatable.HeaderColumnNames())
|
||||
}
|
||||
|
||||
func TestExcelFileDataRowIterator(t *testing.T) {
|
||||
func TestExcelMSCFBFileDataRowIterator(t *testing.T) {
|
||||
testdata, err := os.ReadFile("../../../testdata/simple_excel_file.xls")
|
||||
assert.Nil(t, err)
|
||||
|
||||
datatable, err := CreateNewExcelFileImportedDataTable(testdata)
|
||||
datatable, err := CreateNewExcelMSCFBFileImportedDataTable(testdata)
|
||||
iterator := datatable.DataRowIterator()
|
||||
assert.True(t, iterator.HasNext())
|
||||
|
||||
@@ -86,11 +86,11 @@ func TestExcelFileDataRowIterator(t *testing.T) {
|
||||
assert.False(t, iterator.HasNext())
|
||||
}
|
||||
|
||||
func TestExcelFileDataRowIterator_MultipleSheets(t *testing.T) {
|
||||
func TestExcelMSCFBFileDataRowIterator_MultipleSheets(t *testing.T) {
|
||||
testdata, err := os.ReadFile("../../../testdata/multiple_sheets_excel_file.xls")
|
||||
assert.Nil(t, err)
|
||||
|
||||
datatable, err := CreateNewExcelFileImportedDataTable(testdata)
|
||||
datatable, err := CreateNewExcelMSCFBFileImportedDataTable(testdata)
|
||||
iterator := datatable.DataRowIterator()
|
||||
assert.True(t, iterator.HasNext())
|
||||
|
||||
@@ -123,11 +123,11 @@ func TestExcelFileDataRowIterator_MultipleSheets(t *testing.T) {
|
||||
assert.False(t, iterator.HasNext())
|
||||
}
|
||||
|
||||
func TestExcelFileDataRowIterator_OnlyHeaderLine(t *testing.T) {
|
||||
func TestExcelMSCFBFileDataRowIterator_OnlyHeaderLine(t *testing.T) {
|
||||
testdata, err := os.ReadFile("../../../testdata/only_one_row_excel_file.xls")
|
||||
assert.Nil(t, err)
|
||||
|
||||
datatable, err := CreateNewExcelFileImportedDataTable(testdata)
|
||||
datatable, err := CreateNewExcelMSCFBFileImportedDataTable(testdata)
|
||||
iterator := datatable.DataRowIterator()
|
||||
assert.False(t, iterator.HasNext())
|
||||
|
||||
@@ -140,11 +140,11 @@ func TestExcelFileDataRowIterator_OnlyHeaderLine(t *testing.T) {
|
||||
assert.False(t, iterator.HasNext())
|
||||
}
|
||||
|
||||
func TestExcelFileDataRowIterator_EmptyContent(t *testing.T) {
|
||||
func TestExcelMSCFBFileDataRowIterator_EmptyContent(t *testing.T) {
|
||||
testdata, err := os.ReadFile("../../../testdata/empty_excel_file.xls")
|
||||
assert.Nil(t, err)
|
||||
|
||||
datatable, err := CreateNewExcelFileImportedDataTable(testdata)
|
||||
datatable, err := CreateNewExcelMSCFBFileImportedDataTable(testdata)
|
||||
iterator := datatable.DataRowIterator()
|
||||
assert.False(t, iterator.HasNext())
|
||||
|
||||
@@ -157,11 +157,11 @@ func TestExcelFileDataRowIterator_EmptyContent(t *testing.T) {
|
||||
assert.False(t, iterator.HasNext())
|
||||
}
|
||||
|
||||
func TestExcelFileDataRowColumnCount(t *testing.T) {
|
||||
func TestExcelMSCFBFileDataRowColumnCount(t *testing.T) {
|
||||
testdata, err := os.ReadFile("../../../testdata/simple_excel_file.xls")
|
||||
assert.Nil(t, err)
|
||||
|
||||
datatable, err := CreateNewExcelFileImportedDataTable(testdata)
|
||||
datatable, err := CreateNewExcelMSCFBFileImportedDataTable(testdata)
|
||||
iterator := datatable.DataRowIterator()
|
||||
|
||||
row1 := iterator.Next()
|
||||
@@ -171,11 +171,11 @@ func TestExcelFileDataRowColumnCount(t *testing.T) {
|
||||
assert.EqualValues(t, 4, row2.ColumnCount())
|
||||
}
|
||||
|
||||
func TestExcelFileDataRowGetData(t *testing.T) {
|
||||
func TestExcelMSCFBFileDataRowGetData(t *testing.T) {
|
||||
testdata, err := os.ReadFile("../../../testdata/simple_excel_file.xls")
|
||||
assert.Nil(t, err)
|
||||
|
||||
datatable, err := CreateNewExcelFileImportedDataTable(testdata)
|
||||
datatable, err := CreateNewExcelMSCFBFileImportedDataTable(testdata)
|
||||
iterator := datatable.DataRowIterator()
|
||||
|
||||
row1 := iterator.Next()
|
||||
@@ -189,22 +189,22 @@ func TestExcelFileDataRowGetData(t *testing.T) {
|
||||
assert.Equal(t, "C3", row2.GetData(2))
|
||||
}
|
||||
|
||||
func TestExcelFileDataRowGetData_GetNotExistedColumnData(t *testing.T) {
|
||||
func TestExcelMSCFBFileDataRowGetData_GetNotExistedColumnData(t *testing.T) {
|
||||
testdata, err := os.ReadFile("../../../testdata/simple_excel_file.xls")
|
||||
assert.Nil(t, err)
|
||||
|
||||
datatable, err := CreateNewExcelFileImportedDataTable(testdata)
|
||||
datatable, err := CreateNewExcelMSCFBFileImportedDataTable(testdata)
|
||||
iterator := datatable.DataRowIterator()
|
||||
|
||||
row1 := iterator.Next()
|
||||
assert.Equal(t, "", row1.GetData(3))
|
||||
}
|
||||
|
||||
func TestExcelFileDataRowGetData_MultipleSheets(t *testing.T) {
|
||||
func TestExcelMSCFBFileDataRowGetData_MultipleSheets(t *testing.T) {
|
||||
testdata, err := os.ReadFile("../../../testdata/multiple_sheets_excel_file.xls")
|
||||
assert.Nil(t, err)
|
||||
|
||||
datatable, err := CreateNewExcelFileImportedDataTable(testdata)
|
||||
datatable, err := CreateNewExcelMSCFBFileImportedDataTable(testdata)
|
||||
iterator := datatable.DataRowIterator()
|
||||
|
||||
sheet1Row1 := iterator.Next()
|
||||
@@ -237,10 +237,10 @@ func TestExcelFileDataRowGetData_MultipleSheets(t *testing.T) {
|
||||
assert.Equal(t, "5-C3", sheet5Row2.GetData(2))
|
||||
}
|
||||
|
||||
func TestCreateNewExcelFileImportedDataTable_MultipleSheetsWithDifferentHeaders(t *testing.T) {
|
||||
func TestCreateNewExcelMSCFBFileImportedDataTable_MultipleSheetsWithDifferentHeaders(t *testing.T) {
|
||||
testdata, err := os.ReadFile("../../../testdata/multiple_sheets_with_different_header_row_excel_file.xls")
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, err = CreateNewExcelFileImportedDataTable(testdata)
|
||||
_, err = CreateNewExcelMSCFBFileImportedDataTable(testdata)
|
||||
assert.EqualError(t, err, errs.ErrFieldsInMultiTableAreDifferent.Message)
|
||||
}
|
||||
@@ -30,7 +30,7 @@ var (
|
||||
|
||||
// ParseImportedData returns the imported data by parsing the feidee mymoney (web) transaction xls data
|
||||
func (c *feideeMymoneyWebTransactionDataXlsFileImporter) ParseImportedData(ctx core.Context, user *models.User, data []byte, defaultTimezoneOffset int16, accountMap map[string]*models.Account, expenseCategoryMap map[string]*models.TransactionCategory, incomeCategoryMap map[string]*models.TransactionCategory, transferCategoryMap map[string]*models.TransactionCategory, tagMap map[string]*models.TransactionTag) (models.ImportedTransactionSlice, []*models.Account, []*models.TransactionCategory, []*models.TransactionCategory, []*models.TransactionCategory, []*models.TransactionTag, error) {
|
||||
dataTable, err := excel.CreateNewExcelFileImportedDataTable(data)
|
||||
dataTable, err := excel.CreateNewExcelMSCFBFileImportedDataTable(data)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, nil, nil, err
|
||||
|
||||
Reference in New Issue
Block a user