MCPcopy Index your code
hub / github.com/omkarcloud/botasaurus / write_workbook

Function write_workbook

botasaurus/output.py:387–414  ·  view source on GitHub ↗
(data, filename,  strings_to_urls = True)

Source from the content-addressed store, hash-verified

385 return filename
386MAX_EXCEL_LINKS = 65528
387def write_workbook(data, filename, strings_to_urls = True):
388 import xlsxwriter
389 if strings_to_urls:
390 workbook = xlsxwriter.Workbook(filename)
391 else:
392 workbook = xlsxwriter.Workbook(filename, {'strings_to_urls': False})
393
394 worksheet = workbook.add_worksheet()
395
396 # Write headers
397 fieldnames = get_fields(data)
398 worksheet.write_row(0, 0, fieldnames)
399
400 # Write data
401 row = 1
402 for item in data:
403 # Prevent Warnings and Handle Excel 65K Link Limit
404 if worksheet.hlink_count > MAX_EXCEL_LINKS:
405 workbook.close()
406 if os.path.exists(filename):
407 os.remove(filename)
408 return write_workbook(data, filename,strings_to_urls = False)
409 values = list(item.values())
410 worksheet.write_row(row, 0, values)
411 row += 1
412
413 workbook.close()
414 return filename
415def get_fields(data):
416 if len(data) == 0:
417 return []

Callers 1

write_excelFunction · 0.85

Calls 3

closeMethod · 0.80
removeMethod · 0.80
get_fieldsFunction · 0.70

Tested by

no test coverage detected