qax-os / excelize

Go language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets
https://xuri.me/excelize
BSD 3-Clause "New" or "Revised" License
18.05k stars 1.71k forks source link

Infinite loop of reading Rows #1848

Closed OleksandrMelnyk closed 6 months ago

OleksandrMelnyk commented 6 months ago

Description

Infinite loop of reading lines

Steps to reproduce the issue:

Use xlsx file list.xlsx generated

Version: 7.3.7.2 / LibreOffice Community Build ID: 30(Build:2) CPU threads: 20; OS: Linux 6.5; UI render: default; VCL: gtk3 Locale: en-US (en_US.UTF-8); UI: en-US Ubuntu package version: 1:7.3.7-0ubuntu0.22.04.4 Calc: threaded

Code: rows, err := file.Rows(sheet) if err != nil { return err } for rows.Next() { err = rows.Error() if err != nil { return err } fmt.Printf(" Rows %#v", rows) row, err := rows.Columns() if err != nil { return err } }

Describe the results you received: Infinite loop

"Rows &excelize.Rows{err:error(nil), curRow:1, seekRow:1, needClose:false, rawCellValue:false, sheet:\"xl/worksheets/sheet1.xml\", f:(excelize.File)(0xc00089fdc0), tempFile:(os.File)(nil), sst:(excelize.xlsxSST)(nil), decoder:(xml.Decoder)(0xc000ae8240), token:xml.StartElement{Name:xml.Name{Space:\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\", Local:\"row\"}, Attr:[]xml.Attr{xml.Attr{Name:xml.Name{Space:\"\", Local:\"r\"}, Value:\"1\"}, xml.Attr{Name:xml.Name{Space:\"\", Local:\"customFormat\"}, Value:\"false\"}, xml.Attr{Name:xml.Name{Space:\"\", Local:\"ht\"}, Value:\"15\"}, xml.Attr{Name:xml.Name{Space:\"\", Local:\"hidden\"}, Value:\"false\"}, xml.Attr{Name:xml.Name{Space:\"\", Local:\"customHeight\"}, Value:\"false\"}, xml.Attr{Name:xml.Name{Space:\"\", Local:\"outlineLevel\"}, Value:\"0\"}, xml.Attr{Name:xml.Name{Space:\"\", Local:\"collapsed\"}, Value:\"false\"}}}, curRowOpts:excelize.RowOpts{Height:15, Hidden:false, StyleID:0, OutlineLevel:0}, seekRowOpts:excelize.RowOpts{Height:0, Hidden:false, StyleID:0, OutlineLevel:0}}"

....

" Rows &excelize.Rows{err:error(nil), curRow:3, seekRow:3, needClose:false, rawCellValue:false, sheet:\"xl/worksheets/sheet1.xml\", f:(excelize.File)(0xc00089fdc0), tempFile:(os.File)(nil), sst:(excelize.xlsxSST)(0xc00092ce60), decoder:(xml.Decoder)(0xc000ae8240), token:xml.Token(nil), curRowOpts:excelize.RowOpts{Height:15, Hidden:false, StyleID:0, OutlineLevel:0}, seekRowOpts:excelize.RowOpts{Height:15, Hidden:false, StyleID:0, OutlineLevel:0}}" " Rows &excelize.Rows{err:error(nil), curRow:1047110, seekRow:4, needClose:false, rawCellValue:false, sheet:\"xl/worksheets/sheet1.xml\", f:(excelize.File)(0xc00089fdc0), tempFile:(os.File)(nil), sst:(excelize.xlsxSST)(0xc00092ce60), decoder:(xml.Decoder)(0xc000ae8240), token:xml.Token(nil), curRowOpts:excelize.RowOpts{Height:12.8, Hidden:false, StyleID:0, OutlineLevel:0}, seekRowOpts:excelize.RowOpts{Height:12.8, Hidden:false, StyleID:0, OutlineLevel:0}}"

Infinite repeat last Row

Describe the results you expected: Function rows.Error() should return error

Output of go version:

go version go1.22.0 linux/amd64

Excelize version or commit ID:

github.com/xuri/excelize/v2 v2.8.1

Environment details (OS, Microsoft Excel™ version, physical, etc.): OS: 22.04.1-Ubuntu

LibreOffice : Version: 7.3.7.2 / LibreOffice Community Build ID: 30(Build:2)

xuri commented 6 months ago

Thanks for your issue. There are 1048576 rows in the worksheet "Manufacturer Mapping" in your attachment workbook, even though the cells after the 3rd row seem blank, as the documentation of the Excelize library says, only the continually blank cells in the tail of each row will be skipped, so these cells can not be skipped, you can also confirm this by open the workbook by Excel application, the length of the vertical scroll bar in your workbook. In addition, the print statement will cost more time in iterate progress, so the loop is not infinite, if you remove the print statement, the loop will be finished quickly, so that's expected, I've closed this issue. If you have any questions, please let me know, and you can reopen this anytime.