strings.py 604 B

123456789101112131415161718192021222324
  1. from __future__ import absolute_import
  2. # Copyright (c) 2010-2019 openpyxl
  3. from openpyxl.cell.text import Text
  4. from openpyxl.xml.functions import iterparse
  5. from openpyxl.xml.constants import SHEET_MAIN_NS
  6. def read_string_table(xml_source):
  7. """Read in all shared strings in the table"""
  8. strings = []
  9. STRING_TAG = '{%s}si' % SHEET_MAIN_NS
  10. for _, node in iterparse(xml_source):
  11. if node.tag == STRING_TAG:
  12. text = Text.from_tree(node).content
  13. text = text.replace('x005F_', '')
  14. node.clear()
  15. strings.append(text)
  16. return strings