stephen-hardy / xlsx.js

XLSX.js is a JavaScript library for converting the data in base64 XLSX files into JavaScript objects - and back! Please note that this library is licensed under the Microsoft Office Extensible File License - a license NOT approved by the OSI. While this license is based off of the MS-PL, which is OSI-approved, there are significant differences.
http://blog.innovatejs.com/?tag=xlsx-js
Other
575 stars 122 forks source link

Problem in parsing sharedStrings #24

Closed ghost closed 8 years ago

ghost commented 10 years ago

// xlsx.js, line #54: if (s = zip.file('xl/sharedStrings.xml')) { // Process sharedStrings s = s.asText().split(/<t.*?>/g); i = s.length; while(--i) { sharedStrings[i - 1] = unescapeXML(s[i].substring(0, s[i].indexOf('</t>'))); } // Do not process i === 0, because s[0] is the text before first t element }

an '<si>' element can have multiple '<t>' elements, so above code can cause (logical) parsing errors for particular files.

if (s = zip.file('xl/sharedStrings.xml')) { // Process sharedStrings s = s.asText().split(/<si.*?>/g); i = s.length; while(--i) { sharedStrings[i - 1] = unescapeXML(s[i].replace(/<\/?[^>]+(>|$)/g, '')); } // Do not process i === 0, because s[0] is the text before first t element }

in my case, i changed the code like above, then the issue had solved.

dwiltshire commented 10 years ago

Experienced the same issue, thanks for the fix!

grassick commented 8 years ago

Incorporated in 2.3.2