Skip to content

Instantly share code, notes, and snippets.

@rattrayalex
Last active August 29, 2015 14:06
Show Gist options
  • Save rattrayalex/51c06ee99d2848d4c250 to your computer and use it in GitHub Desktop.
Save rattrayalex/51c06ee99d2848d4c250 to your computer and use it in GitHub Desktop.
--- ./tablib/packages/openpyxl/__init__.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/__init__.py 2011-05-13 17:04:34.000000000 +0800
@@ -26,14 +26,14 @@
"""Imports for the openpyxl package."""
# package imports
-from . import cell
-from . import namedrange
-from . import style
-from . import workbook
-from . import worksheet
-from . import reader
-from . import shared
-from . import writer
+from openpyxl import cell
+from openpyxl import namedrange
+from openpyxl import style
+from openpyxl import workbook
+from openpyxl import worksheet
+from openpyxl import reader
+from openpyxl import shared
+from openpyxl import writer
# constants
Only in ./tablib/packages/openpyxl: __init__.pyc
-bur ./tablib/packages/openpyxl/cell.py /Users/alex/Downloads/openpyxl/cell.py
--- ./tablib/packages/openpyxl/cell.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/cell.py 2011-05-13 17:04:34.000000000 +0800
@@ -38,10 +38,10 @@
import re
# package imports
-from .shared.date_time import SharedDate
-from .shared.exc import CellCoordinatesException, \
+from openpyxl.shared.date_time import SharedDate
+from openpyxl.shared.exc import CellCoordinatesException, \
ColumnStringIndexException, DataTypeException
-from .style import NumberFormat
+from openpyxl.style import NumberFormat
# constants
COORD_RE = re.compile('^[$]?([A-Z]+)[$]?(\d+)$')
@@ -177,7 +177,7 @@
self.xf_index = 0
def __repr__(self):
- return "<Cell %s.%s>" % (self.parent.title, self.get_coordinate())
+ return u"<Cell %s.%s>" % (self.parent.title, self.get_coordinate())
def check_string(self, value):
"""Check string coding, length, and line break character"""
Only in ./tablib/packages/openpyxl: cell.pyc
-bur ./tablib/packages/openpyxl/chart.py /Users/alex/Downloads/openpyxl/chart.py
--- ./tablib/packages/openpyxl/chart.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/chart.py 2011-05-13 17:04:34.000000000 +0800
@@ -25,10 +25,10 @@
import math
-from .style import NumberFormat
-from .drawing import Drawing, Shape
-from .shared.units import pixels_to_EMU, short_color
-from .cell import get_column_letter
+from openpyxl.style import NumberFormat
+from openpyxl.drawing import Drawing, Shape
+from openpyxl.shared.units import pixels_to_EMU, short_color
+from openpyxl.cell import get_column_letter
class Axis(object):
@@ -47,6 +47,7 @@
self.min = 0
self.max = None
self.unit = None
+ self.title = ''
@classmethod
def default_category(cls):
Only in ./tablib/packages/openpyxl: chart.pyc
-bur ./tablib/packages/openpyxl/drawing.py /Users/alex/Downloads/openpyxl/drawing.py
--- ./tablib/packages/openpyxl/drawing.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/drawing.py 2011-05-13 17:04:34.000000000 +0800
@@ -24,8 +24,8 @@
'''
import math
-from .style import Color
-from .shared.units import pixels_to_EMU, EMU_to_pixels, short_color
+from openpyxl.style import Color
+from openpyxl.shared.units import pixels_to_EMU, EMU_to_pixels, short_color
class Shadow(object):
@@ -360,7 +360,7 @@
def _set_border_width(self, w):
self._border_width = pixels_to_EMU(w)
- # print self._border_width
+ print self._border_width
border_width = property(_get_border_width, _set_border_width)
@@ -399,3 +399,4 @@
return (_norm_pct(x_start), _norm_pct(y_start),
_norm_pct(x_end), _norm_pct(y_end))
+
\ No newline at end of file
Only in ./tablib/packages/openpyxl: drawing.pyc
-bur ./tablib/packages/openpyxl/namedrange.py /Users/alex/Downloads/openpyxl/namedrange.py
--- ./tablib/packages/openpyxl/namedrange.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/namedrange.py 2011-05-13 17:04:34.000000000 +0800
@@ -29,7 +29,7 @@
import re
# package imports
-from .shared.exc import NamedRangeException
+from openpyxl.shared.exc import NamedRangeException
# constants
NAMED_RANGE_RE = re.compile("'?([^']*)'?!((\$([A-Za-z]+))?\$([0-9]+)(:(\$([A-Za-z]+))?(\$([0-9]+)))?)$")
@@ -44,7 +44,7 @@
self.local_only = False
def __str__(self):
- return ','.join(['%s!%s' % (sheet, name) for sheet, name in self.destinations])
+ return ','.join([u'%s!%s' % (sheet, name) for sheet, name in self.destinations])
def __repr__(self):
Only in ./tablib/packages/openpyxl: namedrange.pyc
-bur ./tablib/packages/openpyxl/reader/__init__.py /Users/alex/Downloads/openpyxl/reader/__init__.py
--- ./tablib/packages/openpyxl/reader/__init__.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/reader/__init__.py 2011-05-13 17:04:34.000000000 +0800
@@ -26,8 +26,8 @@
"""Imports for the openpyxl.reader namespace."""
# package imports
-from ..reader import excel
-from ..reader import strings
-from ..reader import style
-from ..reader import workbook
-from ..reader import worksheet
+from openpyxl.reader import excel
+from openpyxl.reader import strings
+from openpyxl.reader import style
+from openpyxl.reader import workbook
+from openpyxl.reader import worksheet
Only in ./tablib/packages/openpyxl/reader: __init__.pyc
-bur ./tablib/packages/openpyxl/reader/excel.py /Users/alex/Downloads/openpyxl/reader/excel.py
--- ./tablib/packages/openpyxl/reader/excel.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/reader/excel.py 2011-05-13 17:04:34.000000000 +0800
@@ -29,16 +29,16 @@
from zipfile import ZipFile, ZIP_DEFLATED, BadZipfile
# package imports
-from ..shared.exc import OpenModeError, InvalidFileException
-from ..shared.ooxml import ARC_SHARED_STRINGS, ARC_CORE, ARC_APP, \
+from openpyxl.shared.exc import OpenModeError, InvalidFileException
+from openpyxl.shared.ooxml import ARC_SHARED_STRINGS, ARC_CORE, ARC_APP, \
ARC_WORKBOOK, PACKAGE_WORKSHEETS, ARC_STYLE
-from ..workbook import Workbook
-from ..reader.strings import read_string_table
-from ..reader.style import read_style_table
-from ..reader.workbook import read_sheets_titles, read_named_ranges, \
+from openpyxl.workbook import Workbook
+from openpyxl.reader.strings import read_string_table
+from openpyxl.reader.style import read_style_table
+from openpyxl.reader.workbook import read_sheets_titles, read_named_ranges, \
read_properties_core, get_sheet_ids
-from ..reader.worksheet import read_worksheet
-from ..reader.iter_worksheet import unpack_worksheet
+from openpyxl.reader.worksheet import read_worksheet
+from openpyxl.reader.iter_worksheet import unpack_worksheet
def load_workbook(filename, use_iterators = False):
"""Open the given filename and return the workbook
@@ -66,8 +66,8 @@
try:
archive = ZipFile(filename, 'r', ZIP_DEFLATED)
- except (BadZipfile, RuntimeError, IOError, ValueError):
- raise InvalidFileException()
+ except (BadZipfile, RuntimeError, IOError, ValueError), e:
+ raise InvalidFileException(unicode(e))
wb = Workbook()
if use_iterators:
@@ -75,14 +75,18 @@
try:
_load_workbook(wb, archive, filename, use_iterators)
- except KeyError:
- raise InvalidFileException()
+ except KeyError, e:
+ raise InvalidFileException(unicode(e))
+ except Exception, e:
+ raise e
finally:
archive.close()
return wb
def _load_workbook(wb, archive, filename, use_iterators):
+ valid_files = archive.namelist()
+
# get workbook-level information
wb.properties = read_properties_core(archive.read(ARC_CORE))
try:
@@ -95,9 +99,13 @@
wb.worksheets = [] # remove preset worksheet
sheet_names = read_sheets_titles(archive.read(ARC_APP))
for i, sheet_name in enumerate(sheet_names):
+
sheet_codename = 'sheet%d.xml' % (i + 1)
worksheet_path = '%s/%s' % (PACKAGE_WORKSHEETS, sheet_codename)
+ if not worksheet_path in valid_files:
+ continue
+
if not use_iterators:
new_ws = read_worksheet(archive.read(worksheet_path), wb, sheet_name, string_table, style_table)
else:
Only in ./tablib/packages/openpyxl/reader: excel.pyc
-bur ./tablib/packages/openpyxl/reader/iter_worksheet.py /Users/alex/Downloads/openpyxl/reader/iter_worksheet.py
--- ./tablib/packages/openpyxl/reader/iter_worksheet.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/reader/iter_worksheet.py 2011-05-13 17:04:34.000000000 +0800
@@ -27,28 +27,23 @@
*Still very raw*
"""
-from ....compat import BytesIO as StringIO
+from StringIO import StringIO
import warnings
import operator
from functools import partial
-from itertools import groupby, ifilter
-from ..worksheet import Worksheet
-from ..cell import coordinate_from_string, get_column_letter, Cell
-from ..reader.excel import get_sheet_ids
-from ..reader.strings import read_string_table
-from ..reader.style import read_style_table, NumberFormat
-from ..shared.date_time import SharedDate
-from ..reader.worksheet import read_dimension
-from ..shared.ooxml import (MIN_COLUMN, MAX_COLUMN, PACKAGE_WORKSHEETS,
+from itertools import ifilter, groupby
+from openpyxl.worksheet import Worksheet
+from openpyxl.cell import coordinate_from_string, get_column_letter, Cell
+from openpyxl.reader.excel import get_sheet_ids
+from openpyxl.reader.strings import read_string_table
+from openpyxl.reader.style import read_style_table, NumberFormat
+from openpyxl.shared.date_time import SharedDate
+from openpyxl.reader.worksheet import read_dimension
+from openpyxl.shared.ooxml import (MIN_COLUMN, MAX_COLUMN, PACKAGE_WORKSHEETS,
MAX_ROW, MIN_ROW, ARC_SHARED_STRINGS, ARC_APP, ARC_STYLE)
-try:
- from xml.etree.cElementTree import iterparse
-except ImportError:
- from xml.etree.ElementTree import iterparse
-
-
+from xml.etree.cElementTree import iterparse
from zipfile import ZipFile
-from .. import cell
+import openpyxl.cell
import re
import tempfile
import zlib
@@ -75,7 +70,7 @@
BaseRawCell = namedtuple('RawCell', RAW_ATTRIBUTES)
except ImportError:
- # warnings.warn("""Unable to import 'namedtuple' module, this may cause memory issues when using optimized reader. Please upgrade your Python installation to 2.6+""")
+ warnings.warn("""Unable to import 'namedtuple' module, this may cause memory issues when using optimized reader. Please upgrade your Python installation to 2.6+""")
class BaseRawCell(object):
Only in ./tablib/packages/openpyxl/reader: iter_worksheet.pyc
-bur ./tablib/packages/openpyxl/reader/strings.py /Users/alex/Downloads/openpyxl/reader/strings.py
--- ./tablib/packages/openpyxl/reader/strings.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/reader/strings.py 2011-05-13 17:04:34.000000000 +0800
@@ -26,8 +26,8 @@
"""Read the shared strings table."""
# package imports
-from ..shared.xmltools import fromstring, QName
-from ..shared.ooxml import NAMESPACES
+from openpyxl.shared.xmltools import fromstring, QName
+from openpyxl.shared.ooxml import NAMESPACES
def read_string_table(xml_source):
Only in ./tablib/packages/openpyxl/reader: strings.pyc
-bur ./tablib/packages/openpyxl/reader/style.py /Users/alex/Downloads/openpyxl/reader/style.py
--- ./tablib/packages/openpyxl/reader/style.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/reader/style.py 2011-05-13 17:04:34.000000000 +0800
@@ -26,9 +26,9 @@
"""Read shared style definitions"""
# package imports
-from ..shared.xmltools import fromstring, QName
-from ..shared.exc import MissingNumberFormat
-from ..style import Style, NumberFormat
+from openpyxl.shared.xmltools import fromstring, QName
+from openpyxl.shared.exc import MissingNumberFormat
+from openpyxl.style import Style, NumberFormat
def read_style_table(xml_source):
Only in ./tablib/packages/openpyxl/reader: style.pyc
-bur ./tablib/packages/openpyxl/reader/workbook.py /Users/alex/Downloads/openpyxl/reader/workbook.py
--- ./tablib/packages/openpyxl/reader/workbook.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/reader/workbook.py 2011-05-13 17:04:34.000000000 +0800
@@ -26,11 +26,11 @@
"""Read in global settings to be maintained by the workbook object."""
# package imports
-from ..shared.xmltools import fromstring, QName
-from ..shared.ooxml import NAMESPACES
-from ..workbook import DocumentProperties
-from ..shared.date_time import W3CDTF_to_datetime
-from ..namedrange import NamedRange, split_named_range
+from openpyxl.shared.xmltools import fromstring, QName
+from openpyxl.shared.ooxml import NAMESPACES
+from openpyxl.workbook import DocumentProperties
+from openpyxl.shared.date_time import W3CDTF_to_datetime
+from openpyxl.namedrange import NamedRange, split_named_range
import datetime
Only in ./tablib/packages/openpyxl/reader: workbook.pyc
-bur ./tablib/packages/openpyxl/reader/worksheet.py /Users/alex/Downloads/openpyxl/reader/worksheet.py
--- ./tablib/packages/openpyxl/reader/worksheet.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/reader/worksheet.py 2011-05-13 17:04:34.000000000 +0800
@@ -30,13 +30,12 @@
from xml.etree.cElementTree import iterparse
except ImportError:
from xml.etree.ElementTree import iterparse
-
-from ....compat import ifilter
-from ....compat import BytesIO as StringIO
+from itertools import ifilter
+from StringIO import StringIO
# package imports
-from ..cell import Cell, coordinate_from_string
-from ..worksheet import Worksheet
+from openpyxl.cell import Cell, coordinate_from_string
+from openpyxl.worksheet import Worksheet
def _get_xml_iter(xml_source):
@@ -57,7 +56,11 @@
if element.tag == '{http://schemas.openxmlformats.org/spreadsheetml/2006/main}dimension':
ref = element.get('ref')
+ if ':' in ref:
min_range, max_range = ref.split(':')
+ else:
+ min_range = max_range = ref
+
min_col, min_row = coordinate_from_string(min_range)
max_col, max_row = coordinate_from_string(max_range)
@@ -68,8 +71,7 @@
return None
-def filter_cells(x):
- (event, element) = x
+def filter_cells((event, element)):
return element.tag == '{http://schemas.openxmlformats.org/spreadsheetml/2006/main}c'
@@ -100,7 +102,7 @@
# to avoid memory exhaustion, clear the item after use
element.clear()
-from ..reader.iter_worksheet import IterableWorksheet
+from openpyxl.reader.iter_worksheet import IterableWorksheet
def read_worksheet(xml_source, parent, preset_title, string_table,
style_table, workbook_name = None, sheet_codename = None):
Only in ./tablib/packages/openpyxl/reader: worksheet.pyc
-bur ./tablib/packages/openpyxl/shared/__init__.py /Users/alex/Downloads/openpyxl/shared/__init__.py
--- ./tablib/packages/openpyxl/shared/__init__.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/shared/__init__.py 2011-05-13 17:04:34.000000000 +0800
@@ -26,8 +26,8 @@
"""Imports for the openpyxl.shared namespace."""
# package imports
-from . import date_time
-from . import exc
-from . import ooxml
-from . import password_hasher
-from . import xmltools
+from openpyxl.shared import date_time
+from openpyxl.shared import exc
+from openpyxl.shared import ooxml
+from openpyxl.shared import password_hasher
+from openpyxl.shared import xmltools
Only in ./tablib/packages/openpyxl/shared: __init__.pyc
Only in ./tablib/packages/openpyxl/shared: date_time.pyc
Only in ./tablib/packages/openpyxl/shared: exc.pyc
Only in ./tablib/packages/openpyxl/shared: ooxml.pyc
Only in ./tablib/packages/openpyxl/shared: password_hasher.pyc
Only in ./tablib/packages/openpyxl/shared: units.pyc
-bur ./tablib/packages/openpyxl/shared/xmltools.py /Users/alex/Downloads/openpyxl/shared/xmltools.py
--- ./tablib/packages/openpyxl/shared/xmltools.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/shared/xmltools.py 2011-05-13 17:04:34.000000000 +0800
@@ -41,7 +41,7 @@
QName, fromstring, tostring
# package imports
-from .. import __name__ as prefix
+from openpyxl import __name__ as prefix
def get_document_content(xml_node):
@@ -71,30 +71,12 @@
"""Wrapper to start an xml tag."""
if attr is None:
attr = {}
-
-
- # name = bytes(name, 'utf-8')
-
- # if namespace is not None:
- # namespace = bytes(namespace, 'utf-8')
-
-
attr_vals = {}
attr_keys = {}
- for key, val in attr.items():
-
-
- # if key is not None:
- # key = bytes(key, 'utf-8')
-
- # if val is not None:
- # val = bytes(val, 'utf-8')
-
+ for key, val in attr.iteritems():
key_tuple = (namespace, key)
-
attr_vals[key_tuple] = val
attr_keys[key_tuple] = key
-
attr2 = AttributesNSImpl(attr_vals, attr_keys)
doc.startElementNS((namespace, name), name, attr2)
if body:
Only in ./tablib/packages/openpyxl/shared: xmltools.pyc
-bur ./tablib/packages/openpyxl/style.py /Users/alex/Downloads/openpyxl/style.py
--- ./tablib/packages/openpyxl/style.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/style.py 2011-05-13 17:04:34.000000000 +0800
@@ -307,7 +307,7 @@
48: '##0.0E+0',
49: '@', }
_BUILTIN_FORMATS_REVERSE = dict(
- [(value, key) for key, value in _BUILTIN_FORMATS.items()])
+ [(value, key) for key, value in _BUILTIN_FORMATS.iteritems()])
__fields__ = ('_format_code',
'_format_index')
Only in ./tablib/packages/openpyxl: style.pyc
Only in /Users/alex/Downloads/openpyxl: tests
-bur ./tablib/packages/openpyxl/workbook.py /Users/alex/Downloads/openpyxl/workbook.py
--- ./tablib/packages/openpyxl/workbook.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/workbook.py 2011-05-13 17:04:34.000000000 +0800
@@ -32,13 +32,13 @@
import os
# package imports
-from .worksheet import Worksheet
-from .writer.dump_worksheet import DumpWorksheet, save_dump
-from .writer.strings import StringTableBuilder
-from .namedrange import NamedRange
-from .style import Style
-from .writer.excel import save_workbook
-from .shared.exc import ReadOnlyWorkbookException
+from openpyxl.worksheet import Worksheet
+from openpyxl.writer.dump_worksheet import DumpWorksheet, save_dump
+from openpyxl.writer.strings import StringTableBuilder
+from openpyxl.namedrange import NamedRange
+from openpyxl.style import Style
+from openpyxl.writer.excel import save_workbook
+from openpyxl.shared.exc import ReadOnlyWorkbookException
class DocumentProperties(object):
Only in ./tablib/packages/openpyxl: workbook.pyc
-bur ./tablib/packages/openpyxl/worksheet.py /Users/alex/Downloads/openpyxl/worksheet.py
--- ./tablib/packages/openpyxl/worksheet.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/worksheet.py 2011-05-13 17:04:34.000000000 +0800
@@ -29,15 +29,15 @@
import re
# package imports
-from . import cell
-from .cell import coordinate_from_string, \
+import openpyxl.cell
+from openpyxl.cell import coordinate_from_string, \
column_index_from_string, get_column_letter
-from .shared.exc import SheetTitleException, \
+from openpyxl.shared.exc import SheetTitleException, \
InsufficientCoordinatesException, CellCoordinatesException, \
NamedRangeException
-from .shared.password_hasher import hash_password
-from .style import Style, DEFAULTS as DEFAULTS_STYLE
-from .drawing import Drawing
+from openpyxl.shared.password_hasher import hash_password
+from openpyxl.style import Style, DEFAULTS as DEFAULTS_STYLE
+from openpyxl.drawing import Drawing
_DEFAULTS_STYLE_HASH = hash(DEFAULTS_STYLE)
@@ -229,12 +229,12 @@
self._freeze_panes = None
def __repr__(self):
- return '<Worksheet "%s">' % self.title
+ return u'<Worksheet "%s">' % self.title
def garbage_collect(self):
"""Delete cells that are not storing a value."""
delete_list = [coordinate for coordinate, cell in \
- self._cells.items() if (cell.value in ('', None) and \
+ self._cells.iteritems() if (cell.value in ('', None) and \
hash(cell.style) == _DEFAULTS_STYLE_HASH)]
for coordinate in delete_list:
del self._cells[coordinate]
@@ -344,7 +344,7 @@
if not coordinate in self._cells:
column, row = coordinate_from_string(coordinate)
- new_cell = cell.Cell(self, column, row)
+ new_cell = openpyxl.cell.Cell(self, column, row)
self._cells[coordinate] = new_cell
if column not in self.column_dimensions:
self.column_dimensions[column] = ColumnDimension(column)
@@ -502,7 +502,7 @@
elif isinstance(list_or_dict, dict):
- for col_idx, content in list_or_dict.items():
+ for col_idx, content in list_or_dict.iteritems():
if isinstance(col_idx, basestring):
col_idx = column_index_from_string(col_idx) - 1
Only in ./tablib/packages/openpyxl: worksheet.pyc
-bur ./tablib/packages/openpyxl/writer/__init__.py /Users/alex/Downloads/openpyxl/writer/__init__.py
--- ./tablib/packages/openpyxl/writer/__init__.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/writer/__init__.py 2011-05-13 17:04:34.000000000 +0800
@@ -26,9 +26,9 @@
"""Imports for the openpyxl.writer namespace."""
# package imports
-from . import excel
-from . import strings
-from . import styles
-from . import theme
-from . import workbook
-from . import worksheet
+from openpyxl.writer import excel
+from openpyxl.writer import strings
+from openpyxl.writer import styles
+from openpyxl.writer import theme
+from openpyxl.writer import workbook
+from openpyxl.writer import worksheet
Only in ./tablib/packages/openpyxl/writer: __init__.pyc
-bur ./tablib/packages/openpyxl/writer/charts.py /Users/alex/Downloads/openpyxl/writer/charts.py
--- ./tablib/packages/openpyxl/writer/charts.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/writer/charts.py 2011-05-13 17:04:34.000000000 +0800
@@ -24,8 +24,8 @@
@author: Eric Gazoni
'''
-from ..shared.xmltools import Element, SubElement, get_document_content
-from ..chart import Chart, ErrorBar
+from openpyxl.shared.xmltools import Element, SubElement, get_document_content
+from openpyxl.chart import Chart, ErrorBar
class ChartWriter(object):
@@ -122,6 +122,19 @@
if label == 'c:valAx':
SubElement(ax, 'c:majorGridlines')
SubElement(ax, 'c:numFmt', {'formatCode':"General", 'sourceLinked':'1'})
+ if axis.title != '':
+ title = SubElement(ax, 'c:title')
+ tx = SubElement(title, 'c:tx')
+ rich = SubElement(tx, 'c:rich')
+ SubElement(rich, 'a:bodyPr')
+ SubElement(rich, 'a:lstStyle')
+ p = SubElement(rich, 'a:p')
+ pPr = SubElement(p, 'a:pPr')
+ SubElement(pPr, 'a:defRPr')
+ r = SubElement(p, 'a:r')
+ SubElement(r, 'a:rPr', {'lang':self.chart.lang})
+ t = SubElement(r, 'a:t').text = axis.title
+ SubElement(title, 'c:layout')
SubElement(ax, 'c:tickLblPos', {'val':axis.tick_label_position})
SubElement(ax, 'c:crossAx', {'val':str(axis.cross)})
SubElement(ax, 'c:crosses', {'val':axis.crosses})
@@ -242,7 +255,7 @@
settings = SubElement(root, 'c:printSettings')
SubElement(settings, 'c:headerFooter')
- margins = dict([(k, str(v)) for (k,v) in self.chart.print_margins.items()])
+ margins = dict([(k, str(v)) for (k,v) in self.chart.print_margins.iteritems()])
SubElement(settings, 'c:pageMargins', margins)
SubElement(settings, 'c:pageSetup')
Only in ./tablib/packages/openpyxl/writer: charts.pyc
-bur ./tablib/packages/openpyxl/writer/drawings.py /Users/alex/Downloads/openpyxl/writer/drawings.py
--- ./tablib/packages/openpyxl/writer/drawings.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/writer/drawings.py 2011-05-13 17:04:34.000000000 +0800
@@ -24,7 +24,7 @@
@author: Eric Gazoni
'''
-from ..shared.xmltools import Element, SubElement, get_document_content
+from openpyxl.shared.xmltools import Element, SubElement, get_document_content
class DrawingWriter(object):
Only in ./tablib/packages/openpyxl/writer: drawings.pyc
-bur ./tablib/packages/openpyxl/writer/dump_worksheet.py /Users/alex/Downloads/openpyxl/writer/dump_worksheet.py
--- ./tablib/packages/openpyxl/writer/dump_worksheet.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/writer/dump_worksheet.py 2011-05-13 17:04:34.000000000 +0800
@@ -28,19 +28,19 @@
import datetime
import os
-from ..cell import column_index_from_string, get_column_letter, Cell
-from ..worksheet import Worksheet
-from ..shared.xmltools import XMLGenerator, get_document_content, \
+from openpyxl.cell import column_index_from_string, get_column_letter, Cell
+from openpyxl.worksheet import Worksheet
+from openpyxl.shared.xmltools import XMLGenerator, get_document_content, \
start_tag, end_tag, tag
-from ..shared.date_time import SharedDate
-from ..shared.ooxml import MAX_COLUMN, MAX_ROW
+from openpyxl.shared.date_time import SharedDate
+from openpyxl.shared.ooxml import MAX_COLUMN, MAX_ROW
from tempfile import NamedTemporaryFile
-from ..writer.excel import ExcelWriter
-from ..writer.strings import write_string_table
-from ..writer.styles import StyleWriter
-from ..style import Style, NumberFormat
+from openpyxl.writer.excel import ExcelWriter
+from openpyxl.writer.strings import write_string_table
+from openpyxl.writer.styles import StyleWriter
+from openpyxl.style import Style, NumberFormat
-from ..shared.ooxml import ARC_SHARED_STRINGS, ARC_CONTENT_TYPES, \
+from openpyxl.shared.ooxml import ARC_SHARED_STRINGS, ARC_CONTENT_TYPES, \
ARC_ROOT_RELS, ARC_WORKBOOK_RELS, ARC_APP, ARC_CORE, ARC_THEME, \
ARC_STYLE, ARC_WORKBOOK, \
PACKAGE_WORKSHEETS, PACKAGE_DRAWINGS, PACKAGE_CHARTS
Only in ./tablib/packages/openpyxl/writer: dump_worksheet.pyc
-bur ./tablib/packages/openpyxl/writer/excel.py /Users/alex/Downloads/openpyxl/writer/excel.py
--- ./tablib/packages/openpyxl/writer/excel.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/writer/excel.py 2011-05-13 17:04:34.000000000 +0800
@@ -27,22 +27,22 @@
# Python stdlib imports
from zipfile import ZipFile, ZIP_DEFLATED
-from ....compat import BytesIO as StringIO
+from StringIO import StringIO
# package imports
-from ..shared.ooxml import ARC_SHARED_STRINGS, ARC_CONTENT_TYPES, \
+from openpyxl.shared.ooxml import ARC_SHARED_STRINGS, ARC_CONTENT_TYPES, \
ARC_ROOT_RELS, ARC_WORKBOOK_RELS, ARC_APP, ARC_CORE, ARC_THEME, \
ARC_STYLE, ARC_WORKBOOK, \
PACKAGE_WORKSHEETS, PACKAGE_DRAWINGS, PACKAGE_CHARTS
-from ..writer.strings import create_string_table, write_string_table
-from ..writer.workbook import write_content_types, write_root_rels, \
+from openpyxl.writer.strings import create_string_table, write_string_table
+from openpyxl.writer.workbook import write_content_types, write_root_rels, \
write_workbook_rels, write_properties_app, write_properties_core, \
write_workbook
-from ..writer.theme import write_theme
-from ..writer.styles import StyleWriter
-from ..writer.drawings import DrawingWriter, ShapeWriter
-from ..writer.charts import ChartWriter
-from ..writer.worksheet import write_worksheet, write_worksheet_rels
+from openpyxl.writer.theme import write_theme
+from openpyxl.writer.styles import StyleWriter
+from openpyxl.writer.drawings import DrawingWriter, ShapeWriter
+from openpyxl.writer.charts import ChartWriter
+from openpyxl.writer.worksheet import write_worksheet, write_worksheet_rels
class ExcelWriter(object):
@@ -74,14 +74,9 @@
for ws in self.workbook.worksheets:
ws.garbage_collect()
shared_string_table = create_string_table(self.workbook)
-
-
archive.writestr(ARC_SHARED_STRINGS,
write_string_table(shared_string_table))
- for k, v in shared_string_table.items():
- shared_string_table[k] = bytes(v)
-
return shared_string_table
def _write_worksheets(self, archive, shared_string_table, style_writer):
Only in ./tablib/packages/openpyxl/writer: excel.pyc
-bur ./tablib/packages/openpyxl/writer/strings.py /Users/alex/Downloads/openpyxl/writer/strings.py
--- ./tablib/packages/openpyxl/writer/strings.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/writer/strings.py 2011-05-13 17:04:34.000000000 +0800
@@ -26,10 +26,10 @@
"""Write the shared string table."""
# Python stdlib imports
-from ....compat import BytesIO as StringIO
+from StringIO import StringIO
# package imports
-from ..shared.xmltools import start_tag, end_tag, tag, XMLGenerator
+from openpyxl.shared.xmltools import start_tag, end_tag, tag, XMLGenerator
def create_string_table(workbook):
@@ -49,7 +49,7 @@
start_tag(doc, 'sst', {'xmlns':
'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
'uniqueCount': '%d' % len(string_table)})
- strings_to_write = sorted(string_table.items(),
+ strings_to_write = sorted(string_table.iteritems(),
key=lambda pair: pair[1])
for key in [pair[0] for pair in strings_to_write]:
start_tag(doc, 'si')
Only in ./tablib/packages/openpyxl/writer: strings.pyc
-bur ./tablib/packages/openpyxl/writer/styles.py /Users/alex/Downloads/openpyxl/writer/styles.py
--- ./tablib/packages/openpyxl/writer/styles.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/writer/styles.py 2011-05-13 17:04:34.000000000 +0800
@@ -26,9 +26,9 @@
"""Write the shared style table."""
# package imports
-from ..shared.xmltools import Element, SubElement
-from ..shared.xmltools import get_document_content
-from .. import style
+from openpyxl.shared.xmltools import Element, SubElement
+from openpyxl.shared.xmltools import get_document_content
+from openpyxl import style
class StyleWriter(object):
@@ -44,13 +44,13 @@
crc[hash(style)] = style
self.style_table = dict([(style, i+1) \
for i, style in enumerate(crc.values())])
- sorted_styles = sorted(self.style_table.items(), \
+ sorted_styles = sorted(self.style_table.iteritems(), \
key = lambda pair:pair[1])
return [s[0] for s in sorted_styles]
def get_style_by_hash(self):
return dict([(hash(style), id) \
- for style, id in self.style_table.items()])
+ for style, id in self.style_table.iteritems()])
def write_table(self):
number_format_table = self._write_number_formats()
Only in ./tablib/packages/openpyxl/writer: styles.pyc
-bur ./tablib/packages/openpyxl/writer/theme.py /Users/alex/Downloads/openpyxl/writer/theme.py
--- ./tablib/packages/openpyxl/writer/theme.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/writer/theme.py 2011-05-13 17:04:34.000000000 +0800
@@ -27,7 +27,7 @@
"""Write the theme xml based on a fixed string."""
# package imports
-from ..shared.xmltools import fromstring, get_document_content
+from openpyxl.shared.xmltools import fromstring, get_document_content
def write_theme():
Only in ./tablib/packages/openpyxl/writer: theme.pyc
-bur ./tablib/packages/openpyxl/writer/workbook.py /Users/alex/Downloads/openpyxl/writer/workbook.py
--- ./tablib/packages/openpyxl/writer/workbook.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/writer/workbook.py 2011-05-13 17:04:34.000000000 +0800
@@ -26,12 +26,12 @@
"""Write the workbook global settings to the archive."""
# package imports
-from ..shared.xmltools import Element, SubElement
-from ..cell import absolute_coordinate
-from ..shared.xmltools import get_document_content
-from ..shared.ooxml import NAMESPACES, ARC_CORE, ARC_WORKBOOK, \
+from openpyxl.shared.xmltools import Element, SubElement
+from openpyxl.cell import absolute_coordinate
+from openpyxl.shared.xmltools import get_document_content
+from openpyxl.shared.ooxml import NAMESPACES, ARC_CORE, ARC_WORKBOOK, \
ARC_APP, ARC_THEME, ARC_STYLE, ARC_SHARED_STRINGS
-from ..shared.date_time import datetime_to_W3CDTF
+from openpyxl.shared.date_time import datetime_to_W3CDTF
def write_properties_core(properties):
@@ -72,7 +72,7 @@
'ContentType': 'application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml'})
if sheet._charts:
SubElement(root, 'Override',
- {'PartName' : '/xl/drawings/drawing%d.xml' % (sheet_id + 1),
+ {'PartName' : '/xl/drawings/drawing%d.xml' % drawing_id,
'ContentType' : 'application/vnd.openxmlformats-officedocument.drawing+xml'})
drawing_id += 1
@@ -156,8 +156,10 @@
'sheetId': '%d' % (i + 1), 'r:id': 'rId%d' % (i + 1)})
if not sheet.sheet_state == sheet.SHEETSTATE_VISIBLE:
sheet_node.set('state', sheet.sheet_state)
- # named ranges
+
+ # Defined names
defined_names = SubElement(root, 'definedNames')
+ # named ranges
for named_range in workbook.get_named_ranges():
name = SubElement(defined_names, 'definedName',
{'name': named_range.name})
@@ -178,6 +180,19 @@
# finally write the cells list
name.text = ','.join(dest_cells)
+ # autoFilter
+ for i, sheet in enumerate(workbook.worksheets):
+ #continue
+ auto_filter = sheet.auto_filter
+ if not auto_filter:
+ continue
+ name = SubElement(defined_names, 'definedName',
+ dict(name='_xlnm._FilterDatabase',
+ localSheetId=str(i),
+ hidden='1'))
+ name.text = "'%s'!%s" % (sheet.title.replace("'", "''"),
+ absolute_coordinate(auto_filter))
+
SubElement(root, 'calcPr', {'calcId': '124519', 'calcMode': 'auto',
'fullCalcOnLoad': '1'})
return get_document_content(root)
Only in ./tablib/packages/openpyxl/writer: workbook.pyc
-bur ./tablib/packages/openpyxl/writer/worksheet.py /Users/alex/Downloads/openpyxl/writer/worksheet.py
--- ./tablib/packages/openpyxl/writer/worksheet.py 2014-09-23 11:50:22.000000000 +0800
+++ /Users/alex/Downloads/openpyxl/writer/worksheet.py 2011-05-13 17:04:34.000000000 +0800
@@ -26,11 +26,11 @@
"""Write worksheets to xml representations."""
# Python stdlib imports
-from ....compat import BytesIO as StringIO # cStringIO doesn't handle unicode
+from StringIO import StringIO # cStringIO doesn't handle unicode
# package imports
-from ..cell import coordinate_from_string, column_index_from_string
-from ..shared.xmltools import Element, SubElement, XMLGenerator, \
+from openpyxl.cell import coordinate_from_string, column_index_from_string
+from openpyxl.shared.xmltools import Element, SubElement, XMLGenerator, \
get_document_content, start_tag, end_tag, tag
@@ -107,7 +107,7 @@
if worksheet.column_dimensions:
start_tag(doc, 'cols')
for column_string, columndimension in \
- worksheet.column_dimensions.items():
+ worksheet.column_dimensions.iteritems():
col_index = column_index_from_string(column_string)
col_def = {}
col_def['collapsed'] = str(columndimension.style_index)
Only in ./tablib/packages/openpyxl/writer: worksheet.pyc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment