def save_data(item, sheet): """ 数据保存 :param item: 数据 :param sheet: sheet名 :return: """ dfscores = pd.DataFrame(item) # 写入数据 encoding="utf-8-sig" 看情况而用哦 writer = pd.ExcelWriter("./veteran_move.xlsx", engine='openpyxl') book = openpyxl.load_workbook(writer.path) writer.book = book dfscores.to_excel(excel_writer=writer, sheet_name=sheet, index=None, header=False) writer.save() writer.close()
注意: 此方法只会不覆盖原有sheet,会增加新的sheet
合并sheet参考:https://www.cnblogs.com/itBlogToYpl/p/12691607.html
写入同一sheet参考:https://i.cnblogs.com/posts/edit;postId=13214305