1、包导入
from openpyxl import Workbook from openpyxl import load_workbook from openpyxl.compat import range from openpyxl.utils import get_column_letter
2、数据处理
xlsfile = 'E:/NLP/0.数据列表_20181107.xlsx' wb = load_workbook(xlsfile) print(wb.sheetnames) ws3 = wb.create_sheet(title="Data") for row in range(0, 20): for col in range(0, 54): print(get_column_letter(col)) _ = ws3.cell(column=col, row=row, value="%s" % get_column_letter(col)) print(ws3['AA10'].value) wb.save(xlsfile)
def parseDoc(f): try: doc = docx.Document(f) sheetName = os.path.basename(f) sheetName = sheetName.replace(".docx","") print(sheetName) xlsfile = 'E:/NLP/0.数据列表_20181107.xlsx' wb = load_workbook(xlsfile) print(wb.sheetnames) ws3 = wb.create_sheet(title=sheetName) parag_num = 0 row = 1 ws3.cell(column=1, row=row, value="序号") ws3.cell(column=2, row=row, value="关键字") ws3.cell(column=3, row=row, value="条款名称") ws3.cell(column=4, row=row, value="备注") row = 1 + row for para in doc.paragraphs : print("----------------------------------------------------") print(para.text) ws3.cell(column=3, row=row, value="%s" % para.text) row = 1 + row print("----------------------------------------------------") parag_num += 1 print ('This document has ', parag_num, ' paragraphs') wb.save(xlsfile) except Exception as e: print("Error:",e) finally: print("OK")