本文整理汇总了Python中openpyxl.utils.indexed_list.IndexedList.add方法的典型用法代码示例。如果您正苦于以下问题:Python IndexedList.add方法的具体用法?Python IndexedList.add怎么用?Python IndexedList.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openpyxl.utils.indexed_list.IndexedList
的用法示例。
在下文中一共展示了IndexedList.add方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from openpyxl.utils.indexed_list import IndexedList [as 别名]
# 或者: from openpyxl.utils.indexed_list.IndexedList import add [as 别名]
class DummyWorkbook:
def __init__(self):
self.shared_styles = IndexedList()
self._cell_styles = IndexedList()
self._cell_styles.add(StyleArray())
self._cell_styles.add(StyleArray([10,0,0,0,0,0,0,0,0,0]))
self.sheetnames = []
示例2: __init__
# 需要导入模块: from openpyxl.utils.indexed_list import IndexedList [as 别名]
# 或者: from openpyxl.utils.indexed_list.IndexedList import add [as 别名]
class DummyWorkbook:
def __init__(self):
self.shared_styles = IndexedList()
self._cell_styles = IndexedList()
self._cell_styles.add(StyleId())
self._cell_styles.add(StyleId(fontId=10, numFmtId=0, borderId=0, fillId=0, protectionId=0, alignmentId=0))
def get_sheet_names(self):
return []
示例3: CellStyleList
# 需要导入模块: from openpyxl.utils.indexed_list import IndexedList [as 别名]
# 或者: from openpyxl.utils.indexed_list.IndexedList import add [as 别名]
class CellStyleList(Serialisable):
tagname = "cellXfs"
__attrs__ = ("count",)
count = Integer(allow_none=True)
xf = Sequence(expected_type=CellStyle)
alignment = Sequence(expected_type=Alignment)
protection = Sequence(expected_type=Protection)
__elements__ = ('xf',)
def __init__(self,
count=None,
xf=(),
):
self.xf = xf
@property
def count(self):
return len(self.xf)
def __getitem__(self, idx):
return self.xf[idx]
def _to_array(self):
"""
Extract protection and alignments, convert to style array
"""
self.prots = IndexedList([Protection()])
self.alignments = IndexedList([Alignment()])
styles = [] # allow duplicates
for xf in self.xf:
style = xf.to_array()
if xf.alignment is not None:
style.alignmentId = self.alignments.add(xf.alignment)
if xf.protection is not None:
style.protectionId = self.prots.add(xf.protection)
styles.append(style)
return IndexedList(styles)
示例4: from_comments
# 需要导入模块: from openpyxl.utils.indexed_list import IndexedList [as 别名]
# 或者: from openpyxl.utils.indexed_list.IndexedList import add [as 别名]
def from_comments(cls, comments):
"""
Create a comment sheet from a list of comments for a particular worksheet
"""
authors = IndexedList()
# dedupe authors and get indexes
for comment in comments:
comment.authorId = authors.add(comment.author)
return cls(authors=AuthorList(authors), commentList=comments)
示例5: __init__
# 需要导入模块: from openpyxl.utils.indexed_list import IndexedList [as 别名]
# 或者: from openpyxl.utils.indexed_list.IndexedList import add [as 别名]
class DummyWorkbook:
_guess_types = False
data_only = False
_colors = []
def __init__(self):
self._differential_styles = []
self.shared_strings = IndexedList()
self.shared_strings.add("hello world")
self._fonts = IndexedList()
self._fills = IndexedList()
self._number_formats = IndexedList()
self._borders = IndexedList()
self._alignments = IndexedList()
self._protections = IndexedList()
self._cell_styles = IndexedList()
self.vba_archive = None
for i in range(29):
self._cell_styles.add((StyleArray([i]*9)))
self._cell_styles.add(StyleArray([0,4,6,0,0,1,0,0,0])) #fillId=4, borderId=6, alignmentId=1))
self.sheetnames = []
def create_sheet(self, title):
return Worksheet(self)
示例6: write_comments
# 需要导入模块: from openpyxl.utils.indexed_list import IndexedList [as 别名]
# 或者: from openpyxl.utils.indexed_list.IndexedList import add [as 别名]
def write_comments(self):
"""
Create list of comments and authors
"""
authors = IndexedList()
# dedupe authors and get indexes
for comment in self.comments:
comment.authorId = authors.add(comment.author)
root = CommentSheet(authors=AuthorList(authors), commentList=self.comments)
return tostring(root.to_tree())
示例7: write_comments
# 需要导入模块: from openpyxl.utils.indexed_list import IndexedList [as 别名]
# 或者: from openpyxl.utils.indexed_list.IndexedList import add [as 别名]
def write_comments(self):
"""
Create list of comments and authors
Sorted by row, col
"""
# produce xml
authors = IndexedList()
for comment in self.comments:
comment.authorId = authors.add(comment.author)
author_list = AuthorList(authors)
root = CommentSheet(authors=author_list, commentList=self.comments)
return tostring(root.to_tree())
示例8: write_comments
# 需要导入模块: from openpyxl.utils.indexed_list import IndexedList [as 别名]
# 或者: from openpyxl.utils.indexed_list.IndexedList import add [as 别名]
def write_comments(self):
"""
Create list of comments and authors
Sorted by row, col
"""
# produce xml
authors = IndexedList()
for _coord, cell in sorted(self.sheet._cells.items()):
if cell.comment is not None:
comment = Comment(ref=cell.coordinate)
comment.authorId = authors.add(cell.comment.author)
comment.text.t = cell.comment.text
comment.height = cell.comment.height
comment.width = cell.comment.width
self.comments.append(comment)
author_list = AuthorList(authors)
root = CommentSheet(authors=author_list, commentList=self.comments)
return tostring(root.to_tree())
示例9: __init__
# 需要导入模块: from openpyxl.utils.indexed_list import IndexedList [as 别名]
# 或者: from openpyxl.utils.indexed_list.IndexedList import add [as 别名]
class DummyWorkbook:
_guess_types = False
data_only = False
def __init__(self):
self.shared_strings = IndexedList()
self.shared_strings.add("hello world")
self.shared_styles = 28*[DummyStyle()]
self.shared_styles.append(Style())
self._fonts = IndexedList()
self._fills = IndexedList()
self._number_formats = IndexedList()
self._borders = IndexedList()
self._alignments = IndexedList()
self._protections = IndexedList()
self._cell_styles = IndexedList()
self.vba_archive = None
for i in range(29):
self._cell_styles.add((StyleId(i, i, i, i, i, i)))
self._cell_styles.add(StyleId(fillId=4, borderId=6, alignmentId=1, protectionId=0))
示例10: SharedStylesParser
# 需要导入模块: from openpyxl.utils.indexed_list import IndexedList [as 别名]
# 或者: from openpyxl.utils.indexed_list.IndexedList import add [as 别名]
#.........这里部分代码省略.........
def parse_dxfs(self):
"""Read in the dxfs effects - used by conditional formatting."""
for node in self.root.findall("{%s}dxfs/{%s}dxf" % (SHEET_MAIN_NS, SHEET_MAIN_NS) ):
self.differential_styles.append(DifferentialStyle.from_tree(node))
def parse_fonts(self):
"""Read in the fonts"""
fonts = self.root.findall('{%s}fonts/{%s}font' % (SHEET_MAIN_NS, SHEET_MAIN_NS))
for node in fonts:
yield Font.from_tree(node)
def parse_fills(self):
"""Read in the list of fills"""
fills = self.root.findall('{%s}fills/{%s}fill' % (SHEET_MAIN_NS, SHEET_MAIN_NS))
for fill in fills:
yield Fill.from_tree(fill)
def parse_borders(self):
"""Read in the boarders"""
borders = self.root.findall('{%s}borders/{%s}border' % (SHEET_MAIN_NS, SHEET_MAIN_NS))
for border_node in borders:
yield Border.from_tree(border_node)
def parse_named_styles(self):
"""
Extract named styles
"""
node = self.root.find("{%s}cellStyleXfs" % SHEET_MAIN_NS)
styles = self._parse_xfs(node)
names = self._parse_style_names()
for style in names.values():
_id = styles[style.xfId]
style.border = self.border_list[_id.borderId]
style.fill = self.fill_list[_id.fillId]
style.font = self.font_list[_id.fontId]
if _id.alignmentId:
style.alignment = self.alignments[_id.alignmentId]
if _id.protectionId:
style.protection = self.protections[_id.protectionId]
self.named_styles = names
def _parse_style_names(self):
"""
Extract style names. There can be duplicates in which case last wins
"""
node = self.root.find("{%s}cellStyles" % SHEET_MAIN_NS)
names = {}
for _name in safe_iterator(node, '{%s}cellStyle' % SHEET_MAIN_NS):
name = _name.get("name")
style = NamedStyle(name=name,
builtinId=_name.get("builtinId"),
hidden=_name.get("hidden")
)
style.xfId = int(_name.get("xfId"))
names[name] = style
return names
def parse_cell_styles(self):
"""
Extract individual cell styles
"""
node = self.root.find('{%s}cellXfs' % SHEET_MAIN_NS)
if node is not None:
self.cell_styles = self._parse_xfs(node)
def _parse_xfs(self, node):
"""Read styles from the shared style table"""
_style_ids = []
xfs = safe_iterator(node, '{%s}xf' % SHEET_MAIN_NS)
for xf in xfs:
style = StyleArray.from_tree(xf)
al = xf.find('{%s}alignment' % SHEET_MAIN_NS)
if al is not None:
alignment = Alignment(**al.attrib)
style.alignmentId = self.alignments.add(alignment)
prot = xf.find('{%s}protection' % SHEET_MAIN_NS)
if prot is not None:
protection = Protection(**prot.attrib)
style.protectionId = self.protections.add(protection)
numFmtId = int(xf.get("numFmtId", 0))
# check for custom formats and normalise indices
if numFmtId in self.custom_number_formats:
format_code = self.custom_number_formats[numFmtId]
style.numFmtId = self.number_formats.add(format_code) + 164
_style_ids.append(style)
return IndexedList(_style_ids)
示例11: Workbook
# 需要导入模块: from openpyxl.utils.indexed_list import IndexedList [as 别名]
# 或者: from openpyxl.utils.indexed_list.IndexedList import add [as 别名]
class Workbook(object):
"""Workbook is the container for all other parts of the document."""
_read_only = False
_data_only = False
_keep_links = True
template = False
path = "/xl/workbook.xml"
def __init__(self,
write_only=False,
):
self._sheets = []
self._active_sheet_index = 0
self.defined_names = DefinedNameList()
self._external_links = []
self.properties = DocumentProperties()
self.security = DocumentSecurity()
self.__write_only = write_only
self.shared_strings = IndexedList()
self._setup_styles()
self.loaded_theme = None
self.vba_archive = None
self.is_template = False
self._differential_styles = DifferentialStyleList()
self.code_name = None
self.excel_base_date = CALENDAR_WINDOWS_1900
self.encoding = "utf-8"
if not self.write_only:
self._sheets.append(Worksheet(self))
self.rels = RelationshipList()
def _setup_styles(self):
"""Bootstrap styles"""
from openpyxl.styles.alignment import Alignment
from openpyxl.styles.borders import DEFAULT_BORDER
from openpyxl.styles.fills import DEFAULT_EMPTY_FILL, DEFAULT_GRAY_FILL
from openpyxl.styles.fonts import DEFAULT_FONT
from openpyxl.styles.protection import Protection
from openpyxl.styles.colors import COLOR_INDEX
from openpyxl.styles.named_styles import NamedStyleList
self._fonts = IndexedList()
self._fonts.add(DEFAULT_FONT)
self._alignments = IndexedList([Alignment()])
self._borders = IndexedList()
self._borders.add(DEFAULT_BORDER)
self._fills = IndexedList()
self._fills.add(DEFAULT_EMPTY_FILL)
self._fills.add(DEFAULT_GRAY_FILL)
self._number_formats = IndexedList()
self._protections = IndexedList([Protection()])
self._colors = COLOR_INDEX
self._cell_styles = IndexedList([StyleArray()])
self._named_styles = NamedStyleList()
self.add_named_style(NamedStyle(font=DEFAULT_FONT, builtinId=0))
@property
def read_only(self):
return self._read_only
@property
def data_only(self):
return self._data_only
@property
def write_only(self):
return self.__write_only
@property
def keep_links(self):
return self._keep_links
@deprecated("Use the .active property")
def get_active_sheet(self):
"""Returns the current active sheet."""
return self.active
@property
def active(self):
"""Get the currently active sheet or None"""
try:
return self._sheets[self._active_sheet_index]
except IndexError:
pass
@active.setter
def active(self, value):
#.........这里部分代码省略.........
示例12: Workbook
# 需要导入模块: from openpyxl.utils.indexed_list import IndexedList [as 别名]
# 或者: from openpyxl.utils.indexed_list.IndexedList import add [as 别名]
class Workbook(object):
"""Workbook is the container for all other parts of the document."""
_optimized_worksheet_class = DumpWorksheet
def __init__(self,
optimized_write=False,
encoding='utf-8',
worksheet_class=Worksheet,
guess_types=False,
data_only=False,
read_only=False,
write_only=False):
self.worksheets = []
self._active_sheet_index = 0
self._named_ranges = []
self._external_links = []
self.properties = DocumentProperties()
self.style = Style()
self.security = DocumentSecurity()
self.__write_only = write_only or optimized_write
self.__read_only = read_only
self.__thread_local_data = threading.local()
self.shared_strings = IndexedList()
self._setup_styles()
self.loaded_theme = None
self._worksheet_class = worksheet_class
self.vba_archive = None
self.is_template = False
self._differential_styles = []
self._guess_types = guess_types
self.data_only = data_only
self.relationships = []
self.drawings = []
self.code_name = None
self.excel_base_date = CALENDAR_WINDOWS_1900
self.encoding = encoding
if not self.write_only:
self.worksheets.append(self._worksheet_class(parent_workbook=self))
def _setup_styles(self):
"""Bootstrap styles"""
from openpyxl.styles.alignment import Alignment
from openpyxl.styles.borders import DEFAULT_BORDER
from openpyxl.styles.fills import DEFAULT_EMPTY_FILL, DEFAULT_GRAY_FILL
from openpyxl.styles.fonts import DEFAULT_FONT
from openpyxl.styles.protection import Protection
from openpyxl.styles.colors import COLOR_INDEX
self._fonts = IndexedList()
self._fonts.add(DEFAULT_FONT)
self._alignments = IndexedList([Alignment()])
self._borders = IndexedList()
self._borders.add(DEFAULT_BORDER)
self._fills = IndexedList()
self._fills.add(DEFAULT_EMPTY_FILL)
self._fills.add(DEFAULT_GRAY_FILL)
self._number_formats = IndexedList()
self._protections = IndexedList([Protection()])
self._colors = COLOR_INDEX
self._cell_styles = IndexedList([StyleId()])
@deprecated('this method is private and should not be called directly')
def read_workbook_settings(self, xml_source):
self._read_workbook_settings(xml_source)
def _read_workbook_settings(self, xml_source):
root = fromstring(xml_source)
view = root.find('*/' '{%s}workbookView' % SHEET_MAIN_NS)
if view is not None:
if 'activeTab' in view.attrib:
self.active = int(view.attrib['activeTab'])
@property
def shared_styles(self):
"""
Legacy
On the fly conversion of style references to style objects
"""
styles = []
for sid in self._cell_styles:
font = self._fonts[sid.font]
fill = self._fills[sid.fill]
border = self._borders[sid.border]
alignment = self._alignments[sid.alignment]
protection = self._protections[sid.protection]
nf_id = sid.number_format
if nf_id < 164:
number_format = BUILTIN_FORMATS.get(nf_id, "General")
else:
#.........这里部分代码省略.........
示例13: Workbook
# 需要导入模块: from openpyxl.utils.indexed_list import IndexedList [as 别名]
# 或者: from openpyxl.utils.indexed_list.IndexedList import add [as 别名]
class Workbook(object):
"""Workbook is the container for all other parts of the document."""
def __init__(self,
optimized_write=False,
encoding='utf-8',
guess_types=False,
data_only=False,
read_only=False,
write_only=False):
self.worksheets = []
self._active_sheet_index = 0
self._named_ranges = []
self._external_links = []
self.properties = DocumentProperties()
self.security = DocumentSecurity()
self.__write_only = write_only or optimized_write
self.__read_only = read_only
self.shared_strings = IndexedList()
self._setup_styles()
self.loaded_theme = None
self.vba_archive = None
self.is_template = False
self._differential_styles = []
self._guess_types = guess_types
self.data_only = data_only
self._drawings = []
self._charts = []
self._images = []
self.code_name = None
self.excel_base_date = CALENDAR_WINDOWS_1900
self.encoding = encoding
if not self.write_only:
self.worksheets.append(Worksheet(parent_workbook=self))
def _setup_styles(self):
"""Bootstrap styles"""
from openpyxl.styles.alignment import Alignment
from openpyxl.styles.borders import DEFAULT_BORDER
from openpyxl.styles.fills import DEFAULT_EMPTY_FILL, DEFAULT_GRAY_FILL
from openpyxl.styles.fonts import DEFAULT_FONT
from openpyxl.styles.protection import Protection
from openpyxl.styles.colors import COLOR_INDEX
self._fonts = IndexedList()
self._fonts.add(DEFAULT_FONT)
self._alignments = IndexedList([Alignment()])
self._borders = IndexedList()
self._borders.add(DEFAULT_BORDER)
self._fills = IndexedList()
self._fills.add(DEFAULT_EMPTY_FILL)
self._fills.add(DEFAULT_GRAY_FILL)
self._number_formats = IndexedList()
self._protections = IndexedList([Protection()])
self._colors = COLOR_INDEX
self._cell_styles = IndexedList([StyleId()])
self._named_styles = {'Normal': NamedStyle(font=DEFAULT_FONT)}
@property
def read_only(self):
return self.__read_only
@property
def write_only(self):
return self.__write_only
@deprecated("Use the .active property")
def get_active_sheet(self):
"""Returns the current active sheet."""
return self.active
@property
def active(self):
"""Get the currently active sheet"""
return self.worksheets[self._active_sheet_index]
@active.setter
def active(self, value):
"""Set the active sheet"""
self._active_sheet_index = value
def create_sheet(self, index=None, title=None):
"""Create a worksheet (at an optional index).
:param index: optional position at which the sheet will be inserted
:type index: int
"""
#.........这里部分代码省略.........
示例14: SharedStylesParser
# 需要导入模块: from openpyxl.utils.indexed_list import IndexedList [as 别名]
# 或者: from openpyxl.utils.indexed_list.IndexedList import add [as 别名]
#.........这里部分代码省略.........
"""Read in the list of fills"""
fills = self.root.findall('{%s}fills/{%s}fill' % (SHEET_MAIN_NS, SHEET_MAIN_NS))
for fill in fills:
yield Fill.from_tree(fill)
def parse_borders(self):
"""Read in the boarders"""
borders = self.root.findall('{%s}borders/{%s}border' % (SHEET_MAIN_NS, SHEET_MAIN_NS))
for border_node in borders:
yield Border.from_tree(border_node)
def parse_named_styles(self):
"""
Extract named styles
"""
ns = []
styles_node = self.root.find("{%s}cellStyleXfs" % SHEET_MAIN_NS)
self._parse_xfs(styles_node)
_ids = self.cell_styles
for _name, idx in self._parse_style_names():
_id = _ids[idx]
style = NamedStyle(name=_name)
style.border = self.border_list[_id.border]
style.fill = self.fill_list[_id.fill]
style.font = self.font_list[_id.font]
if _id.alignment:
style.alignment = self.alignments[_id.alignment]
if _id.protection:
style.protection = self.protections[_id.protection]
ns.append(style)
self.named_styles = IndexedList(ns)
def _parse_style_names(self):
names_node = self.root.find("{%s}cellStyles" % SHEET_MAIN_NS)
for _name in names_node:
yield _name.get("name"), int(_name.get("xfId"))
def parse_cell_styles(self):
"""
Extract individual cell styles
"""
node = self.root.find('{%s}cellXfs' % SHEET_MAIN_NS)
if node is not None:
self._parse_xfs(node)
def _parse_xfs(self, node):
"""Read styles from the shared style table"""
_styles = []
_style_ids = []
builtin_formats = numbers.BUILTIN_FORMATS
xfs = safe_iterator(node, '{%s}xf' % SHEET_MAIN_NS)
for index, xf in enumerate(xfs):
_style = {}
attrs = dict(xf.attrib)
alignmentId = protectionId = 0
numFmtId = int(xf.get("numFmtId", 0))
fontId = int(xf.get("fontId", 0))
fillId = int(xf.get("fillId", 0))
borderId = int(xf.get("borderId", 0))
if numFmtId < 164:
format_code = builtin_formats.get(numFmtId, 'General')
else:
format_code = self.number_formats[numFmtId-165]
_style['number_format'] = format_code
if bool_attrib(xf, 'applyAlignment'):
al = xf.find('{%s}alignment' % SHEET_MAIN_NS)
if al is not None:
alignment = Alignment(**al.attrib)
attrs['alignmentId'] = self.alignments.add(alignment)
_style['alignment'] = alignment
if bool_attrib(xf, 'applyFont'):
_style['font'] = self.font_list[fontId]
if bool_attrib(xf, 'applyFill'):
_style['fill'] = self.fill_list[fillId]
if bool_attrib(xf, 'applyBorder'):
_style['border'] = self.border_list[borderId]
if bool_attrib(xf, 'applyProtection'):
prot = xf.find('{%s}protection' % SHEET_MAIN_NS)
if prot is not None:
protection = Protection(**prot.attrib)
attrs['protectionId'] = self.protections.add(protection)
_style['protection'] = protection
_styles.append(Style(**_style))
_style_ids.append(StyleId(**attrs))
self.shared_styles = _styles
self.cell_styles = IndexedList(_style_ids)