|
|
@@ -1,17 +1,18 @@ |
|
|
|
import os |
|
|
|
import docx |
|
|
|
import requests |
|
|
|
import mysql_pool |
|
|
|
from pymysql.converters import escape_string |
|
|
|
import xlsxwriter |
|
|
|
import uuid |
|
|
|
|
|
|
|
|
|
|
|
def read_docx(file_path): |
|
|
|
mysql = mysql_pool.ConnMysql() |
|
|
|
# print(os.path.abspath('丽水市本级信息化项目建设方案模板.docx')) |
|
|
|
# # 通过url获取文件 http://jobapi.ningdatech.com/prometheus-yw_file_service/files/20240116/5a75cb43d17d4f1589d455d21547ab0c.doc |
|
|
|
# url = "http://jobapi.ningdatech.com/prometheus-yw_file_service/files/20240919/669f323c5c824f89a34bf04a66105902.doc" |
|
|
|
# file_name = "丽水市本级信息化项目建设方案模板.docx" |
|
|
|
# file_path = os.path.join("temp", file_name) |
|
|
|
excel_path = f"/Users/kebobo/fsdownload/dup_check/temp/{uuid.uuid4()}.xls" |
|
|
|
try: |
|
|
|
# r = requests.get(url) |
|
|
|
# with open(file_path, "wb") as code: |
|
|
@@ -63,18 +64,36 @@ def read_docx(file_path): |
|
|
|
feature_name = para.text |
|
|
|
|
|
|
|
# 使用next函数逐个获取元素 |
|
|
|
# for key, value in feature_map.items(): |
|
|
|
# if key != "3.1.2 建设内容" and key != "": |
|
|
|
# print(f"Key: {key}, Value: {value}") |
|
|
|
# # 将功能描述入库 |
|
|
|
# mysql.sql_change_msg( |
|
|
|
# """insert into user_history_module_data(xmmc,gnmc,gnms,line, remark) value("%s", "%s", "%s", "%s", "%s")""" % ( |
|
|
|
# escape_string(xmmc), escape_string(key), escape_string(value), "", "自动拆解导入")) |
|
|
|
|
|
|
|
# 生成excel文件(兼容老版本, 减少改动量) |
|
|
|
workbook = xlsxwriter.Workbook(excel_path) |
|
|
|
worksheet = workbook.add_worksheet("Sheet1") |
|
|
|
worksheet.write('A1', '项目名称') |
|
|
|
worksheet.write('B1', escape_string(xmmc)) |
|
|
|
|
|
|
|
i = 0 |
|
|
|
for key, value in feature_map.items(): |
|
|
|
if key != "3.1.2 建设内容" and key != "": |
|
|
|
print(f"Key: {key}, Value: {value}") |
|
|
|
# 将功能描述入库 |
|
|
|
mysql.sql_change_msg( |
|
|
|
"""insert into user_history_module_data(xmmc,gnmc,gnms,line, remark) value("%s", "%s", "%s", "%s", "%s")""" % ( |
|
|
|
escape_string(xmmc), escape_string(key), escape_string(value), "", "自动拆解导入")) |
|
|
|
i = i + 1 |
|
|
|
worksheet.write(f"A{i + 1}", '功能模块') |
|
|
|
worksheet.write(f"B{i + 1}", escape_string(key)) |
|
|
|
worksheet.write(f"C{i + 1}", '功能描述') |
|
|
|
worksheet.write(f"D{i + 1}", escape_string(value)) |
|
|
|
workbook.close() |
|
|
|
return excel_path |
|
|
|
|
|
|
|
|
|
|
|
finally: |
|
|
|
# os.remove(file_path) |
|
|
|
print("删除文件") |
|
|
|
# print("删除文件") |
|
|
|
print("转换完成") |
|
|
|
|
|
|
|
return "\n".join(content) |
|
|
|
|
|
|
|