Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'exclude_hidden_sheets': options.exclude_hidden_sheets,
'merge_cells': options.merge_cells,
'outputencoding': options.outputencoding,
'lineterminator': options.lineterminator,
'ignore_formats': options.ignore_formats
}
sheetid = options.sheetid
if options.all:
sheetid = 0
outfile = options.outfile or sys.stdout
try:
if os.path.isdir(options.infile):
convert_recursive(options.infile, sheetid, outfile, kwargs)
else:
xlsx2csv = Xlsx2csv(options.infile, **kwargs)
if options.sheetname:
sheetid = xlsx2csv.getSheetIdByName(options.sheetname)
if not sheetid:
raise XlsxException("Sheet '%s' not found" % options.sheetname)
xlsx2csv.convert(outfile, sheetid)
except XlsxException:
_, e, _ = sys.exc_info()
sys.stderr.write(str(e) + "\n")
sys.exit(1)
def normalize_tabular_format(project_path):
kwargs = {
'delimiter' : '\t',
'skip_empty_lines' : True,
'outputencoding': 'utf-8',
}
sheetid = 0
for xf in project_path.rglob('*.xlsx'):
xlsx2csv = Xlsx2csv(xf, **kwargs)
with open(xf.with_suffix('.tsv'), 'wt') as f:
try:
xlsx2csv.convert(f, sheetid)
except SheetNotFoundException as e:
log.warning(f'Sheet weirdness in {xf}\n{e}')
def xlsx(self):
kwargs = {
'delimiter': '\t',
'skip_empty_lines': True,
'outputencoding': 'utf-8',
'hyperlinks': True,
}
sheetid = 1
try:
xlsx2csv = Xlsx2csv(self.path.as_posix(), **kwargs)
except InvalidXlsxFileException as e:
raise exc.NoDataError(f'{self.path}') from e
ns = len(xlsx2csv.workbook.sheets)
if ns > 1:
message = f'too many sheets ({ns}) in {self.path.as_posix()!r}'
if self.addError(exc.EncodingError(message),
blame='submission',
path=self.path):
logd.error(message)
f = io.StringIO()
try:
xlsx2csv.convert(f, sheetid)
f.seek(0)
gen = csv.reader(f, delimiter='\t')