小编Arp*_*rma的帖子

Python (openpyxl):将数据从一个 excel 文件放到另一个(模板文件)并用另一个名称保存,同时保留模板

我有一个名为 as的模板excel 文件,template.xlsx其中包含许多工作表。我想将数据从一个单独的.csv文件复制到template.xlsx(命名为data)的第一张纸中,并将新文件另存为,result.xlsx同时保留原始模板文件。

我想粘贴从第二排开始的数据data的表template.xlsx

这是我迄今为止开发的代码

import pandas as pd
from openpyxl.utils.dataframe import dataframe_to_rows
import openpyxl
from shutil import copyfile

template_file = 'template.xlsx' # Has a header in row 1 already which needs to be skipped while pasting data but it should be there in the output file
output_file = 'result.xlsx' 

copyfile(template_file, output_file)
df = pd.read_csv('input_file.csv') #The file which is to be pasted in the template …
Run Code Online (Sandbox Code Playgroud)

python excel shutil python-3.x openpyxl

7
推荐指数
1
解决办法
4482
查看次数

标签 统计

excel ×1

openpyxl ×1

python ×1

python-3.x ×1

shutil ×1