Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.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 Excel复制不带公式的数据openpyxl_Python_Python 3.x_Pandas_Openpyxl - Fatal编程技术网

Python Excel复制不带公式的数据openpyxl

Python Excel复制不带公式的数据openpyxl,python,python-3.x,pandas,openpyxl,Python,Python 3.x,Pandas,Openpyxl,我正在尝试将一些数据从一张纸复制粘贴到另一张纸上。代码运行良好,但我只需要值 original_wb = xl.load_workbook(filename1) copy_to_wb = xl.load_workbook(filename1) source_sheet = original_wb.worksheets[0] # The first worksheet copy_to_sheet = copy_to_wb.create_sheet(source_sheet.title+"

我正在尝试将一些数据从一张纸复制粘贴到另一张纸上。代码运行良好,但我只需要值

original_wb = xl.load_workbook(filename1)
copy_to_wb = xl.load_workbook(filename1)
source_sheet = original_wb.worksheets[0] # The first worksheet
copy_to_sheet = copy_to_wb.create_sheet(source_sheet.title+"_copy")
for row in source_sheet:
  for cell in row:
    copy_to_sheet[cell.coordinate].value = cell.value
copy_to_wb.save(str(filename1))

如果您只想读取值并将其复制到新工作表中,是否可以改为使用pandas执行此操作?

。尝试读取excel和写入excel命令

file_name= r"path"

#Read 
df= (pd.read_excel(io=file_name,sheet_name='name'))

#process required data

#write to new work book or sheet
df.to_excel( file_name ,sheet_name= 'name')

openpyxl文档中介绍了这一点。它没有复制公式单元格值。它显示空值