0

我有一个 django 站点,它将获取上传的 .xls 文件并将它们合并到一个工作簿中

我无法合并上传的 Worksdheets。这是我的代码示例:

import pyexcel
import openpyxl
from pyexcel.cookbook import merge_all_to_a_book

   def post(self, request, *args, **kwargs):
        form_class = self.get_form_class()
        form = self.get_form(form_class)
        if form.is_valid():
            type_of_case = form.cleaned_data['Selection_type']
            case = form.cleaned_data['Case']
            new_name = type_of_case + '-' +case + '.xlsx'
            file_names = []
            objects=[]
            for x in request.FILES.getlist('Files'):
                filename = x.name
                file_names.append(filename)
                excel_ojects = x.read
                objects.append(excel_ojects)
                file_names.append(filename)
                print (x.content_type)
            merge_all_to_a_book(objects, outfilename=(new_name))

我尝试将 merge_all_to_a_book 更改为选项 (objects) 和 (file_names) 但它们都产生错误提示: OSError: Unsupported file type

但是,当我打印我得到的内容类型时: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

谁能帮我合并这些该死的电子表格?

4

0 回答 0