20240828
This commit is contained in:
1 parent
11a1e51802
commit
724bf28fbf
12 files changed
+708
-446
No files matched your search
+52
-36
@@ -94,7 +94,7 @@
|
||||
"\n",
|
||||
"list1 = []\n",
|
||||
"filepath = '文本文件/'\n",
|
||||
"files = glob.glob(f'{filepath}*.txt')\n",
|
||||
"files = glob.glob(f'{filepath}*.md')\n",
|
||||
"for fn in files:\n",
|
||||
" with open(fn, \"r\") as f:\n",
|
||||
" data = f.readlines()\n",
|
||||
@@ -108,32 +108,19 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 36,
|
||||
"execution_count": null,
|
||||
"id": "14696c7a-d44e-4c99-9d28-a810d991ed20",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-07-29T09:38:17.617646Z",
|
||||
"iopub.status.busy": "2024-07-29T09:38:17.616877Z",
|
||||
"iopub.status.idle": "2024-07-29T09:38:17.699602Z",
|
||||
"shell.execute_reply": "2024-07-29T09:38:17.699000Z",
|
||||
"shell.execute_reply.started": "2024-07-29T09:38:17.617576Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"['10', '100', '101', '102', '103', '104', '105', '106', '107', '108', '109', '11', '110', '111', '112', '113', '114', '115', '116', '117', '118', '119', '12', '120', '121', '122', '123', '124', '125', '126', '127', '128', '129', '130', '131', '132', '133', '134', '135', '136', '137', '138', '139', '14', '140', '141', '142', '143', '144', '145', '146', '147', '148', '149', '15', '150', '151', '152', '153', '154', '155', '156', '157', '158', '159', '16', '160', '161', '162', '163', '164', '165', '166', '167', '168', '169', '17', '170', '171', '173', '174', '175', '176', '177', '178', '179', '18', '180', '181', '182', '183', '184', '185', '186', '187', '188', '189', '19', '190', '191', '192', '193', '195', '198', '2', '20', '200', '201', '203', '204', '209', '21', '212', '213', '214', '22', '221', '222', '227', '228', '23', '230', '232', '24', '242', '243', '245', '246', '248', '249', '25', '251', '254', '255', '26', '27', '276', '28', '29', '290', '293', '3', '30', '304', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '6', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '7', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '8', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '9', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99']\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import glob\n",
|
||||
"import os,shutil\n",
|
||||
"from pathlib import Path\n",
|
||||
"import re\n",
|
||||
"from docx import Document\n",
|
||||
"import openpyxl\n",
|
||||
"from docxtpl import DocxTemplate,InlineImage\n",
|
||||
"from docx.shared import Mm\n",
|
||||
"\n",
|
||||
"def find_all_numbers(text):\n",
|
||||
" return re.findall(r'\\d+', text)\n",
|
||||
@@ -152,13 +139,16 @@
|
||||
" result = pattern.sub(lambda x: f\"{{{{ img_{x.group(0)} }}}}\", text)\n",
|
||||
" \n",
|
||||
" return result\n",
|
||||
"doc = Document()\n",
|
||||
"#doc = Document()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"list1 = []\n",
|
||||
"filepath = '文本文件/'\n",
|
||||
"files = glob.glob(f'{filepath}*.txt')\n",
|
||||
"for fn in files:\n",
|
||||
" p = Path(fn)\n",
|
||||
" with open(fn, \"r\") as f:\n",
|
||||
" list1 = []\n",
|
||||
" doc = Document()\n",
|
||||
" paragraph3 = doc.add_paragraph()\n",
|
||||
" data = f.readlines()\n",
|
||||
" for s in data:\n",
|
||||
@@ -173,23 +163,27 @@
|
||||
" list1.sort()\n",
|
||||
" #paragraph3 = doc.add_paragraph()\n",
|
||||
" paragraph3.add_run(ss.replace('\\r', ''))\n",
|
||||
" \n",
|
||||
"print(list1)\n",
|
||||
"doc.save('槐荫堂9.docx')"
|
||||
" print(p.stem)\n",
|
||||
" print(list1)\n",
|
||||
" if len(list1) >0:\n",
|
||||
" #paragraph3 = doc.add_paragraph()\n",
|
||||
" #paragraph3.add_run(ss.replace('\\r', ''))\n",
|
||||
" doc.save(f'./templete/{p.stem}.docx')\n",
|
||||
" dict1 = {}\n",
|
||||
" tpl = DocxTemplate(f'./templete/{p.stem}.docx')\n",
|
||||
" for item in list1:\n",
|
||||
" dict1['img_'+str(item)] = InlineImage(tpl, image_descriptor=f'./img/{str(item)}.jpg',width=Mm(4))\n",
|
||||
" tpl.render(dict1)\n",
|
||||
" tpl.save(f'./docx/{p.stem}.docx')\n",
|
||||
"#print(list1)\n",
|
||||
"#doc.save('离垢居谈棋.docx')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 37,
|
||||
"execution_count": null,
|
||||
"id": "8d3f1a7a-1322-48b5-9b14-c7ba8f38bacb",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-07-29T09:38:34.133722Z",
|
||||
"iopub.status.busy": "2024-07-29T09:38:34.132997Z",
|
||||
"iopub.status.idle": "2024-07-29T09:38:36.600350Z",
|
||||
"shell.execute_reply": "2024-07-29T09:38:36.599803Z",
|
||||
"shell.execute_reply.started": "2024-07-29T09:38:34.133659Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
@@ -200,13 +194,13 @@
|
||||
"\n",
|
||||
"dict1 = {}\n",
|
||||
"\n",
|
||||
"tpl = DocxTemplate(\"槐荫堂9.docx\")\n",
|
||||
"tpl = DocxTemplate(\"离垢居谈棋.docx\")\n",
|
||||
"for item in list1: \n",
|
||||
" dict1['img_'+str(item)] = InlineImage(tpl, image_descriptor=f'./img/{str(item)}.jpg',width=Mm(4))\n",
|
||||
" dict1['img_'+str(item)] = InlineImage(tpl, image_descriptor=f'./img/黑先/{str(item)}.jpg',width=Mm(4))\n",
|
||||
"#dict1['img_radar'] = InlineImage(tpl, image_descriptor=dict1['radar'])\n",
|
||||
"\n",
|
||||
"tpl.render(dict1)\n",
|
||||
"tpl.save('槐荫堂第九卷.docx')"
|
||||
"tpl.save('离垢居谈棋(黑先).docx')"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -215,6 +209,28 @@
|
||||
"id": "efc716f8-0ec7-4e0d-9960-676764965be4",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import openpyxl\n",
|
||||
"from docxtpl import DocxTemplate,InlineImage\n",
|
||||
"from docx.shared import Mm\n",
|
||||
"\n",
|
||||
"dict1 = {}\n",
|
||||
"\n",
|
||||
"tpl = DocxTemplate(\"离垢居谈棋.docx\")\n",
|
||||
"for item in list1: \n",
|
||||
" dict1['img_'+str(item)] = InlineImage(tpl, image_descriptor=f'./img/白先/{str(item)}.jpg',width=Mm(4))\n",
|
||||
"#dict1['img_radar'] = InlineImage(tpl, image_descriptor=dict1['radar'])\n",
|
||||
"\n",
|
||||
"tpl.render(dict1)\n",
|
||||
"tpl.save('离垢居谈棋(白先).docx')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "fcfd6cab-d83f-4b79-9a0b-05570ca6cecb",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user