-
-
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
GetComment() returns incorrect mapping between worksheets and comments #345
Comments
Hi @tobiassoppa, thanks for your issue. I have fixed it. |
This appeared again in 2.1.0 |
Hi @xyz347, thanks for your feedback. I have tested and it works well. Could you provide file and code attachments without sensitive info? |
package main
import (
"fmt"
"github.com/360EntSecGroup-Skylar/excelize/v2"
)
func main() {
a, err := excelize.OpenFile("a.xlsx")
fmt.Printf("err=%v\ncomments=%+v\n", err, a.GetComments())
} output is (miss sheet a1) if use v2.0.0, output is ok: How to reproduce the bug: sometimes map miss some sheet |
I have fixed it. Please try to upgrade the library with the master branch code. |
It work, thx. |
Description
func (f *File) GetComments() (comments map[string][]Comment)
returns wrong mapping between worksheets and comments.This problem only occurs if a workbook contains multiple worksheets and at least one of them (except the last one) doesn't contain comments.
Example:
Assuming a workbook has 3 worksheets, there will be 3 files in
\xl\worksheets
.sheet1.xml
(sheet without comments),sheet2.xml
andsheet3.xml
.Since the first sheet doesn't contain any comments, there will only be two comment files in
\xl\
.comments1.xml
,comments2.xml
.Currently the relation between
sheet<number>.xml
andcomments<number>.xml
seems to be index based, according to Comment.go.Code snippet from link above:
commentID := f.GetSheetIndex(n)
commentsXML := "xl/comments" + strconv.Itoa(commentID) + ".xml"
Solution:
Matching
sheet<number>.xml
andcomments<number>.xml
based on a common index returns wrong matchings, if any worksheet (except the last one) has no comments.It seems that the proper relationship between worksheets and comments can be found in
\xl\worksheets\_rels
.This folder contains XML files for each worksheet that has any relationships. A plain worksheet will have no file in
\xl\worksheets\_rels
.According to the example I mentioned above,
sheet1.xml.rels
contains the linesNote that there is no reference to
\xl\comments1.xml
.sheet2.xml.rels
contains the linesNote that there is a reference to
\xl\comments1.xml
in lineTo avoid the issue, I would propose to match worksheets and comments based on their relationship in
\xl\worksheets\_rels
. Please note that a plain worksheet will not have a corresponding file in\xl\worksheets\_rels
. Thus it may happen that you will only seesheet2.xml.rels
andsheet3.xml.rels
, assuming that worksheet one is plain, but worksheet two and three contain comments.Steps to reproduce the issue:
GetComments()
Describe the results you received:
Output with some additional formatting:
Describe the results you expected:
Since the first sheet had no comments, but only sheet two and three, I would expect:
Output of
go version
:Excelize version or commit ID:
Environment details (OS, Microsoft Excel™ version, physical, etc.):
OSX Mojave 10.14.3
Microsoft Excel 2010
The text was updated successfully, but these errors were encountered: