{"id":335,"date":"2018-11-13T12:26:32","date_gmt":"2018-11-13T04:26:32","guid":{"rendered":"https:\/\/www.yinyubo.cn\/?p=335"},"modified":"2022-05-17T09:45:08","modified_gmt":"2022-05-17T01:45:08","slug":"pyinstaller","status":"publish","type":"post","link":"https:\/\/www.yinyubo.com\/?p=335","title":{"rendered":"\u89e3\u51b3pyinstaller\u4e0d\u517c\u5bb9python-docx\u7684\u65b9\u6cd5"},"content":{"rendered":"<h1>\u9700\u6c42<\/h1>\n<p><span style=\"color: #ff6600;\"><strong>python-docx<\/strong><\/span>\u662f\u4e00\u4e2apython\u7684\u8bfb\u5199word\u7684\u5e93\uff0c\u53ef\u4ee5\u7528\u6765\u8bfb\u5199word\u6587\u6863\uff0c\u5411word\u6587\u6863\u91cc\u63d2\u5165\u8868\u683c\u3002\u4f8b\u5982\u5982\u4e0b\u7684\u64cd\u4f5cdocx\u7684\u4ee3\u7801\uff1a<\/p>\n<pre class=\"lang:python decode:true EnlighterJSRAW\" data-enlighter-language=\"python\"><code class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">from docx import Document\ndocument = Document()\ndocument.add_heading('Document Title', 0)\np = document.add_paragraph('A plain paragraph having some ')\np.add_run('bold').bold = True\np.add_run(' and some ')\np.add_run('italic.').italic = True\ndocument.add_heading('Heading, level 1', level=1)\ndocument.add_paragraph('Intense quote', style='Intense Quote')\ndocument.add_paragraph(\n    'first item in unordered list', style='List Bullet'\n)\ndocument.add_paragraph(\n    'first item in ordered list', style='List Number'\n)\nrecords = (\n    (3, '101', 'Spam'),\n    (7, '422', 'Eggs'),\n    (4, '631', 'Spam, spam, eggs, and spam')\n)\ntable = document.add_table(rows=1, cols=3,style='Light Grid Accent 1')\nhdr_cells = table.rows[0].cells\nhdr_cells[0].text = 'Qty'\nhdr_cells[1].text = 'Id'\nhdr_cells[2].text = 'Desc'\nfor qty, id, desc in records:\n    row_cells = table.add_row().cells\n    row_cells[0].text = str(qty)\n    row_cells[1].text = id\n    row_cells[2].text = desc\ndocument.add_page_break()\ndocument.save('demo.docx')<\/code><\/pre>\n<p>\u00a0<br \/><span style=\"color: #ff6600;\"><strong>pyinstaller<\/strong><\/span>\u662fpython\u6253\u5305\u6210exe\u7684\u5de5\u5177\u3002<br \/>\u5f53\u6211\u4eec\u8981\u628a\u7f16\u5199\u597d\u7684\u4f7f\u7528\u4e86python-docx\u7684\u7a0b\u5e8f\u6253\u5305\u65f6\uff0c\u95ee\u9898\u6765\u4e86\u3002<br \/>\u9996\u5148\uff0c\u547d\u4ee4\u884c\u6253\u5305<\/p>\n<pre class=\"lang:python decode:true\"><code class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">pyinstaller -D word_generate.py<\/code><\/pre>\n<p>\u8fd9\u4e2a\u6ca1\u95ee\u9898\uff0cword_generate.py\u662f\u6211\u7684\u4e3b\u7a0b\u5e8f\u6587\u4ef6\u3002\u8fd9\u91cc\u6253\u5305\u4e5f\u4e0d\u62a5\u9519\u3002\u4f46\u662f\u4e0b\u4e00\u6b65\uff0c\u8fd0\u884c\u7684\u65f6\u5019\uff0cduang~\u62a5\u9519\u4e86\uff0c\u62a5\u9519\u5982\u4e0b\uff1a<\/p>\n<pre class=\"lang:python decode:true \"><code class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">C:\\lzw_programming\\jira_test\\dist\\word_generate&gt;word_generate.exe\nTraceback (most recent call last):\n  File \"word_generate.py\", line 4, in &lt;module&gt;\n  File \"site-packages\\docx\\api.py\", line 25, in Document\n  File \"site-packages\\docx\\opc\\package.py\", line 116, in open\n  File \"site-packages\\docx\\opc\\pkgreader.py\", line 32, in from_file\n  File \"site-packages\\docx\\opc\\phys_pkg.py\", line 31, in __new__\ndocx.opc.exceptions.PackageNotFoundError: Package not found at 'C:\\LZW_PR~1\\JIRA_T~1\\dist\\WORD_G~1\\docx\\templates\\default.docx'\n[4232] Failed to execute script word_generate<\/code><\/pre>\n<h1>\u89e3\u51b3\u65b9\u6cd5<\/h1>\n<p>\u5728\u7ffb\u4e86\u5f88\u591a\u5730\u65b9\u4e4b\u540e\uff0c\u7ec8\u4e8e\u627e\u5230\u4e86\u89e3\u51b3\u65b9\u6cd5\u3002\u5f88\u7b80\u5355\u3002\u589e\u52a0\u4e00\u4e2ahook-docx.py\u6587\u4ef6\u5728PyInstaller\\hooks\u76ee\u5f55\u4e0b\u5c31\u53ef\u4ee5\u4e86\u3002\u4e0b\u9762\u662f\u6587\u4ef6\u5185\u5bb9\u4ee5\u53ca\u8def\u5f84<\/p>\n<pre class=\"lang:python decode:true\"><code class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">#-----------------------------------------------------------------------------\n# Copyright (c) 2018-2018, PyInstaller Development Team.\n#\n# Distributed under the terms of the GNU General Public License with exception\n# for distributing bootloader.\n#\n# The full license is in the file COPYING.txt, distributed with this software.\n#-----------------------------------------------------------------------------\nfrom PyInstaller.utils.hooks import collect_data_files\ndatas = collect_data_files(\"docx\")\n<\/code><\/pre>\n<p>\u8def\u5f84\uff1a<br \/><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-336 size-full\" src=\"https:\/\/yinyubo-1257235934.cos.ap-nanjing.myqcloud.com\/content\/hook-docx\u6587\u4ef6.png\" alt=\"\" width=\"711\" height=\"305\" \/><\/p>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9700\u6c42 python-docx\u662f\u4e00\u4e2apython\u7684\u8bfb\u5199word\u7684\u5e93\uff0c\u53ef\u4ee5\u7528\u6765\u8bfb\u5199word\u6587\u6863\uff0c\u5411word\u6587\u6863\u91cc\u63d2 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":337,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-335","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/335","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=335"}],"version-history":[{"count":2,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/335\/revisions"}],"predecessor-version":[{"id":939,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/335\/revisions\/939"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/media\/337"}],"wp:attachment":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}