最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Python openpyxl issue when save xlsx file - Stack Overflow

programmeradmin4浏览0评论

I'm using Walmart template file to upload bulk listings to their site. The template only allow 10.000 rows, so I have to split them into multiple files. The solution I'm using is to copy the original xlsx file and use new name for the file.

Here's the code for copying file

newWMFile = 'c:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python312\\'+'walmart-test-save.xlsx'

shutil.copyfile('c:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python312\\walmart.xlsx', newWMFile)

I try to open the new file using openpyxl and just save the file without any changes.

After I ran the code, I open the xlsx file, everything looks the same when viewing it with Excel program, but when I uploaded it to Walmart, it said something wrong with the file. After checking, I found out that the headers were modified somehow, I only knew this when I tried to copy the header "SKU" which is a merged cell, and pasted into text editor.

The SKU header of the original file from Walmart, in sheet "Product Content And Site Exp" looks like this:

SKU

SKU

while the file after saving using openpyxl looks like this:

SKU

There's a missing SKU as you can see.

Here's link to the 2 files:

Original working file:

;ouid=117184241470804778107&rtpof=true&sd=true

Corrupted file after saving using openpyxl: ;ouid=117184241470804778107&rtpof=true&sd=true

And here's the code that I'm using:

code

workbook = load_workbook(newWMFile)
worksheet = workbook.active
workbook.save(newWMFile)
workbook.close()

code

发布评论

评论列表(0)

  1. 暂无评论