Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
elif isinstance(value, datetime):
property_type = 'date'
elif isinstance(value, int_types):
property_type = 'number_int'
elif isinstance(value, num_types):
property_type = 'number'
else:
property_type = 'text'
if property_type == 'date':
value = value.strftime("%Y-%m-%dT%H:%M:%SZ")
if property_type == 'text' and len(value) > 255:
warn("Length of 'value' parameter exceeds Excel's limit of 255 "
"characters in set_custom_property(): '%s'" %
force_unicode(value))
if len(name) > 255:
warn("Length of 'name' parameter exceeds Excel's limit of 255 "
"characters in set_custom_property(): '%s'" %
force_unicode(name))
self.custom_properties.append((name, value, property_type))
continue
# Handle non-contiguous ranges like:
# (Sheet1!$A$1:$A$2,Sheet1!$A$4:$A$5).
# We don't try to parse them. We just return an empty list.
if sheetname.startswith('('):
chart.formula_data[r_id] = []
seen_ranges[c_range] = []
continue
# Warn if the name is unknown since it indicates a user error
# in a chart series formula.
if sheetname not in worksheets:
warn("Unknown worksheet reference '%s' in range "
"'%s' passed to add_series()"
% (force_unicode(sheetname), force_unicode(c_range)))
chart.formula_data[r_id] = []
seen_ranges[c_range] = []
continue
# Find the worksheet object based on the sheet name.
worksheet = worksheets[sheetname]
# Get the data from the worksheet table.
data = worksheet._get_range_data(*cells)
# TODO. Handle SST string ids if required.
# Add the data to the chart.
chart.formula_data[r_id] = data
# Store range data locally to avoid lookup if seen again.
if formula.startswith('='):
formula = formula.lstrip('=')
# Local defined names are formatted like "Sheet1!name".
sheet_parts = re.compile(r'^(.*)!(.*)$')
match = sheet_parts.match(name)
if match:
sheetname = match.group(1)
name = match.group(2)
sheet_index = self._get_sheet_index(sheetname)
# Warn if the sheet index wasn't found.
if sheet_index is None:
warn("Unknown sheet name '%s' in defined_name()"
% force_unicode(sheetname))
return -1
else:
# Use -1 to indicate global names.
sheet_index = -1
# Warn if the defined name contains invalid chars as defined by Excel.
if (not re.match(r'^[\w\\][\w\\.]*$', name, re.UNICODE)
or re.match(r'^\d', name)):
warn("Invalid Excel characters in defined_name(): '%s'"
% force_unicode(name))
return -1
# Warn if the defined name looks like a cell name.
if re.match(r'^[a-zA-Z][a-zA-Z]?[a-dA-D]?[0-9]+$', name):
warn("Name looks like a cell name in defined_name(): '%s'"
% force_unicode(name))
property_type = 'number'
else:
property_type = 'text'
if property_type == 'date':
value = value.strftime("%Y-%m-%dT%H:%M:%SZ")
if property_type == 'text' and len(value) > 255:
warn("Length of 'value' parameter exceeds Excel's limit of 255 "
"characters in set_custom_property(): '%s'" %
force_unicode(value))
if len(name) > 255:
warn("Length of 'name' parameter exceeds Excel's limit of 255 "
"characters in set_custom_property(): '%s'" %
force_unicode(name))
self.custom_properties.append((name, value, property_type))