Closed ye-xue closed 2 years ago
Thanks for the detailed report. That looks like a bug. I'll look into it.
I don't see the same result as you. I modified your sample code to move the second image closer to the first for comparison and the images are different:
Here is an image comparison of the images in the output file (renamed to qrcode.xlsx). The grey areas are different between the 2 images:
The QR codes read from the images is also different.
I tested it on another computer and the result is still the same. What does the code you use look like? I'll test it
Here is the code I ran. It is the same as yours, without the commented out code, with the second image moved to cell C1 and with the filename changed:
import io
import qrcode
from xlsxwriter import Workbook
def get_io_qr(qr_str, version=5, box_size=2, border=1) -> io.BytesIO:
qr = qrcode.QRCode(version=version, box_size=box_size, border=border)
qr.add_data(qr_str)
qr_data = io.BytesIO()
qr.make(fit=True)
img = qr.make_image()
img.save(qr_data)
return qr_data
with Workbook('gh913.xlsx') as workbook:
worksheet = workbook.add_worksheet('test')
label_str = '1137249488/6000|KMC51030079V001|KM51006110V001|1'
qr_data = get_io_qr(label_str, version=4, box_size=2)
worksheet.insert_image(0, 0, label_str,
{'image_data': qr_data, 'x_offset': 5, 'y_offset': 5})
label_str = '1137249493/6000|KMC51030079V001|KM51123515V000|1.0'
qr_data = get_io_qr(label_str, version=4, box_size=2)
worksheet.insert_image(0, 2, label_str,
{'image_data': qr_data, 'x_offset': 5, 'y_offset': 5})
I've attached the output file: gh913.xlsx
Using the same code I ran out of still the same problem. When checking whether it is the same picture, the Windows side determines that the two pictures are the same. gh913.xlsx
That is a bit weird. I see the same as you with Excel 15 but not other versions:
I'll look into it a bit more.
Test images, for reference:
Reference files for testing:
File created by xlsxwriter: gh913_xlsxwriter.xlsx
File created in Excel12/2007: gh913_excel12.xlsx
File created in Excel15: gh913_excel15.xlsx
File created in Excel16/365: gh913_excel16.xlsx
The gh913_excel??.xlsx
Excel files were created by opening a new blank worksheet in Excel, and inserted image1.png (from above) in Cel A1 and image2.png in cell C1, and then saving the file. The gh913_xlsxwriter.xlsx
file was created using XlsxWriter.
Note, all of these files show different images in Excel12 and Excel16 but the same in Excel15. Even when inserting the images in Excel15 they looked the same. You can test this yourself.
So this looks like an Excel15 issue since it is clearly reproducible with files created in other versions of Excel. Again, you can verify this for yourself.
Also, interestingly, the file created with Excel15 only has one unique image in it, although I double checked that I had added both:
unzip -l ~/Desktop/gh913_excel15.xlsx
Archive: /Users/John/Desktop/gh913_excel15.xlsx
Length Date Time Name
--------- ---------- ----- ----
1202 01-01-1980 00:00 [Content_Types].xml
588 01-01-1980 00:00 _rels/.rels
2180 01-01-1980 00:00 xl/workbook.xml
557 01-01-1980 00:00 xl/_rels/workbook.xml.rels
954 01-01-1980 00:00 xl/worksheets/sheet1.xml
8390 01-01-1980 00:00 xl/theme/theme1.xml
1618 01-01-1980 00:00 xl/styles.xml
2528 01-01-1980 00:00 xl/drawings/drawing1.xml
364 01-01-1980 00:00 xl/media/image1.png
299 01-01-1980 00:00 xl/worksheets/_rels/sheet1.xml.rels
292 01-01-1980 00:00 xl/drawings/_rels/drawing1.xml.rels
619 01-01-1980 00:00 docProps/core.xml
785 01-01-1980 00:00 docProps/app.xml
--------- -------
20376 13 files
Note, this contains image1.png
only. Excel usually only stores 1 copy of each unique image. So it seems that Excel15 thinks that image1.png
and image2.png
are the same.
Here is the same output for the Excel16 file:
~/Development/xlsx/inspect$ unzip -l ~/Desktop/gh913_excel16.xlsx
Archive: /Users/John/Desktop/gh913_excel16.xlsx
Length Date Time Name
--------- ---------- ----- ----
1202 01-01-1980 00:00 [Content_Types].xml
588 01-01-1980 00:00 _rels/.rels
557 01-01-1980 00:00 xl/_rels/workbook.xml.rels
2249 01-01-1980 00:00 xl/workbook.xml
2528 01-01-1980 00:00 xl/drawings/drawing1.xml
364 01-01-1980 00:00 xl/media/image1.png
1618 01-01-1980 00:00 xl/styles.xml
427 01-01-1980 00:00 xl/drawings/_rels/drawing1.xml.rels
364 01-01-1980 00:00 xl/media/image2.png
8390 01-01-1980 00:00 xl/theme/theme1.xml
971 01-01-1980 00:00 xl/worksheets/sheet1.xml
299 01-01-1980 00:00 xl/worksheets/_rels/sheet1.xml.rels
619 01-01-1980 00:00 docProps/core.xml
795 01-01-1980 00:00 docProps/app.xml
--------- -------
20971 14 files
Note, this contains 2 image files: image1.png
and image2.png
.
So this, to me, looks like an Excel15 bug.
I use Microsoft Office Home and Student 2019 to open these files with the same pattern. There are no other versions of Office to test at this time.
The major version we use is Office2019, is there a way to avoid this problem?
I use Microsoft Office Home and Student 2019 to open these files with the same pattern.
If you see the same image when you open the Excel12 and Excel16 file then that implies that this isn't an XlsxWriter issue since those files were created in Excel and not XlsxWriter.
The major version we use is Office2019, is there a way to avoid this problem?
I don't think so. It looks like an Excel bug.
Thank you so much! Can you file this bug with Microsoft?
Thank you so much! Can you file this bug with Microsoft?
Sorry, no. I don't know how. If you submit it you can point back to the test files here.
Closing.
P.S., it may be worth installing any available Excel updates to see if this issue was fixed in an update.
Current behavior
Add multiple images, the images are different, but the result is that the two pictures are the same.
Expected behavior
Different image data shows different image content
Sample code to reproduce
Environment
Any other information
No response
OpenOffice and LibreOffice users