python操作Excel
一、使用pandas操作Excel
import pandas as pd """ {"CFORDER": 1, "TEXT02": "充电式应急照明灯", "NUM01": 2}, """ CFORDER = '{"CFORDER": ' TEXT02 = ', "TEXT02": "' NUM01 = '", "NUM01":' # 读取Excel文件 df = pd.read_excel('工器具交接记录本.xls', sheet_name='输煤') # 聪= df.iloc[:, 0].astype(str) + '-' + df.iloc[:, 1].astype(str) + '-' + df.iloc[:, 2].astype(str)# print(聪) # 假设要合并的三列是'col1', 'col2', 'col3',通过'-'进行合并 c = CFORDER + df['序号'].astype(str) + TEXT02 + df['名称'].astype(str) + NUM01 + df['数量'].astype(str) + '},' print(c.tolist()) for i in c.tolist(): print(i) # 将合并后的列保存到新的Excel文件 # df.to_excel('merged_example.xlsx', index=False)

浙公网安备 33010602011771号