|
@@ -51,7 +51,7 @@ def f_upload_file(save_path) -> str:
|
|
|
print('fail with unknown error: {}'.format(e))
|
|
|
|
|
|
|
|
|
-def f_doc_export(token: str) -> str:
|
|
|
+def f_doc_export(token: str, data: object) -> str:
|
|
|
|
|
|
app_id = BaseConfig.app_id
|
|
|
app_secret = BaseConfig.app_secret
|
|
@@ -124,19 +124,24 @@ def f_doc_export(token: str) -> str:
|
|
|
save_path = os.path.join(word_save_dir, file_name)
|
|
|
with open(save_path, "wb") as f:
|
|
|
f.write(response3.file.read())
|
|
|
+ time.sleep(2)
|
|
|
|
|
|
|
|
|
- doc = Document(save_path)
|
|
|
- placeholder = ""
|
|
|
- for paragraph in doc.paragraphs:
|
|
|
- if not placeholder in paragraph.text:
|
|
|
- continue
|
|
|
-
|
|
|
- for run in paragraph.runs:
|
|
|
- run.text = run.text.replace(placeholder, "")
|
|
|
- table = doc.add_table(rows=1, cols=[])
|
|
|
- paragraph._element.addnext(table._element)
|
|
|
- doc.save(save_path)
|
|
|
+ if data is not None:
|
|
|
+ doc = Document(save_path)
|
|
|
+ placeholder = ""
|
|
|
+ for paragraph in doc.paragraphs:
|
|
|
+ if not placeholder in paragraph.text:
|
|
|
+ continue
|
|
|
+
|
|
|
+ for run in paragraph.runs:
|
|
|
+ run.text = run.text.replace(placeholder, "")
|
|
|
+
|
|
|
+ table = doc.add_table(rows=1, cols=[])
|
|
|
+
|
|
|
+ paragraph._element.addnext(table._element)
|
|
|
+ doc.save(save_path)
|
|
|
+ time.sleep(2)
|
|
|
|
|
|
word_download_url = f_upload_file(save_path)
|
|
|
|