Insertrows returning row number exceeds maximum limit error
farzinghanbari opened this issue · comments
I opened an excel file with 6 rows and when I tried to insert a new row before row#4 I got an error saying "row number exceeds maximum limit error". Here is the piece of code that is not working:
f, err := excelize.OpenFile(path)
if err != nil {
log.Fatal(err)
}
defer func() {
if err := f.Close(); err != nil {
log.Fatal(err)
}
}()
sheetName := f.GetSheetName(0)
rows, err := f.GetRows(sheetName)
if err != nil {
log.Fatal(err)
}
fmt.Printf("total number of rows %d\n", len(rows))
for i := 10; i >= 0; i-- {
if err := f.InsertRows(sheetName, 4, 1); err != nil {
log.Fatal(err)
}
item := Items[i]
record := &[]interface{}{item.Hall, item.Code, item.GoodName, item.Producer, item.Packing, item.ProductionLocation, item.ContractType, item.Clearing, item.DeliveryDate, item.MinBuy, item.Price, item.Volume, item.Description}
f.SetSheetRow(sheetName, "A4", record)
}
I get the following output:
total number of rows 6
2024/07/20 22:22:22 row number exceeds maximum limit
Thanks for your issue. Which version of this library are you using? This issue maybe already fixed on master branch, please try to upgrade by go get -u github.com/xuri/excelize/v2@master
. If it still doesn't work, please let me know and provide workbook your opening without confidential info.
Thank you for getting back to me. Yes, I have the latest version, my excelize version is 2.8.1. The same problem happens when I am duplicating a row. I don't know what the problem might be.
Okay, I have created a new excel file from scratch and tried again and this time it worked. I still have no idea what the problem is with my old excel file. Do you have any idea what the problem might be?
Thank you very much.
As my reply above, please try to upgrade the master branch code at first, not v2.8.1 versions code.
Ok I upgraded to the master branch but still got the same error.
Thanks for your feedback. Could you show us a complete, standalone example program or reproducible demo? If you open an existing workbook, please provide the file attachment without confidential info.
I have the exact same problem with one workbook. I have attached the workbook I have the problem with. It is tested with latest master branch and this simple code:
testing.xlsx
package main
import (
"fmt"
"github.com/xuri/excelize/v2"
)
func main() {
f, err := excelize.OpenFile("testing.xlsx")
if err != nil {
fmt.Println(err)
return
}
err = f.DuplicateRowTo("Report", 9, 10)
if err != nil {
fmt.Println(err)
return
}
// Save spreadsheet by the given path.
if err := f.SaveAs("Book1.xlsx"); err != nil {
fmt.Println(err)
}
}
Hi @jebirch, thanks for your feedback, as the description of the DuplicateRowTo
function says, it inserts a copy of specified row by it Excel number to specified row position moving down exists rows after target position. The worksheet "Report" in your attachment workbook already reaches the maximum Excel rows 1048576 (excelize.TotalRows
), you can't insert any more rows in this worksheet, so this behavior is expected. But I'm not sure if the same situation for @farzinghanbari, there is still not enough information for this, I'll close this, if you have any questions, please let me know, and you can reopen this anytime.