jmcnamara / XlsxWriter

A Python module for creating Excel XLSX files.
https://xlsxwriter.readthedocs.io
BSD 2-Clause "Simplified" License
3.66k stars 631 forks source link

question: Is there any limit to how many images can be anchored in a excel sheet ? #1088

Closed 80avin closed 2 months ago

80avin commented 2 months ago

Question

I tried adding many images using xlsxwriter and openpyxl into cells, anchoring them to some cell. But for both libraries, after 1865 row, the anchoring failed to work.

All the images which should be beyond 1864/1865 row get stacked at one place. image

Note: I've hidden some confidential columns.

Sample code:

import xlsxwriter

workbook = xlsxwriter.Workbook('hello.xlsx')
worksheet = workbook.add_worksheet()

worksheet.write('A1', 'Hello world')
# workaround:
# worksheet.set_row(0, 16)
for i in range(3000):
  img_name, io_buf = get_image()
  ws.insert_image(f'R{i}', img_name, {'image_data': io_buf })

workbook.close()
jmcnamara commented 2 months ago

Is there any limit to how many images can be anchored in a excel sheet

Not that I am aware of.

Also, I ran a version of your program and an images in row 3000:

import xlsxwriter

workbook = xlsxwriter.Workbook("gh1088.xlsx")
worksheet = workbook.add_worksheet()

worksheet.write("A1", "Hello world")

for i in range(3000):
    worksheet.insert_image(i + 1, 0, "red.png")

workbook.close()

Image:

red

Output:

screenshot

So clearly it works.

If you think there is a bug please submit a complete working program and image to replicate it.

80avin commented 2 months ago

@jmcnamara Thank you for testing this. Looks like there is a limit though not in the number of anchors or images. It is in numbers (internal) going greater than $2^{31}$ ref: https://github.com/jmcnamara/XlsxWriter/issues/1089