要不说python 真是好用,代码简单资料多,随随便便抄点就能用
我需要excel的内容逐行输出到word内:然后汇总发出,
excel汇总方便快速,而word又是最终交付的内容,所以一个批量转化的工具就能方便快速实现。
或者
都是我需要交付的样子,
- import pandas as pd
- from docx import Document
-
- def main():
- excel_file = '1.xlsx'
- df = pd.read_excel(excel_file,sheet_name='Sheet1',header=None)
-
-
- word_file = '1.docx'
- doc = Document()
-
- for row in range(1,df.shape[0]):
- for column in range(df.shape[1]):
- text_1 = str(df.iat[0,column]) + ':'
-
- text_2 = str(df.iat[row,column])
- text = text_1 + text_2
- doc.add_paragraph(text)
-
- doc.save(word_file)
- if __name__ == "__main__":
- main()
20行代码直接搞定,只需要更新好一份文件然后剩下的就是运行excel to word
最后去word里手动调整格式就好啦。