diff --git a/文件管理1.ipynb b/文件管理1.ipynb index 4f9eb4f..e2d3e5d 100755 --- a/文件管理1.ipynb +++ b/文件管理1.ipynb @@ -66,16 +66,9 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "id": "4a43668e-47ba-491f-a29c-e289885badb0", "metadata": { - "execution": { - "iopub.execute_input": "2022-08-05T09:28:50.166885Z", - "iopub.status.busy": "2022-08-05T09:28:50.166355Z", - "iopub.status.idle": "2022-08-05T09:28:50.380976Z", - "shell.execute_reply": "2022-08-05T09:28:50.379827Z", - "shell.execute_reply.started": "2022-08-05T09:28:50.166837Z" - }, "tags": [] }, "outputs": [], @@ -632,38 +625,18 @@ "cell_type": "code", "execution_count": null, "id": "b5e500b5-14d4-4417-8b5e-46df71a6b6b8", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "import json\n", "import re\n", - "filename = '症状对症处方选穴.json'\n", - "pattern = r'[\\d\\.]'\n", - "mo =r'[\\u4e00-\\u9fa5]+'\n", - "dict2 = {}\n", + "filename = 'file/ticemuban.json'\n", + "\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", - "for k,v in dict1.items():\n", - " m_title = v['title']\n", - " for k1,v1 in v['sub'].items():\n", - " sub_title = k1 \n", - " s = ''\n", - " for mx in v1: \n", - " s = s + mx\n", - " list1 = re.split(pattern, s)\n", - " list2 = []\n", - " for ss in list1:\n", - " if ss != '':\n", - " list3 = re.findall(mo,ss)\n", - " list2.append(list3)\n", - " \n", - " #print(m_title,sub_title,list2)\n", - " dict2.setdefault(m_title,{})\n", - " dict2[m_title][sub_title] = list2\n", - "filename = 'new_症状对症处方选穴.json'\n", - "with open(filename,'w') as fl:\n", - " json.dump(dict2, fl,ensure_ascii=False) \n", - "print('ok') \n", + "print(dict1)\n", " " ] }, @@ -677,36 +650,68 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "id": "9957a90c-7735-4224-b5b5-4a4b1b7688c9", "metadata": { + "execution": { + "iopub.execute_input": "2022-12-07T06:24:28.191719Z", + "iopub.status.busy": "2022-12-07T06:24:28.191155Z", + "iopub.status.idle": "2022-12-07T06:24:28.291897Z", + "shell.execute_reply": "2022-12-07T06:24:28.290876Z", + "shell.execute_reply.started": "2022-12-07T06:24:28.191671Z" + }, "tags": [] }, "outputs": [], "source": [ "import openpyxl\n", - "from docxtpl import DocxTemplate\n", + "from docxtpl import DocxTemplate,InlineImage\n", "\n", - "wb = openpyxl.load_workbook('file/火车餐厅人员信息表1.xlsx')\n", - "sheet = wb.active\n", - "# sheets = wb.sheetnames\n", "list1 = []\n", - "context = {}\n", - "for n in range(2, sheet.max_row+1):\n", - " dict1 = {}\n", - " dict1['xh'] = sheet.cell(n,1).value\n", - " dict1['xm'] = sheet.cell(n,2).value\n", - " dict1['sfzhm'] = sheet.cell(n,3).value\n", - " dict1['dh'] = sheet.cell(n,4).value\n", - " dict1['cx'] = sheet.cell(n,5).value\n", - " dict1['xzdz'] = sheet.cell(n,6).value\n", - " list1.append(dict1)\n", + "filename = 'file/ticemuban.json'\n", + "tpl = DocxTemplate(\"file/体测报告模板.docx\")\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "dict1['img_radar'] = InlineImage(tpl, image_descriptor=dict1['radar'])\n", + "list1.append(dict1)\n", + "\n", "context['info'] = list1\n", - "tpl = DocxTemplate(\"file/火车餐厅人员信息表.docx\")\n", - "tpl.render(context)\n", + "\n", + "tpl.render(dict1)\n", "tpl.save('file/test1.docx')" ] }, + { + "cell_type": "code", + "execution_count": 36, + "id": "42122edc-eb77-4cfc-bcd8-3f844ffcca58", + "metadata": { + "execution": { + "iopub.execute_input": "2022-12-07T07:30:29.738226Z", + "iopub.status.busy": "2022-12-07T07:30:29.737684Z", + "iopub.status.idle": "2022-12-07T07:30:30.656573Z", + "shell.execute_reply": "2022-12-07T07:30:30.655231Z", + "shell.execute_reply.started": "2022-12-07T07:30:29.738176Z" + }, + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "转换完成\n" + ] + } + ], + "source": [ + "from subprocess import Popen\n", + "\n", + "file = 'file/test1.docx'\n", + "Popen(['abiword', '-t', 'pdf', file]).communicate()\n", + "print('转换完成')" + ] + }, { "cell_type": "markdown", "id": "8a555d4f-8b2c-4f2c-af7e-fe8dfbd33f5f",