(data, filename, strings_to_urls = True)
| 385 | return filename |
| 386 | MAX_EXCEL_LINKS = 65528 |
| 387 | def 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 |
| 415 | def get_fields(data): |
| 416 | if len(data) == 0: |
| 417 | return [] |
no test coverage detected