本文整理汇总了Python中openpyxl.styles.Protection方法的典型用法代码示例。如果您正苦于以下问题:Python styles.Protection方法的具体用法?Python styles.Protection怎么用?Python styles.Protection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openpyxl.styles
的用法示例。
在下文中一共展示了styles.Protection方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _convert_to_protection
# 需要导入模块: from openpyxl import styles [as 别名]
# 或者: from openpyxl.styles import Protection [as 别名]
def _convert_to_protection(cls, protection_dict):
"""
Convert ``protection_dict`` to an openpyxl v2 Protection object.
Parameters
----------
protection_dict : dict
A dict with zero or more of the following keys.
'locked'
'hidden'
Returns
-------
"""
from openpyxl.styles import Protection
return Protection(**protection_dict)
示例2: to_openpyxl_style
# 需要导入模块: from openpyxl import styles [as 别名]
# 或者: from openpyxl.styles import Protection [as 别名]
def to_openpyxl_style(self):
try:
openpyxl_style = self.cache[self]
except KeyError:
side = Side(border_style=self.border_type, color=utils.colors.black)
border = Border(left=side, right=side, top=side, bottom=side)
openpyxl_style = self.cache[self] = NamedStyle(
name=str(hash(self)),
font=Font(name=self.font, size=self.font_size, color=OpenPyColor(self.font_color),
bold=self.bold, underline=self.underline),
fill=PatternFill(patternType=self.fill_pattern_type, fgColor=self.bg_color),
alignment=Alignment(horizontal=self.horizontal_alignment, vertical=self.vertical_alignment,
wrap_text=self.wrap_text, shrink_to_fit=self.shrink_to_fit,
indent=self.indent, text_rotation=self.text_rotation),
border=border,
number_format=self.number_format,
protection=Protection(locked=self.protection)
)
return openpyxl_style
示例3: test_to_excel_styleconverter
# 需要导入模块: from openpyxl import styles [as 别名]
# 或者: from openpyxl.styles import Protection [as 别名]
def test_to_excel_styleconverter(self, merge_cells, ext, engine):
from openpyxl import styles
hstyle = {
"font": {
"color": '00FF0000',
"bold": True,
},
"borders": {
"top": "thin",
"right": "thin",
"bottom": "thin",
"left": "thin",
},
"alignment": {
"horizontal": "center",
"vertical": "top",
},
"fill": {
"patternType": 'solid',
'fgColor': {
'rgb': '006666FF',
'tint': 0.3,
},
},
"number_format": {
"format_code": "0.00"
},
"protection": {
"locked": True,
"hidden": False,
},
}
font_color = styles.Color('00FF0000')
font = styles.Font(bold=True, color=font_color)
side = styles.Side(style=styles.borders.BORDER_THIN)
border = styles.Border(top=side, right=side, bottom=side, left=side)
alignment = styles.Alignment(horizontal='center', vertical='top')
fill_color = styles.Color(rgb='006666FF', tint=0.3)
fill = styles.PatternFill(patternType='solid', fgColor=fill_color)
number_format = '0.00'
protection = styles.Protection(locked=True, hidden=False)
kw = _OpenpyxlWriter._convert_to_style_kwargs(hstyle)
assert kw['font'] == font
assert kw['border'] == border
assert kw['alignment'] == alignment
assert kw['fill'] == fill
assert kw['number_format'] == number_format
assert kw['protection'] == protection
示例4: test_to_excel_styleconverter
# 需要导入模块: from openpyxl import styles [as 别名]
# 或者: from openpyxl.styles import Protection [as 别名]
def test_to_excel_styleconverter(self):
import openpyxl
from openpyxl import styles
hstyle = {
"font": {
"color": '00FF0000',
"bold": True,
},
"borders": {
"top": "thin",
"right": "thin",
"bottom": "thin",
"left": "thin",
},
"alignment": {
"horizontal": "center",
"vertical": "top",
},
"fill": {
"patternType": 'solid',
'fgColor': {
'rgb': '006666FF',
'tint': 0.3,
},
},
"number_format": {
"format_code": "0.00"
},
"protection": {
"locked": True,
"hidden": False,
},
}
font_color = styles.Color('00FF0000')
font = styles.Font(bold=True, color=font_color)
side = styles.Side(style=styles.borders.BORDER_THIN)
border = styles.Border(top=side, right=side, bottom=side, left=side)
alignment = styles.Alignment(horizontal='center', vertical='top')
fill_color = styles.Color(rgb='006666FF', tint=0.3)
fill = styles.PatternFill(patternType='solid', fgColor=fill_color)
# ahh openpyxl API changes
ver = openpyxl.__version__
if ver >= LooseVersion('2.0.0') and ver < LooseVersion('2.1.0'):
number_format = styles.NumberFormat(format_code='0.00')
else:
number_format = '0.00' # XXX: Only works with openpyxl-2.1.0
protection = styles.Protection(locked=True, hidden=False)
kw = _Openpyxl20Writer._convert_to_style_kwargs(hstyle)
assert kw['font'] == font
assert kw['border'] == border
assert kw['alignment'] == alignment
assert kw['fill'] == fill
assert kw['number_format'] == number_format
assert kw['protection'] == protection