###############################################################################
#
# Worksheet - A class for writing the Excel XLSX Worksheet file.
#
# SPDX-License-Identifier: BSD-2-Clause
# Copyright 2013-2022, John McNamara, jmcnamara@cpan.org
#
# Standard packages.
import datetime
import os
import re
import tempfile
from collections import defaultdict
from collections import namedtuple
from decimal import Decimal
from fractions import Fraction
from io import StringIO
from math import isinf
from math import isnan
from warnings import warn
# Package imports.
from . import xmlwriter
from .format import Format
from .drawing import Drawing
from .shape import Shape
from .xmlwriter import XMLwriter
from .utility import xl_rowcol_to_cell
from .utility import xl_rowcol_to_cell_fast
from .utility import xl_cell_to_rowcol
from .utility import xl_col_to_name
from .utility import xl_range
from .utility import xl_color
from .utility import get_sparkline_style
from .utility import supported_datetime
from .utility import datetime_to_excel_datetime
from .utility import preserve_whitespace
from .utility import quote_sheetname
from .exceptions import DuplicateTableName
# Compile performance critical regular expressions.
re_control_chars_1 = re.compile('(_x[0-9a-fA-F]{4}_)')
re_control_chars_2 = re.compile(r'([\x00-\x08\x0b-\x1f])')
re_dynamic_function = re.compile(r"""
\bSORT\( |
\bLET\( |
\bLAMBDA\( |
\bSINGLE\( |
\bSORTBY\( |
\bUNIQUE\( |
\bXMATCH\( |
\bFILTER\( |
\bXLOOKUP\( |
\bSEQUENCE\( |
\bRANDARRAY\( |
\bANCHORARRAY\(""", re.VERBOSE)
###############################################################################
#
# Decorator functions.
#
###############################################################################
def convert_cell_args(method):
"""
Decorator function to convert A1 notation in cell method calls
to the default row/col notation.
"""
def cell_wrapper(self, *args, **kwargs):
try:
# First arg is an int, default to row/col notation.
if len(args):
first_arg = args[0]
int(first_arg)
except ValueError:
# First arg isn't an int, convert to A1 notation.
new_args = xl_cell_to_rowcol(first_arg)
args = new_args + args[1:]
return method(self, *args, **kwargs)
return cell_wrapper
def convert_range_args(method):
"""
Decorator function to convert A1 notation in range method calls
to the default row/col notation.
"""
def cell_wrapper(self, *args, **kwargs):
try:
# First arg is an int, default to row/col notation.
if len(args):
int(args[0])
except ValueError:
# First arg isn't an int, convert to A1 notation.
if ':' in args[0]:
cell_1, cell_2 = args[0].split(':')
row_1, col_1 = xl_cell_to_rowcol(cell_1)
row_2, col_2 = xl_cell_to_rowcol(cell_2)
else:
row_1, col_1 = xl_cell_to_rowcol(args[0])
row_2, col_2 = row_1, col_1
new_args = [row_1, col_1, row_2, col_2]
new_args.extend(args[1:])
args = new_args
return method(self, *args, **kwargs)
return cell_wrapper
def convert_column_args(method):
"""
Decorator function to convert A1 notation in columns method calls
to the default row/col notation.
"""
def column_wrapper(self, *args, **kwargs):
try:
# First arg is an int, default to row/col notation.
if len(args):
int(args[0])
except ValueError:
# First arg isn't an int, convert to A1 notation.
cell_1, cell_2 = [col + '1' for col in args[0].split(':')]
_, col_1 = xl_cell_to_rowcol(cell_1)
_, col_2 = xl_cell_to_rowcol(cell_2)
new_args = [col_1, col_2]
new_args.extend(args[1:])
args = new_args
return method(self, *args, **kwargs)
return column_wrapper
###############################################################################
#
# Named tuples used for cell types.
#
###############################################################################
cell_string_tuple = namedtuple('String', 'string, format')
cell_number_tuple = namedtuple('Number', 'number, format')
cell_blank_tuple = namedtuple('Blank', 'format')
cell_boolean_tuple = namedtuple('Boolean', 'boolean, format')
cell_formula_tuple = namedtuple('Formula', 'formula, format, value')
cell_arformula_tuple = namedtuple('ArrayFormula',
'formula, format, value, range, atype')
###############################################################################
#
# Worksheet Class definition.
#
###############################################################################
class Worksheet(xmlwriter.XMLwriter):
"""
A class for writing the Excel XLSX Worksheet file.
"""
###########################################################################
#
# Public API.
#
###########################################################################
def __init__(self):
"""
Constructor.
"""
super(Worksheet, self).__init__()
self.name = None
self.index = None
self.str_table = None
self.palette = None
self.constant_memory = 0
self.tmpdir = None
self.is_chartsheet = False
self.ext_sheets = []
self.fileclosed = 0
self.excel_version = 2007
self.excel2003_style = False
self.xls_rowmax = 1048576
self.xls_colmax = 16384
self.xls_strmax = 32767
self.dim_rowmin = None
self.dim_rowmax = None
self.dim_colmin = None
self.dim_colmax = None
self.colinfo = {}
self.selections = []
self.hidden = 0
self.active = 0
self.tab_color = 0
self.top_left_cell = ''
self.panes = []
self.active_pane = 3
self.selected = 0
self.page_setup_changed = False
self.paper_size = 0
self.orientation = 1
self.print_options_changed = False
self.hcenter = False
self.vcenter = False
self.print_gridlines = False
self.screen_gridlines = True
self.print_headers = False
self.row_col_headers = False
self.header_footer_changed = False
self.header = ''
self.footer = ''
self.header_footer_aligns = True
self.header_footer_scales = True
self.header_images = []
self.footer_images = []
self.header_images_list = []
self.margin_left = 0.7
self.margin_right = 0.7
self.margin_top = 0.75
self.margin_bottom = 0.75
self.margin_header = 0.3
self.margin_footer = 0.3
self.repeat_row_range = ''
self.repeat_col_range = ''
self.print_area_range = ''
self.page_order = 0
self.black_white = 0
self.draft_quality = 0
self.print_comments = 0
self.page_start = 0
self.fit_page = 0
self.fit_width = 0
self.fit_height = 0
self.hbreaks = []
self.vbreaks = []
self.protect_options = {}
self.protected_ranges = []
self.num_protected_ranges = 0
self.set_cols = {}
self.set_rows = defaultdict(dict)
self.zoom = 100
self.zoom_scale_normal = 1
self.print_scale = 100
self.is_right_to_left = 0
self.show_zeros = 1
self.leading_zeros = 0
self.outline_row_level = 0
self.outline_col_level = 0
self.outline_style = 0
self.outline_below = 1
self.outline_right = 1
self.outline_on = 1
self.outline_changed = False
没有合适的资源?快使用搜索试试~ 我知道了~
Python3使用xlrd修改Excel数据映射关系
共1703个文件
py:802个
pyc:801个
exe:14个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 101 浏览量
2022-04-01
23:17:35
上传
评论
收藏 7.21MB ZIP 举报
温馨提示
使用python3脚本实现如下功能: 根据映射关系数据,完善Excel表格中品牌与型号的对应关系,输出修改后的Excel。 使用 xlrd 依赖库,实现Excel数据的读写; 使用 xlutils.copy 依赖库,复制并修改Excel文件, 并输出最终的修订结果Excel。 详细文章介绍地址如下: https://xiaxl.blog.csdn.net/article/details/123910322
资源推荐
资源详情
资源评论
收起资源包目录
Python3使用xlrd修改Excel数据映射关系 (1703个子文件)
pip3.7 285B
activate 2KB
sysconfig.cfg 3KB
pyvenv.cfg 104B
activate.csh 1KB
.DS_Store 6KB
.DS_Store 6KB
t64-arm.exe 177KB
w64-arm.exe 163KB
gui-arm64.exe 135KB
cli-arm64.exe 134KB
t64.exe 104KB
w64.exe 98KB
t32.exe 95KB
w32.exe 88KB
gui-64.exe 74KB
cli-64.exe 73KB
gui.exe 64KB
gui-32.exe 64KB
cli-32.exe 64KB
cli.exe 64KB
activate.fish 2KB
excel-formula.g 11KB
.gitignore 1KB
.gitignore 176B
PythonForExcel.iml 402B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
metadata.json 1KB
metadata.json 1KB
LICENSE 4KB
LICENSE 1KB
margins 278B
README.md 783B
METADATA 6KB
METADATA 4KB
METADATA 3KB
METADATA 3KB
METADATA 3KB
METADATA 2KB
cacert.pem 260KB
pip 285B
pip3 285B
distutils-precedence.pth 151B
worksheet.py 266KB
fastjsonschema_validations.py 254KB
pyparsing.py 227KB
pyparsing.py 227KB
core.py 207KB
uts46data.py 200KB
_emoji_codes.py 137KB
more.py 129KB
langrussianmodel.py 128KB
chart.py 124KB
more.py 115KB
html5parser.py 114KB
__init__.py 106KB
__init__.py 105KB
sheet.py 104KB
langbulgarianmodel.py 103KB
langthaimodel.py 101KB
langhungarianmodel.py 100KB
langgreekmodel.py 97KB
langhebrewmodel.py 96KB
BIFFRecords.py 95KB
langturkishmodel.py 94KB
formula.py 92KB
tarfile.py 90KB
typing_extensions.py 85KB
typing_extensions.py 85KB
easy_install.py 84KB
antlr.py 82KB
constants.py 82KB
console.py 79KB
_tokenizer.py 75KB
_mapping.py 68KB
util.py 66KB
workbook.py 62KB
unistring.py 62KB
book.py 56KB
test_filter.py 54KB
python.py 52KB
locators.py 51KB
database.py 50KB
msvc.py 49KB
dist.py 49KB
distro.py 47KB
Worksheet.py 47KB
ccompiler.py 47KB
dist.py 45KB
formatting.py 45KB
text.py 43KB
idnadata.py 43KB
wheel.py 42KB
compat.py 41KB
__init__.py 39KB
共 1703 条
- 1
- 2
- 3
- 4
- 5
- 6
- 18
资源评论
bjxiaxueliang
- 粉丝: 1w+
- 资源: 47
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功