This commit is contained in:
512song committed 2023-04-10 11:06:38 +00:00
1 parent 1a3c492710
commit 62073b8e4b
1 file changed
+81 -21
+81 -21
View File
@@ -444,27 +444,12 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 42, "execution_count": null,
"id": "88d84849-5b98-48cb-86b1-e96757a8615f", "id": "88d84849-5b98-48cb-86b1-e96757a8615f",
"metadata": { "metadata": {
"execution": {
"iopub.execute_input": "2023-01-05T05:09:41.478369Z",
"iopub.status.busy": "2023-01-05T05:09:41.477814Z",
"iopub.status.idle": "2023-01-05T05:11:07.156560Z",
"shell.execute_reply": "2023-01-05T05:11:07.155155Z",
"shell.execute_reply.started": "2023-01-05T05:09:41.478316Z"
},
"tags": [] "tags": []
}, },
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"/tmp/tmp0tguht7x\n"
]
}
],
"source": [ "source": [
"from pdf2image import convert_from_path, convert_from_bytes\n", "from pdf2image import convert_from_path, convert_from_bytes\n",
"import os,sys\n", "import os,sys\n",
@@ -721,8 +706,7 @@
"\n", "\n",
"context['info'] = list1\n", "context['info'] = list1\n",
"\n", "\n",
"tpl.render(dict1)\n", "tpl.render(dict1)tpl.save('file/test1.docx')"
"tpl.save('file/test1.docx')"
] ]
}, },
{ {
@@ -741,6 +725,82 @@
"print('转换完成')" "print('转换完成')"
] ]
}, },
{
"cell_type": "markdown",
"id": "d2569395-1010-4cc0-8cc8-54bf3c73e01c",
"metadata": {},
"source": [
"### word使用模板生成钥匙扣标签"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "d05d85d2-5229-446e-bfff-1f0feb8b7f09",
"metadata": {
"execution": {
"iopub.execute_input": "2023-04-10T10:04:32.991821Z",
"iopub.status.busy": "2023-04-10T10:04:32.991387Z",
"iopub.status.idle": "2023-04-10T10:04:34.154437Z",
"shell.execute_reply": "2023-04-10T10:04:34.153707Z",
"shell.execute_reply.started": "2023-04-10T10:04:32.991783Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"13\n"
]
}
],
"source": [
"import openpyxl\n",
"from docxtpl import DocxTemplate,InlineImage\n",
"\n",
"wb = openpyxl.load_workbook('file/杨庙社区分组情况表 .xlsx')\n",
"sheet = wb.active\n",
"sheet = wb.active\n",
"data1 =list(sheet.values)\n",
"\n",
"del data1[0]\n",
"page = len(data1)//30\n",
"print(page)\n",
"dict1 = {}\n",
"tpl = DocxTemplate(\"file/钥匙扣模板.docx\")\n",
"for p in range(0,page): \n",
" n = 0\n",
" for i in range(1,7):\n",
" for j in range(1,6):\n",
" dict1[f'name_{i}_{j}'] = data1[30*p+n][3]\n",
" dict1[f'fenzu_{i}_{j}'] = data1[30*p+n][1]+'组'\n",
" dict1[f'bh_{i}_{j}'] = data1[30*p+n][2]\n",
" n = n+1\n",
" #print(dict1)\n",
" tpl.render(dict1)\n",
" tpl.save(f'file/钥匙扣{p+1}.docx') \n",
"dict2 = {}\n",
"n =390\n",
"while n < 395:\n",
" for i in range(1,7):\n",
" for j in range(1,6):\n",
" if n < 395:\n",
" dict2[f'name_{i}_{j}'] = data1[n][3]\n",
" dict2[f'fenzu_{i}_{j}'] = data1[n][1]+'组'\n",
" dict2[f'bh_{i}_{j}'] = data1[n][2]\n",
" else:\n",
" dict2[f'name_{i}_{j}'] = ''\n",
" dict2[f'fenzu_{i}_{j}'] = ''\n",
" dict2[f'bh_{i}_{j}'] = ''\n",
" n = n+1\n",
"\n",
"tpl.render(dict2)\n",
"tpl.save(f'file/钥匙扣{page+1}.docx') \n",
" \n"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "8a555d4f-8b2c-4f2c-af7e-fe8dfbd33f5f", "id": "8a555d4f-8b2c-4f2c-af7e-fe8dfbd33f5f",
@@ -1101,7 +1161,7 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python 3 (ipykernel)",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@@ -1115,7 +1175,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.8.10" "version": "3.10.6"
} }
}, },
"nbformat": 4, "nbformat": 4,