コード例 #1
0
ファイル: cell.py プロジェクト: BatataWada1/NOP-commerce
 def check_string(self, value):
     """Check string coding, length, and line break character"""
     if value is None:
         return
     # convert to unicode string
     if not isinstance(value, unicode):
         value = unicode(value, self.encoding)
     value = unicode(value)
     # string must never be longer than 32,767 characters
     # truncate if necessary
     value = value[:32767]
     if next(ILLEGAL_CHARACTERS_RE.finditer(value), None):
         raise IllegalCharacterError
     return value
コード例 #2
0
ファイル: test_worksheet.py プロジェクト: sciris/openpyexcel
def test_get_xml_iter():
    #1 file object
    #2 stream (file-like)
    #3 string
    #4 zipfile
    from openpyexcel.reader.worksheet import _get_xml_iter
    from tempfile import TemporaryFile

    FUT = _get_xml_iter
    s = b""
    stream = FUT(s)
    assert isinstance(stream, BytesIO), type(stream)

    u = unicode(s)
    stream = FUT(u)
    assert isinstance(stream, BytesIO), type(stream)

    f = TemporaryFile(mode='rb+', prefix='openpyexcel.', suffix='.unpack.temp')
    stream = FUT(f)
    assert stream == f
    f.close()

    t = TemporaryFile()
    z = ZipFile(t, mode="w")
    z.writestr("test", "whatever")
    stream = FUT(z.open("test"))
    assert hasattr(stream, "read")

    try:
        z.close()
    except IOError:
        # you can't just close zipfiles in Windows
        z.close() # python 2.7
コード例 #3
0
def _add_table_headers(ws):
    """
    Check if tables have tableColumns and create them and autoFilter if necessary.
    Column headers will be taken from the first row of the table.
    """

    tables = TablePartList()

    for table in ws._tables:
        if not table.tableColumns:
            table._initialise_columns()
            if table.headerRowCount:
                row = ws[table.ref][0]
                for cell, col in zip(row, table.tableColumns):
                    if cell.data_type != "s":
                        warn(
                            "File may not be readable: column headings must be strings."
                        )
                    col.name = unicode(cell.value)
        rel = Relationship(Type=table._rel_type, Target="")
        ws._rels.append(rel)
        table._rel_id = rel.Id
        tables.append(Related(id=rel.Id))

    return tables
コード例 #4
0
 def value(self):
     if self._value is None:
         return
     if self.data_type == 'n':
         if self.style_array:
             if is_date_format(self.number_format):
                 return from_excel(self._value, self.base_date)
         return self._value
     if self.data_type == 'b':
         return self._value == '1'
     elif self.data_type in (Cell.TYPE_INLINE,
                             Cell.TYPE_FORMULA_CACHE_STRING):
         return unicode(self._value)
     elif self.data_type == 's':
         return unicode(self.shared_strings[int(self._value)])
     return self._value
コード例 #5
0
ファイル: reference.py プロジェクト: BatataWada1/NOP-commerce
 def __repr__(self):
     return unicode(self)
コード例 #6
0
ファイル: cell.py プロジェクト: BatataWada1/NOP-commerce
 def check_error(self, value):
     """Tries to convert Error" else N/A"""
     try:
         return unicode(value)
     except UnicodeDecodeError:
         return u'#N/A'
コード例 #7
0
ファイル: test_reference.py プロジェクト: sciris/openpyexcel
 def test_repr(self, Reference):
     ref = Reference(range_string=b"'D\xc3\xbcsseldorf'!A1:A10".decode("utf8"))
     assert unicode(ref) == b"'D\xc3\xbcsseldorf'!$A$1:$A$10".decode("utf8")
コード例 #8
0
 def test_unicode(self, _HeaderFooterPart):
     from openpyexcel.compat import unicode
     hf = _HeaderFooterPart()
     hf.text = u"D\xfcsseldorf"
     assert unicode(hf) == u"D\xfcsseldorf"
コード例 #9
0
 def test_unicode(self, HeaderFooterItem):
     from openpyexcel.compat import unicode
     hf = HeaderFooterItem()
     hf.left.text = u'D\xfcsseldorf'
     assert unicode(hf) == u'&LD\xfcsseldorf'