sharedStringsReader provides a function to get the pointer to the structure after deserialization of xl/sharedStrings.xml.
()
| 504 | // sharedStringsReader provides a function to get the pointer to the structure |
| 505 | // after deserialization of xl/sharedStrings.xml. |
| 506 | func (f *File) sharedStringsReader() (*xlsxSST, error) { |
| 507 | var err error |
| 508 | f.mu.Lock() |
| 509 | defer f.mu.Unlock() |
| 510 | relPath := f.getWorkbookRelsPath() |
| 511 | if f.SharedStrings == nil { |
| 512 | var sharedStrings xlsxSST |
| 513 | ss := f.readXML(defaultXMLPathSharedStrings) |
| 514 | if err = f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(ss))). |
| 515 | Decode(&sharedStrings); err != nil && err != io.EOF { |
| 516 | return f.SharedStrings, err |
| 517 | } |
| 518 | if sharedStrings.Count == 0 { |
| 519 | sharedStrings.Count = len(sharedStrings.SI) |
| 520 | } |
| 521 | if sharedStrings.UniqueCount == 0 { |
| 522 | sharedStrings.UniqueCount = sharedStrings.Count |
| 523 | } |
| 524 | f.SharedStrings = &sharedStrings |
| 525 | for i := range sharedStrings.SI { |
| 526 | if sharedStrings.SI[i].T != nil { |
| 527 | f.sharedStringsMap[sharedStrings.SI[i].T.Val] = i |
| 528 | } |
| 529 | } |
| 530 | if err = f.addContentTypePart(0, "sharedStrings"); err != nil { |
| 531 | return f.SharedStrings, err |
| 532 | } |
| 533 | rels, err := f.relsReader(relPath) |
| 534 | if err != nil { |
| 535 | return f.SharedStrings, err |
| 536 | } |
| 537 | for _, rel := range rels.Relationships { |
| 538 | if rel.Target == "/xl/sharedStrings.xml" { |
| 539 | return f.SharedStrings, nil |
| 540 | } |
| 541 | } |
| 542 | // Update workbook.xml.rels |
| 543 | f.addRels(relPath, SourceRelationshipSharedStrings, "/xl/sharedStrings.xml", "") |
| 544 | } |
| 545 | |
| 546 | return f.SharedStrings, nil |
| 547 | } |
| 548 | |
| 549 | // SetRowVisible provides a function to set visible of a single row by given |
| 550 | // worksheet name and Excel row number. For example, hide row 2 in Sheet1: |