Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 通过将.xls文件转换为.xlsx再转换回.xls来更改其属性_Python_Excel_Properties_Xlsx_Xls - Fatal编程技术网

Python 通过将.xls文件转换为.xlsx再转换回.xls来更改其属性

Python 通过将.xls文件转换为.xlsx再转换回.xls来更改其属性,python,excel,properties,xlsx,xls,Python,Excel,Properties,Xlsx,Xls,我有这段代码,可以在其中更改.xls文件的属性,但“last_modified_by”除外,因为当我将其转换回时,我的计算机将是最后一个被修改的人(有时它只是一个emtpy字符串,50-50)。我知道为什么,但是呃。 有没有办法改变这一点?因此,当我在“last_modified_by”中键入“asd”时,输出文件的属性(不想再次写入“last_modified_by”哈哈)将是“asd” 我的代码简介: At first i convert the .xls to xlsx. Aft

我有这段代码,可以在其中更改.xls文件的属性,但“last_modified_by”除外,因为当我将其转换回时,我的计算机将是最后一个被修改的人(有时它只是一个emtpy字符串,50-50)。我知道为什么,但是呃。 有没有办法改变这一点?因此,当我在“last_modified_by”中键入“asd”时,输出文件的属性(不想再次写入“last_modified_by”哈哈)将是“asd”

我的代码简介:

  At first i convert the .xls to xlsx. 
  After that i open the file(.xlsx) with openpyxl and change the properties and then save it. 
  At the end i convert it back to .xls and here the "last_modified_by" part changes.
这是我的密码:

import win32com.client as win32
from openpyxl import load_workbook
from xls2xlsx import XLS2XLSX
from datetime import datetime

# xls --> xlsx
x2x = XLS2XLSX("path\\file.xls")
x2x.to_xlsx('path\\file.xlsx')

# set workbook's properties
wb = load_workbook(filename = 'path\\file.xlsx')
wb.properties.title = 'asd'
wb.properties.creator = 'asd'
wb.properties.title = 'asd'
wb.properties.subject = 'asd'
wb.properties.keywords = 'asd'
wb.properties.category = 'asd'
wb.properties.description = 'asd'
wb.properties.creator = 'asd'

wb.properties.last_modified_by = 'asd'   #Here is the "last_modified_by"

wb.properties.created = datetime(2012,1,12,12,12) # Year,Month,Day,Hour,Sec
wb.properties.lastPrinted = datetime(2012,1,12,12,12) # Year,Month,Day,Hour,Sec
wb.properties.modified = datetime(2012,1,12,12,12) # Year,Month,Day,Hour,Sec
wb.save('path\\file.xlsx')

#xlsx --> xls
excel = win32.gencache.EnsureDispatch('Excel.Application')
asd = excel.Workbooks.Open('path\\file.xlsx')
asd.SaveAs('path\\file.xls', FileFormat = 56)       
asd.Close()                                    
excel.Application.Quit()