This commit is contained in:
512song committed 2024-04-11 11:35:29 +08:00
1 parent 55437a8820
commit 0d4e4454b4
2 files changed
+74 -130

No files matched your search

+49 -12
View File
@@ -638,24 +638,23 @@
"for i, table in enumerate(doc.tables):\n",
" print(f\"Table {i}:\")\n",
" for row in table.rows:\n",
" print(type(row))\n",
" #print(type(row))\n",
" for cell in row.cells:\n",
" if cell.text =='序号':\n",
" print(cell.text, end=\" | \")\n",
" print(cell.text, end=\" | \")\n",
" print() # 每一行结束后换行\n"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "c3ccfa25-f31c-46d4-bfd0-903832cc620d",
"execution_count": 36,
"id": "fe615899-447e-489a-9f0d-90a239031e7c",
"metadata": {
"execution": {
"iopub.execute_input": "2024-04-10T11:08:13.063231Z",
"iopub.status.busy": "2024-04-10T11:08:13.063012Z",
"iopub.status.idle": "2024-04-10T11:08:25.173599Z",
"shell.execute_reply": "2024-04-10T11:08:25.173048Z",
"shell.execute_reply.started": "2024-04-10T11:08:13.063213Z"
"iopub.execute_input": "2024-04-11T03:04:05.540001Z",
"iopub.status.busy": "2024-04-11T03:04:05.539789Z",
"iopub.status.idle": "2024-04-11T03:04:19.212186Z",
"shell.execute_reply": "2024-04-11T03:04:19.211594Z",
"shell.execute_reply.started": "2024-04-11T03:04:05.539987Z"
},
"tags": []
},
@@ -675,14 +674,52 @@
"doc = docx.Document(r\"data/中国石化北海炼化有限责任公司2023年职业体检团体报告.docx\")\n",
"list2 = []\n",
"for i, table in enumerate(doc.tables):\n",
" list1= []\n",
" for row in table.rows:\n",
" list3 = []\n",
" for cell in row.cells:\n",
" if cell.text.strip()!='':\n",
" list3.append(cell.text)\n",
" list1.append(list3)\n",
" if list1[0][0] =='序号':\n",
" for n in range(1,len(list1)):\n",
" list2.append(list1[n])\n",
"filename = '北海职业体测报告情况表2024.xlsx'\n",
"wb = openpyxl.Workbook()\n",
"sheet = wb.active\n",
"\n",
"for row in list2:\n",
" sheet.append(row)\n",
" \n",
" if table.cell(0, 0).text == '序号':\n",
"wb.save(filename)\n",
"print('ok!')\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c3ccfa25-f31c-46d4-bfd0-903832cc620d",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import docx\n",
"import json\n",
"import openpyxl\n",
"doc = docx.Document(r\"data/中国石化北海炼化有限责任公司2023年健康体检团体报告.docx\")\n",
"list2 = []\n",
"for i, table in enumerate(doc.tables):\n",
" \n",
" if table.cell(0, 0).text == '序号' or table.cell(0, 1).text == '序号':\n",
" #print(f\"Table {i}:\")\n",
" \n",
" for row in table.rows:\n",
" list1= []\n",
" for cell in row.cells:\n",
" list1.append(cell.text)\n",
" if cell.text.strip()!='':\n",
" list1.append(cell.text)\n",
" if list1[0] !='序号':\n",
" list2.append(list1)\n",
"filename = '北海体测报告情况表2024.xlsx'\n",