Skip to content

When the data exceeds 567 columns, the subsequent data reading is abnormal. #94

@AndsGo

Description

@AndsGo

When the data exceeds 567 columns, the subsequent data reading is abnormal.
image

The attached file is the test file.
202409301357(HBOGJ).xls

I don't know if it's a problem with my code or the file? I hope someone can answer this for me, thank you.

Below is my code:

package excelutil

import (
	"fmt"
	"os"
	"strings"

	"github.com/extrame/xls"
	"github.com/xuri/excelize/v2"
)
func ReadExcelAll4Xls(filepath string) (map[string][][]string, error) {
	fi, err := os.Open(filepath)
	if err != nil {
		return nil, err
	}
	xlFile, err := xls.OpenReader(fi, "utf-8")
	if err != nil {
		return nil, err
	}

	numSheets := xlFile.NumSheets()
	resMap := make(map[string][][]string, numSheets)
	for i := 0; i < numSheets; i++ {
		sheet := xlFile.GetSheet(0)
		sheetRows, err := getRows4Xls(sheet)
		if err != nil {
			return nil, err
		}
		resMap[sheet.Name] = sheetRows
	}
	fi.Close()
	xlFile = nil
	return resMap, nil
}

func getRows4Xls(sheet *xls.WorkSheet) ([][]string, error) {
	if sheet == nil {
		return nil, fmt.Errorf("sheet is nil")
	}
	sheetRows := make([][]string, 0)

	for rowIndex := 0; rowIndex <= int(sheet.MaxRow); rowIndex++ {
		row := sheet.Row(rowIndex)
		rowArr := make([]string, 0)
		if row != nil {
			for colIndex := 0; colIndex < row.LastCol(); colIndex++ {
				rowArr = append(rowArr, row.Col(colIndex))
			}
		}
		sheetRows = append(sheetRows, rowArr)
	}
	return sheetRows, nil
}

Test

package excelutil

import (
	"fmt"
	"testing"
)
func Test_read_xls(t *testing.T) {
	list, err := ReadExcelAll4Xls("D:/work/notes/demo/ows/doc/202409301336(HBOGJ).xls")
	fmt.Println(list, err)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions