Skip to content
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

Panic Read xlsx file when shardStrings.xml has repeat strings. #45

Closed
bronze1man opened this issue Sep 18, 2014 · 4 comments · Fixed by #46
Closed

Panic Read xlsx file when shardStrings.xml has repeat strings. #45

bronze1man opened this issue Sep 18, 2014 · 4 comments · Fixed by #46

Comments

@bronze1man
Copy link
Contributor

The excel file is coming from windows ms excel.

panic: runtime error: index out of range

goroutine 24 [running]:
runtime.panic(0x5185c0, 0x8612dc)
    /usr/local/Cellar/go/1.3/libexec/src/pkg/runtime/panic.c:279 +0xf5
github.com/tealeg/xlsx.getValueFromCellData(0xc20a941638, 0x4, 0xa, 0xc20a941658, 0x1, 0xc20a941680, 0x3, 0xc208dc5fc0, 0x0, 0x0)
    /Users/xxxx/src/github.com/tealeg/xlsx/lib.go:324 +0x1c0
github.com/tealeg/xlsx.readRowsFromSheet(0xc2088a2930, 0xc20875fcc0, 0x0, 0x0, 0x0, 0x4, 0xc208707860)
    /Users/xxxx/src/github.com/tealeg/xlsx/lib.go:387 +0x530
github.com/tealeg/xlsx.readSheetFromFile(0xc209d6b080, 0x0, 0xc209e562d0, 0x7, 0xc209e562e0, 0x1, 0xc209e562f0, 0x4, 0xc20875fcc0, 0xc2087079e0)
    /Users/xxxx/src/github.com/tealeg/xlsx/lib.go:421 +0x12f
created by github.com/tealeg/xlsx.readSheetsFromZipFile
    /Users/xxxx/src/github.com/tealeg/xlsx/lib.go:451 +0x3a1

Sorry,I can not public that excel file,and I do not have windows ms excel. Other excel software(mac numbers, windows wps) will not product that kind of xlsx file.

change this function it will pass this xlsx file,but will fail some other tests.
https://github.com/tealeg/xlsx/blob/master/sharedstrings.go#L91

func (rt *RefTable) AddString(str string) int {
    rt.indexedStrings = append(rt.indexedStrings, str)
    index, ok := rt.knownStrings[str]
    if ok {
        return index
    }
    index = len(rt.indexedStrings) - 1
    rt.knownStrings[str] = index
    return index
}
@tealeg
Copy link
Owner

tealeg commented Sep 18, 2014

Thanks bronze1man. I'll look into it ASAP.

@brentechols-wf
Copy link

Just some conjecture, but it may have to do with the handling of empty strings?

We just updated to the most recent version of master, and the cell count is lower than it was before in one of our test sheets. Additionally, some of our sheets now encounter this error as well. Hopefully this helps!

@KingJT
Copy link

KingJT commented Sep 18, 2014

Easy to reproduce (in windows and mac excel):

New Workbook, set A1 to the string abcdef and set A2 to the string abcdef. Then edit the cell A2, select the letters "def" and hit control-b to bold it.

Here is a sample:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="2" uniqueCount="2">
  <si>
    <t>abcdef</t>
  </si>
  <si>
    <r>
      <t>abc</t>
    </r>
    <r>
      <rPr>
        <b/>
        <sz val="12"/>
        <color theme="1"/>
        <rFont val="Calibri"/>
        <family val="2"/>
        <scheme val="minor"/>
      </rPr>
      <t>def</t>
    </r>
  </si>
</sst>

It must be thrown off by the fact that two strings have the same plaintext but different formatted text

@tealeg
Copy link
Owner

tealeg commented Sep 19, 2014

Thanks to both of you for you input. It's much appreciated and very helpful.

I'm aware of the round tripping issue - it's part of why I call the write functionality experimental ;-)

bronze1man added a commit to bronze1man/xlsx that referenced this issue Sep 22, 2014
tealeg added a commit that referenced this issue Sep 22, 2014
fix #45 add an isWrite option on RefTable.
tealeg pushed a commit that referenced this issue Apr 1, 2016
tealeg pushed a commit that referenced this issue Apr 1, 2016
fix #45 add an isWrite option on RefTable.
tealeg pushed a commit that referenced this issue Jan 14, 2020
tealeg added a commit that referenced this issue Jan 14, 2020
fix #45 add an isWrite option on RefTable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants