{"id":512,"date":"2023-09-04T06:25:17","date_gmt":"2023-09-03T22:25:17","guid":{"rendered":"http:\/\/blog.yuekegu.com\/?p=512"},"modified":"2023-09-04T06:25:17","modified_gmt":"2023-09-03T22:25:17","slug":"%e6%96%87%e4%bb%b6%e6%89%b9%e9%87%8f%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"https:\/\/book.yuekegu.com\/index.php\/2023\/09\/04\/%e6%96%87%e4%bb%b6%e6%89%b9%e9%87%8f%e5%a4%84%e7%90%86\/","title":{"rendered":"\u6587\u4ef6\u6279\u91cf\u5904\u7406"},"content":{"rendered":"\n<ol class=\"wp-block-list\"><li>\u6279\u91cf\u91cd\u547d\u540d\u6587\u4ef6<br>\u5728\u8fd9\u91cc\u6700\u6838\u5fc3\u7684\u5c31\u662fos.listdir(\uff09\uff0c\u8fd9\u4e2a\u51fd\u6570\u53ef\u4ee5\u8fd4\u56de\u6587\u4ef6\u5939\u91cc<strong>\u6240\u6709\u6587\u4ef6\u7684\u6587\u4ef6\u540d.<\/strong> \u6709\u4e86\u8fd9\u4e2a\u6211\u4eec\u624d\u80fd\u8fdb\u884c\u5176\u4ed6\u64cd\u4f5c\uff0c\u5305\u62ec\u904d\u5386\u3002<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">import sys\nimport os                                 #OS\u5e93\u662f\u6587\u4ef6\u5904\u7406\u4e2d\u7ecf\u5e38\u7528\u5230\u7684\u5e93\nimport comtypes.client\n#\u5355\u4e2aword\u8f6cPDF\nwdFormatPDF = 17\naddr = 'C:\\\\Users\\\\wang\\\\Desktop\\\\G13-a\\\\'   #\u6587\u4ef6\u5939\u7684\u7edd\u5bf9\u8def\u5f84\n\nnames = os.listdir(addr)                        # \u8bfb\u53d6\u6587\u4ef6\u5939\u4e0b\u7684\u6240\u6709\u6587\u4ef6\u540d\n\n#\u8fdb\u884c\u904d\u5386\nfor name in names:                         \n    old_name = addr + name                 #\u6ce8\u610frename\u51fd\u6570\u91cc\u8981\u653e\u5b8c\u6574\u7684\u8def\u5f84\uff0c\u4e0d\u80fd\u53ea\u653e\u65b0\u65e7\u540d\u5b57\n    new_name = addr + name[:13]            #\u8fd9\u662f\u5f53\u65f6\u7532\u65b9\u8981\u6c42\u53bb\u9664\u540e\u7f00\uff0c\u6545\u53ea\u53d6\u65e7\u9898\u76ee\u7684\u524d13\u4f4d\n    os.rename (old_name, new_name)      <\/pre>\n\n\n\n<p>2. \u6587\u4ef6\u5206\u7c7b<br>\u5728tender\u7684\u6700\u540e\u63d0\u4ea4\u65f6\uff0c\u7532\u65b9\u8981\u6c42\u6309\u5de5\u4f5c\u7f16\u53f7\u8fdb\u884c\u63d0\u4ea4\uff0c\u8fd9\u91cc\u9700\u8981\u6309\u7167register\u91cc\u7684\u7f16\u53f7\u8fdb\u884c\u5206\u7c7b\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u8bfb\u53d6\u6587\u6863\uff0c\u89c2\u5bdf\u6570\u636e\u5f62\u5f0f<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import pandas as pd\ndf = pd.read_excel('C:\\\\Users\\\\wang\\\\Desktop\\\\DCC_file.xlsx')<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-fa0c88d04d78bd78521e79889a073014_720w.jpg\" alt=\"\"\/><figcaption>\u901a\u8fc7\u8bfb\u53d6register\u53d1\u73b0\u6211\u4eec\u9700\u8981\u6839\u636e\u201cDCC\u201d\u5217\u8fdb\u884c\u5206\u7c7b\uff0c\u800c\u5bf9\u5e94\u7684\u6587\u4ef6\u540d\u5728\u201cNATIVE\u201d\u5217<\/figcaption><\/figure>\n\n\n\n<p>\u63a5\u4e0b\u6765\uff0c\u9700\u8981\u5b8c\u6210\u7684\u5c31\u662f\uff1a\uff081\uff09 \u83b7\u53d6\u6bcf\u4e00\u7c7bDCC\u7f16\u7801\u4e0b\u7684\u6587\u4ef6\u540d\uff1b\uff082\uff09\u590d\u5236\u5bf9\u5e94\u6587\u4ef6\u540d\u81f3\u76f8\u5e94\u6587\u4ef6\u5939\u3002<\/p>\n\n\n\n<p>\u5176\u4e2d\u6587\u6863\u7684\u590d\u5236\u79fb\u52a8\u4e3b\u8981\u4f9d\u9760shutil\u6a21\u5757.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import os\nimport shutil \n\nfile_dir = r'C:\\Users\\wang\\Desktop\\All file'     #\u8fd9\u91cc\u662f\u5b58\u653e\u6240\u6709\u6587\u4ef6\u7684\u4f4d\u7f6e\uff0c\u5b83\u4eec\u9700\u8981\u8fdb\u884c\u5206\u7c7b\n\nos.chdir(file_dir)    \n\nnumb = '10-01902-0002-050'   #\u8fd9\u662f\u5176\u4e2d\u4e00\u4e2aDCC \u7f16\u7801\nos.mkdir(numb)          #\u5728\u5f53\u524d\u8def\u5f84\u4e0b\u521b\u5efa\u5bf9\u5e94\u7684\u6587\u4ef6\u5939 \n\nfilenames = df.loc[(df['DCC']== numb)]['NATIVE']    #\u5229\u7528loc\u51fd\u6570\u7b5b\u9009\u51fa '10-01902-0002-050' \u5bf9\u5e94\u7684\u6240\u6709\u6587\u4ef6\u540d\n\n# \u8fd9\u91cc\u64cd\u4f5c\u662f\u56e0\u4e3aDC\u90e8\u95e8\u5728\u547d\u540d\u6587\u4ef6\u65f6\uff0cPdf\uff0c Word \u548cdrawing\u7684\u6587\u4ef6\u540d\u540e\u4e09\u4f4d\u5206\u522b\u662f\u201cP00\u201d,\u201cW00\u201d\u548c\u201cV00\u201d,\n# \u6240\u4ee5\u901a\u8fc7\u8fd9\u4e2a\uff0c\u4e3a\u5bf9\u5e94\u7684\u6587\u4ef6\u540d\u52a0\u4e0a\u5bf9\u5e94\u7684\u540e\u7f00\uff0c\u6765\u6784\u6210\u5b8c\u6574\u7684\u6587\u4ef6\u540d\n\nfor name in filenames:      \n \n    if name[-3] == 'X':\n        fname = name + '.xls'\n    if name[-3] == 'V':\n        fname = name + '.dgn'\n    if name[-3] == 'W':\n        fname = name + '.doc'\n    \n    if os.path.exists(fname) ==1:        #\u5224\u65ad\u6587\u4ef6\u662f\u5426\u5b58\u5728\n        shutil.copy(fname,numb)         #\u590d\u5236\u6587\u4ef6\u81f3\u6587\u4ef6\u5939\n    else:\n        print(fname)                     #\u8f93\u51fa\u4e0d\u5b58\u5728\u7684\u6587\u4ef6\u540d\uff0c\u7528\u6765\u68c0\u67e5<\/pre>\n\n\n\n<p>3. \u6279\u91cfWord\u8f6cPDF<\/p>\n\n\n\n<p>\u8fd9\u4e2a\u5f88\u5e38\u89c1\u7684\u9700\u6c42\uff0c\u9700\u8981\u5c06word\u8f6c\u4e3aPDF\uff0c\u4f46\u4f20\u7edf\u7684Adobe\u8f6cPDF\u9700\u8981\u4e00\u4e2a\u4e00\u4e2a\u70b9\uff0c\u6bd4\u8f83\u6162\uff0c\u800c\u7f51\u4e0a\u5927\u90e8\u5206\u6279\u91cf\u8f6cPDF\u7684\u8f6f\u4ef6\u57fa\u672c\u6536\u8d39\uff0c\u6240\u4ee5\u4e5f\u662f\u4e34\u65f6\u60f3\u8d77\u7528python\u5199\u4e2a\u5c0f\u7a0b\u5e8f\u3002<\/p>\n\n\n\n<p>\u8fd9\u91cc\u5462\uff0c\u5982\u524d\u9762\u63d0\u5230\u7684DC\u8981\u6c42\uff0c\u8f6c\u6362\u5f97\u5230\u7684PDF\uff0c\u540d\u5b57\u540e\u4e09\u4f4d\u9700\u8981\u65f6\u201cP00&#8243;, \u4f8b\u5982C860040001W00.doc \u8f6c\u6362\u540e\u7684PDF\u5e94\u8be5\u662f C860040001W00.pdf.<\/p>\n\n\n\n<p>\u6240\u4ee5\u8fd9\u91cc\u76ee\u6807\u6709\u4e24\u4e2a\uff1a<\/p>\n\n\n\n<p>\uff081\uff09 \u904d\u5386\uff0c\u4e5f\u5c31\u662f\u8fbe\u5230\u6279\u91cf\u5904\u7406\u7684\u76ee\u7684<\/p>\n\n\n\n<p>\uff082\uff09 \u91cd\u547d\u540d\u540e\u4e09\u4f4d\u4e3a\u201dP00&#8243;<\/p>\n\n\n\n<p>\u8fd9\u91cc\u7528\u5230\u7684\u5e93\u662f comtypes.client\uff0c\u7528\u5b83\u8bbf\u95eeCOM\u7ec4\u4ef6\u8fbe\u5230\u8f6cPDF\u7684\u76ee\u7684\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import sys\nimport os\nimport comtypes.client\n\nwdFormatPDF = 17\n\naddr = 'C:\\\\Users\\\\wang\\\\Desktop\\\\doc\\\\10-01902-0002-711\\\\' # \u76ee\u6807\u8def\u5f84\uff0c\u5b58\u653eword\u7684\u4f4d\u7f6e\n\ndoc_names = os.listdir(addr)  #\u8bfb\u53d6\u6587\u4ef6\u5939\u91cc\u6240\u6709\u6587\u4ef6\u7684\u540d\u5b57\npdf_names = []              #\u5c06\u7528\u6765\u5b58\u653e\u8f6c\u6362\u540ePDF\u7684\u540d\u5b57\n\n#\u5f00\u59cb\u904d\u5386\nfor name in doc_names:     \n    pdf_name = name[:10] +'P00.pdf'    #\u5b9e\u73b0\u6587\u4ef6\u540d\u8f6c\u6362\uff1aC860040001W00.doc \u5230 C860040001W00.pdf.\n    pdf_names.append(pdf_name)  #\u5b58\u653e\u65b0\u7684PDF\u6587\u6863\u6587\u4ef6\u540d\n    in_file = os.path.abspath(addr + name)  #\u6784\u9020\u5b8c\u6574\u8def\u5f84\u7684\u6587\u4ef6\u540d\n    out_file = os.path.abspath(addr + pdf_name)\n    word = comtypes.client.CreateObject('Word.Application')\n    doc = word.Documents.Open(in_file)\n    doc.SaveAs(out_file, FileFormat=wdFormatPDF)   #\u8f6c\u6362\u4e3aPDF\n    doc.Close()\n    word.Quit()<\/pre>\n\n\n\n<p>\u6709\u4e86\u8fd9\u4e9b\u5c0f\u7a0b\u5e8f\uff0c\u57fa\u672c\u53ef\u4ee5\u5904\u7406\u5de5\u4f5c\u4e2d\u7684\u6587\u6863\u64cd\u4f5c\u4e86\uff01\u611f\u8c22Python\u8ba9\u6211\u73b0\u5728\u6709\u65f6\u95f4\u559d\u5496\u5561\u5199\u6587\u7ae0\uff0c\u800c\u4e0d\u7528\u7ee7\u7eedclick\uff0cclick\uff0cclick.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6279\u91cf\u91cd\u547d\u540d\u6587\u4ef6\u5728\u8fd9\u91cc\u6700\u6838\u5fc3\u7684\u5c31\u662fos.listdir(\uff09\uff0c\u8fd9\u4e2a\u51fd\u6570\u53ef\u4ee5\u8fd4\u56de\u6587\u4ef6\u5939\u91cc\u6240\u6709\u6587\u4ef6\u7684\u6587\u4ef6\u540d. \u6709\u4e86\u8fd9\u4e2a\u6211\u4eec\u624d\u80fd\u8fdb\u884c\u5176\u4ed6\u64cd\u4f5c\uff0c\u5305\u62ec\u904d\u5386\u3002 import sys import os #OS\u5e93\u662f\u6587\u4ef6\u5904\u7406\u4e2d\u7ecf\u5e38\u7528\u5230\u7684\u5e93 import comtypes.client #\u5355\u4e2aword\u8f6cPDF wdFormatPDF = 17 addr = &#8216;C:\\\\Users\\\\wang\\\\Desktop\\\\G13-a\\\\&#8217; #\u6587\u4ef6\u5939\u7684\u7edd\u5bf9\u8def\u5f84 names = os.listdir(addr) # \u8bfb\u53d6\u6587\u4ef6\u5939\u4e0b\u7684\u6240\u6709\u6587\u4ef6\u540d #\u8fdb\u884c\u904d\u5386 for name in names: old_name = addr + name #\u6ce8\u610frename\u51fd\u6570\u91cc\u8981\u653e\u5b8c\u6574\u7684\u8def\u5f84\uff0c\u4e0d\u80fd\u53ea\u653e\u65b0\u65e7\u540d\u5b57 new_name = addr + name[:13] #\u8fd9\u662f\u5f53\u65f6\u7532\u65b9\u8981\u6c42\u53bb\u9664\u540e\u7f00\uff0c\u6545\u53ea\u53d6\u65e7\u9898\u76ee\u7684\u524d13\u4f4d os.rename (old_name, new_name) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-512","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/posts\/512","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/comments?post=512"}],"version-history":[{"count":0,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/posts\/512\/revisions"}],"wp:attachment":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/media?parent=512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/categories?post=512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/tags?post=512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}