-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When Edit excel file,show warning "发现“22.xlsx”中的部分内容有问题。是否让我们尽量尝试恢复? 如果您信任此工作簿的源,请单击“是”。" #1139
Comments
Thanks for your issue. Could you provide your input file attachment without confidential info? |
Please using |
SetCellValue works, thanks |
I have fixed it, please try upgrading to the master branch code, and this patch will be released in the next version. |
|
@zohu Thanks for your feedback. Can you show us a complete, standalone example program or reproducible demo? or give a try to upgrade to v2.6.1? |
it's fine after the upgrade. thank you. |
- Add default value on getting `View` property of sheet views - Add examples and unit test for set sheet views - Re-order field on sheet view options - Fix incorrect build-in number format: 42 - Simplify code for the `stylesReader` function
Hey,guys,I have the same problem.It can open by WPS,but Office doen't work. I upgrade to v2.6.1! I use the StreamWrieter for set values .Just Like
Go: 1.17 |
Is it possible that you forgot to call streamWriter.Flush() ? |
Thanks for your answer,and I Flush() it in the end after method setRows.It works in WPS! DONT WORK IN MAC & PC MicroSoft Excel! if err := streamWriter.Flush(); err != nil {
fmt.Println(err)
return "", err
} |
Hi @floki2020, thanks for your feedback. Can you show us a complete, standalone example program or reproducible demo? |
Could you provide a simple and executable reproducible code? There is no definition of the valid |
func BuilderExcel() (string, error) {
file := excelize.NewFile()
streamWriter, err := file.NewStreamWriter("Sheet1")
if err != nil {
fmt.Println(err)
return "", err
}
sHead, _ := file.NewStyle(&excelize.Style{Alignment: &excelize.Alignment{Horizontal: "Center"}, Font: &excelize.Font{Bold: true}})
sRow, err := file.NewStyle(&excelize.Style{Alignment: &excelize.Alignment{Horizontal: "Center"}})
if err != nil {
fmt.Println(err)
return "", err
}
rowTotal := "A9"
numStr := "8"
subStart := "A" + numStr
subEnd := "D" + numStr
subHead := "A" + numStr
err = streamWriter.MergeCell("A1", "D1")
if err != nil {
fmt.Print(err)
}
streamWriter.MergeCell(subStart, subEnd)
streamWriter.SetColWidth(1, 4, 20)
if err := streamWriter.SetRow("A1", []interface{}{
excelize.Cell{StyleID: sHead, Value: "123"}}); err != nil {
return "", err
}
if err := streamWriter.SetRow(subHead, []interface{}{
excelize.Cell{StyleID: sHead, Value: "综合统计"}}); err != nil {
return "", err
}
if err := streamWriter.SetRow("A2", []interface{}{
excelize.Cell{StyleID: sRow, Value: "所属矿场"}, excelize.Cell{StyleID: sRow, Value: "进口车次"}, excelize.Cell{StyleID: sRow, Value: "出口车次"}, excelize.Cell{StyleID: sRow, Value: "日期"}}); err != nil {
return "", err
}
if err := streamWriter.SetRow(rowTotal, []interface{}{
excelize.Cell{StyleID: sRow, Value: "所属"}, excelize.Cell{StyleID: sRow, Value: "进口车次"}, excelize.Cell{StyleID: sRow, Value: "出口车次"}, excelize.Cell{StyleID: sRow, Value: "日期"}}); err != nil {
return "", err
}
for rowID := 0; rowID < 4; rowID++ {
row := make([]interface{}, 2)
row[0] = rowID * 2
row[1] = rowID + 1
cell, _ := excelize.CoordinatesToCellName(1, rowID+3)
if err := streamWriter.SetRow(cell, row); err != nil {
fmt.Println(err)
return "", err
}
}
for i := 0; i < 6; i++ {
row := make([]interface{}, 2)
row[0] = i * 3
row[1] = i + 1
cell, _ := excelize.CoordinatesToCellName(1, i+6)
if err := streamWriter.SetRow(cell, row); err != nil {
fmt.Println(err)
return "", err
}
}
if err := streamWriter.Flush(); err != nil {
fmt.Println(err)
return "", err
}
file.NewSheet("Sheet2")
truckStm, err := file.NewStreamWriter("Sheet2")
if err != nil {
fmt.Println(err)
return "", err
}
truckStm.SetColWidth(1, 4, 20)
if err := truckStm.SetRow("A1", []interface{}{
excelize.Cell{StyleID: sRow, Value: "所属矿场"}, excelize.Cell{StyleID: sRow, Value: "车牌号"}, excelize.Cell{StyleID: sRow, Value: "位置"}, excelize.Cell{StyleID: sRow, Value: "日期"}}); err != nil {
fmt.Println(err)
return "", err
}
for idx := 0; idx < 5; idx++ {
row := make([]interface{}, 2)
row[0] = "123"
row[1] = idx * 2
cell, _ := excelize.CoordinatesToCellName(1, idx+2)
if err := truckStm.SetRow(cell, row); err != nil {
fmt.Println(err)
return "", err
}
}
if err := truckStm.Flush(); err != nil {
fmt.Println(err)
return "", err
}
path := "report/" + "test" + ".xlsx"
if err := file.SaveAs(path); err != nil {
fmt.Println(err)
return "", err
}
return path, nil
} |
I think maybe method MergeCell problem,when i remove it from the code,it works in excel |
As the documentation of the |
My oder line number is ascending. I don't think it's wrong :). Written according to the demo,i just use the funciton MergeCell |
The order of row numbers is not ascending in your code. The variable if err := streamWriter.SetRow("A2", []interface{}{
excelize.Cell{StyleID: sRow, Value: "所属矿场"}, excelize.Cell{StyleID: sRow, Value: "进口车次"}, excelize.Cell{StyleID: sRow, Value: "出口车次"}, excelize.Cell{StyleID: sRow, Value: "日期"}}); err != nil {
return "", err
}
if err := streamWriter.SetRow(subHead, []interface{}{
excelize.Cell{StyleID: sHead, Value: "综合统计"}}); err != nil {
return "", err
} instead of if err := streamWriter.SetRow(subHead, []interface{}{
excelize.Cell{StyleID: sHead, Value: "综合统计"}}); err != nil {
return "", err
}
if err := streamWriter.SetRow("A2", []interface{}{
excelize.Cell{StyleID: sRow, Value: "所属矿场"}, excelize.Cell{StyleID: sRow, Value: "进口车次"}, excelize.Cell{StyleID: sRow, Value: "出口车次"}, excelize.Cell{StyleID: sRow, Value: "日期"}}); err != nil {
return "", err
} Please also check the row number in the for loop statements. I'll consider checking the row number in the stream writer and returning the error to avoid this issue. |
I'm so sorry. I forget this scope.Maybe it can works~ Thanks again |
I have added a check of the row number in the stream writer and returned the error: |
…ply the result - An error will be returned when setting the stream row without ascending row numbers, to avoid potential mistakes as mentioned in qax-os#1139 - Updated unit tests
- Add default value on getting `View` property of sheet views - Add examples and unit test for set sheet views - Re-order field on sheet view options - Fix incorrect build-in number format: 42 - Simplify code for the `stylesReader` function
…ply the result - An error will be returned when setting the stream row without ascending row numbers, to avoid potential mistakes as mentioned in qax-os#1139 - Updated unit tests
Description
when edit the excel file with excelize , show the warning "发现“22.xlsx”中的部分内容有问题。是否让我们尽量尝试恢复? 如果您信任此工作簿的源,请单击“是"。"
Steps to reproduce the issue:
create a empty excel file,saved as "22.xlsx"
use code edit it .
f, _ := excelize.OpenFile("/Users/dev/Downloads/22.xlsx")
f.SetActiveSheet(0)
sheetName := f.GetSheetName(0)
fmt.Println(sheetName)
er := f.SetCellDefault(sheetName, "C4", "test")
fmt.Println(er)
f.Save()
open the 22.xlsx file
Describe the results you received:
Describe the results you expected:
Output of
go version
:Excelize version or commit ID:
Environment details (OS, Microsoft Excel™ version, physical, etc.):
macOS Big Sur 11.4
Go 1.16.4
excelize 2.4.1
Excel 16.29(19090802)
The text was updated successfully, but these errors were encountered: