Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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 3.x 为什么在python中创建_sheet()不起作用?_Python 3.x_Openpyxl - Fatal编程技术网

Python 3.x 为什么在python中创建_sheet()不起作用?

Python 3.x 为什么在python中创建_sheet()不起作用?,python-3.x,openpyxl,Python 3.x,Openpyxl,我想通过python代码在现有excel文件中创建一个新的工作表。我正在使用openpyxl模块。我使用了create_sheet方法,但不起作用..plz帮助。我的代码如下所示 将openpyxl作为op导入 file=op.load_工作簿('C:/Users/pavan m sunder/Desktop/hotelpythonda.xlsx') 文件。创建工作表(“新闻表”) 我希望这是“将openpyxl导入为op”而不仅仅是“将openpyxl导入为op” 创建工作表后,还需要保存ex

我想通过python代码在现有excel文件中创建一个新的工作表。我正在使用openpyxl模块。我使用了create_sheet方法,但不起作用..plz帮助。我的代码如下所示
将openpyxl作为op导入
file=op.load_工作簿('C:/Users/pavan m sunder/Desktop/hotelpythonda.xlsx')
文件。创建工作表(“新闻表”)

我希望这是“
将openpyxl导入为op
”而不仅仅是“
将openpyxl导入为op

创建工作表后,还需要保存excel。
import openpyxl as op
xlfile = 'C:/Users/pavan m sunder/Desktop/hotelpythondata.xlsx'
file=op.load_workbook(xlfile)
file.create_sheet('newsheet')

file.save(xlfile)               # You can save it as the same file or specify another path/ filename