{"id":1071,"date":"2013-07-12T18:17:59","date_gmt":"2013-07-12T10:17:59","guid":{"rendered":"http:\/\/www.gejoin.com\/?p=1071"},"modified":"2013-07-12T18:17:59","modified_gmt":"2013-07-12T10:17:59","slug":"%e4%bd%bf%e7%94%a8python%e5%af%b9excel%e8%bf%9b%e8%a1%8c%e8%af%bb%e5%86%99","status":"publish","type":"post","link":"https:\/\/www.mujins.com\/?p=1071","title":{"rendered":"\u4f7f\u7528python\u5bf9excel\u8fdb\u884c\u8bfb\u5199"},"content":{"rendered":"<p>\u5de5\u4f5c\u5468\u62a5\u6216\u662f\u65e5\u62a5\uff0c\u6708\u62a5\uff0c\u662f\u6bcf\u4e00\u4e2aIT\u6c11\u5de5\u7684\u75db\u5427\uff0c\u4e00\u5929\u5fd9\u788c\u4e0b\u6765\u8fd8\u8981\u88ab\u50ac\u7740\u5199\u5468\u62a5&#8230;\u8fd8\u597d\uff0c\u6211\u4eec\u7684\u5468\u62a5\u6570\u636e\u662f<br \/>\n\u4ece\u9879\u76ee\u7ba1\u7406\u5e73\u53f0(\u7c7b\u4f3cmantis\uff09\u4e0a\u5bfc\u51fa\u6765\u7684\u3002\u5df2\u7ecf\u6709\u524d\u8f88\u4f7f\u7528Perl\u5199\u4e86\u5c06\u5bfc\u51fa\u7684excel\u6570\u636e\u8fdb\u884c\u7b5b\u9009\u751f\u6210\u65e2\u5b9a\u7684<br \/>\nEXCEL\u683c\u5f0f\u7684\u6587\u6863\u3002<\/p>\n<p><a href=\"https:\/\/www.gigiwangs.com\/wp-content\/uploads\/2012\/07\/python-logo.png\" data-lightbox=\"gal[1071]\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-729\" alt=\"python-logo\" src=\"https:\/\/www.gigiwangs.com\/wp-content\/uploads\/2012\/07\/python-logo.png\" width=\"401\" height=\"301\" \/><\/a><br \/>\n\u5927\u5bb6\u90fd\u662f\u61d2\u4eba&#8230; \u8fd9\u4e2a\u5bfc\u51fa\u5468\u62a5\u52a0\u4e0a\u4ee3\u7801\u7ef4\u62a4\u7684\u5de5\u4f5c\u4ea4\u7ed9\u4e86\u6211\u3002<br \/>\n\u6211\u6240\u8981\u505a\u7684\u5de5\u4f5c\u6574\u4e2a\u6b65\u9aa4\u662f\uff1a\u767b\u5f55\u7f51\u7ad9\uff08\u7528\u6237\u540d\/\u5bc6\u7801\uff09-&gt;<br \/>\n-&gt;\u5217\u8868\u9875\u9762-&gt;\u8f93\u5165\u6761\u4ef6-&gt;\u5bfc\u51fa\u4e3a||-&gt;\u4f7f\u7528Perl\u5c06\u5bfc\u51fa\u6587\u4ef6\u8fdb\u884c\u5904\u7406-&gt;\u63d0\u4ea4\u5468\u62a5-&gt;&#8230;<br \/>\n\u5982\u679c\u5c06&#8221;\u5bfc\u51fa\u4e3a&#8221;\u4e4b\u524d\u7684\u624b\u5de5\u6b65\u9aa4\u4e5f\u7701\u7565\u6389\u7684\u8bdd,\u90a3\u624d\u771f\u6b63\u5b9e\u73b0\u4e00\u6b65\u5b8c\u6210..\u7531\u4e8e\u5bf9Perl\u8fd8\u4e0d\u719f\uff0c\u6240\u6709\u6b65\u9aa4\u5c31\u9009\u7528python<br \/>\n\u91cd\u65b0\u5199\u4e86\uff01\u90a3\u5c31\u76f4\u63a5\u52a8\u624b\u505a\u5427:<br \/>\n\u5206\u6790\uff1a\u6a21\u5757\u4e0a\u5305\u62ec\u767b\u5f55WEB\uff0c\u4e0b\u8f7d\u6587\u4ef6\uff0c\u5bfc\u51fa\u5230EXCEL\u3002<br \/>\n\u524d\u4e24\u4e2a\u6a21\u5757\u90fd\u5f88\u7b80\u5355\uff0c\u7f51\u4e0a\u8d44\u6599\u4e5f\u5f88\u591a\uff1a<br \/>\n1.\u767b\u5f55\uff0c\u7531\u4e8e\u662f\u767b\u5f55\u540e\u4e0b\u8f7d\uff0c\u6240\u4ee5\u9700\u8981\u6a21\u62df\u6d4f\u89c8\u5668\uff0c\u4f7f\u7528cookies\u3002\u8fd9\u91cc\u5c31\u8d34\u51fa\u6d4b\u8bd5\u7684Demon<\/p>\n<pre class=\"brush:python\">\ndef get_srcfile(begindt,fridaydt):\n\n    cj= cookielib.CookieJar()\n    opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))\n    opener.addheaders = [('User-agent','Mozilla\/5.0 (compatible; MSIE 7.0; Windows NT 5.1)')]\n    params = urllib.urlencode({'username':'username',              \n                           'password':'passwd',\n                            'Cookies_Time': 1,\n                             'IsLogin':True})\n    #  with cookies\n    login_page='http:\/\/www.xxx.com\/login'\n    login_data = urllib.urlencode({u\"username\":u'wangzhe2',u\"password\":u'wangzhe2'})   \n    opener.open(login_page,login_data)\n     ......\n    opener.close()\n<\/pre>\n<p>2.\u4e0b\u8f7d\u6587\u4ef6\uff1a<br \/>\n\u51cf\u5c11\u6587\u5b57\u91cf\uff0c\u53c2\u770b\u8fd9\u91cc\u5427\uff1ahttp:\/\/outofmemory.cn\/code-snippet\/83\/sanzhong-Python-xiazai-url-save-file-code<\/p>\n<p>3.\u8bfb\u4e0b\u8f7d\u7684\u6587\u4ef6\uff0c\u5e76\u5bfc\u5165\u751f\u6210\u7684excel<br \/>\n\u8fd9\u91cc\u4e0d\u5f97\u4e0d\u63d0\u5230xlwt,xlrd,xlutils\u8fd9\u51e0\u4e2a\u5305\u3002<br \/>\nxlrd\uff1a\u8bfbexcel\u6587\u4ef6\uff0c\u4ece\u540d\u5b57\u53ef\u4ee5\u770b\u51fa\u6765\uff0cxls read \u3002\u5730\u5740\uff1a<a href=\"https:\/\/pypi.python.org\/pypi\/xlrd\" target=\"_blank\">https:\/\/pypi.python.org\/pypi\/xlrd<\/a><br \/>\nxlwt\uff1a\u5199excel\u6587\u4ef6\uff0cxls write\uff0c\u53ef\u4ee5\u63a7\u5236Excel\u4e2d\u5355\u5143\u683c\u7684\u683c\u5f0f\u3002\u5730\u5740\uff1ahttps:\/\/pypi.python.org\/pypi\/xlwt<br \/>\nxlutils\uff1axlwt\u5bf9\u4e8e\u8bfb\u53d6\u548c\u751f\u6210Excel\u6587\u4ef6\u90fd\u975e\u5e38\u5bb9\u6613\u5904\u7406\uff0c\u4f46\u662f\u5bf9\u4e8e\u5df2\u7ecf\u5b58\u5728\u7684Excel\u6587\u4ef6\u8fdb\u884c\u4fee\u6539\u5c31\u5b58\u5728\u95ee\u9898\u4e86\uff0c<br \/>\nxlutils\uff08\u4f9d\u8d56\u4e8exlrd\u548cxlwt\uff09\u63d0\u4f9b\u590d\u5236excel\u6587\u4ef6\u5185\u5bb9\u548c\u4fee\u6539\u6587\u4ef6\u7684\u529f\u80fd\u3002<br \/>\n\u4e0b\u8f7d\u5730\u5740\uff1a<a href=\"https:\/\/pypi.python.org\/pypi\/xlutils\" target=\"_blank\">https:\/\/pypi.python.org\/pypi\/xlutils<\/a><br \/>\n\u5177\u4f53\u53c2\u89c1\u6587\u6863\uff1a <a href=\"http:\/\/www.python-excel.org\/\" target=\"_blank\">http:\/\/www.python-excel.org\/<\/a>\u00a0\u00a0 <a href=\"http:\/\/pythonhosted.org\/xlutils\/\" target=\"_blank\">http:\/\/pythonhosted.org\/xlutils\/<\/a><\/p>\n<p>\u4e0d\u5f97\u4e0d\u8bf4\u5728\u4f7f\u7528\u7684\u65f6\u5019\u9047\u5230\u4e86\u95ee\u9898\uff0c\u6211\u9700\u8981\u7684\u662f\u64cd\u4f5coffice 2007+ \u7684xlsx\u6587\u4ef6\uff0c\u800c\u4e14\u8981\u7528\u5230excel\u7684\u6570\u636e\u9a8c\u8bc1\u548c\u4e0b\u62c9\u9009\u6846<br \/>\n\uff08Data validation and drop down lists\uff09\uff0c\u8fd9\u6837\u95ee\u9898\u663e\u800c\u6613\u89c1\u4e86\uff0c\u8fd9\u4e2a\u5305\u80af\u5b9a\u4e0d\u80fd\u7528\u4e86\u3002<br \/>\n\u4e8e\u662f\uff0c\u5fc5\u987b\u8981\u91cd\u65b0\u9009\u62e9\u5176\u4ed6\u65b9\u6cd5\u4e86\uff0c\u8fd9\u65f6Google\u7ed9\u51fa\u4e86\u8fd9\u4e2a\u6700\u4f73\u7b54\u6848\uff1a XlsxWriter!<br \/>\n<a href=\"  https:\/\/pypi.python.org\/pypi\/XlsxWriter\" target=\"_blank\">\u00a0 https:\/\/pypi.python.org\/pypi\/XlsxWriter<\/a><br \/>\n\u901a\u8fc7\u4ecb\u7ecd\u53ef\u4ee5\u770b\u5f97\u51fa\u6765\uff0cXlsxWriter\u53ef\u4ee5\u64cd\u4f5cxlsx\u6587\u4ef6\uff0c\u5355\u5143\u683c\u5199\u5165\u6587\u672c\uff0c\u6570\u5b57\uff0c\u516c\u5f0f\uff0c\u65e5\u671f\u7b49\u4e0d\u540c\u683c\u5f0f\uff1b\u683c\u5f0f\u5316\u8868\u683c\uff0c<br \/>\n\u56fe\u8868\uff0c\u5408\u5e76\u5355\u5143\u683c\u7b49\u7b49\u3002\uff0c\u6700\u4e3b\u8981\u6ee1\u8db3Data validation and drop down lists\u64cd\u4f5c\u7684\u9700\u6c42\u3002<\/p>\n<figure id=\"attachment_1074\" aria-describedby=\"caption-attachment-1074\" style=\"width: 574px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gigiwangs.com\/wp-content\/uploads\/2013\/07\/data_validate1.png\" data-lightbox=\"gal[1071]\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-1074\" alt=\"excel \u6570\u636e\u9a8c\u8bc1 xlsxWriter\" src=\"https:\/\/www.gigiwangs.com\/wp-content\/uploads\/2013\/07\/data_validate1.png\" width=\"574\" height=\"454\" \/><\/a><figcaption id=\"caption-attachment-1074\" class=\"wp-caption-text\">excel \u6570\u636e\u9a8c\u8bc1 xlsxWriter<\/figcaption><\/figure>\n<p>XlsxWriter is a Python module for creating Excel XLSX files.<br \/>\nXlsxWriter supports the following features:<\/p>\n<p>100% compatible Excel XLSX files.<br \/>\nWrite text, numbers, formulas, dates to cells.<br \/>\nWrite hyperlinks to cells.<br \/>\nFull cell formatting.<br \/>\nMultiple worksheets.<br \/>\nCharts.<br \/>\nPage setup methods for printing.<br \/>\nMerged cells.<br \/>\nDefined names.<br \/>\nAutofilters.<br \/>\nData validation and drop down lists.<br \/>\nConditional formatting.<br \/>\nWorksheet PNG\/JPEG images.<br \/>\nRich multi-format strings.<br \/>\nCell comments.<br \/>\nDocument properties.<br \/>\nWorksheet cell protection.<br \/>\nFreeze and split worksheet panes.<br \/>\nWorksheet Tables.<br \/>\nSparklines.<br \/>\nOutlines and Grouping.<br \/>\nMemory optimisation mode for writing large files.<br \/>\nStandard libraries only.<br \/>\nPython 2.6, 2.7, 3.1, 3.2 and 3.3 support.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5de5\u4f5c\u5468\u62a5\u6216\u662f\u65e5\u62a5\uff0c\u6708\u62a5\uff0c\u662f\u6bcf\u4e00\u4e2aIT\u6c11\u5de5\u7684\u75db\u5427\uff0c\u4e00\u5929\u5fd9\u788c\u4e0b\u6765\u8fd8\u8981\u88ab\u50ac\u7740\u5199\u5468\u62a5&#8230;\u8fd8\u597d\uff0c\u6211\u4eec\u7684\u5468\u62a5\u6570\u636e\u662f \u4ece\u9879\u76ee\u7ba1\u7406\u5e73\u53f0(\u7c7b\u4f3cmantis\uff09\u4e0a\u5bfc\u51fa\u6765\u7684\u3002\u5df2\u7ecf\u6709\u524d\u8f88\u4f7f\u7528Perl\u5199\u4e86\u5c06\u5bfc\u51fa\u7684excel\u6570\u636e\u8fdb\u884c\u7b5b\u9009\u751f\u6210\u65e2\u5b9a\u7684 EXCEL\u683c\u5f0f\u7684\u6587\u6863\u3002 \u5927\u5bb6\u90fd\u662f\u61d2\u4eba&#8230; \u8fd9\u4e2a\u5bfc\u51fa\u5468\u62a5\u52a0\u4e0a\u4ee3\u7801\u7ef4\u62a4\u7684\u5de5\u4f5c\u4ea4\u7ed9\u4e86\u6211\u3002 \u6211\u6240\u8981\u505a\u7684\u5de5\u4f5c\u6574\u4e2a\u6b65\u9aa4\u662f\uff1a\u767b\u5f55\u7f51\u7ad9\uff08\u7528\u6237\u540d\/\u5bc6\u7801\uff09-&gt; -&gt;\u5217\u8868\u9875\u9762-&gt;\u8f93\u5165\u6761\u4ef6-&gt;\u5bfc\u51fa\u4e3a||-&gt;\u4f7f\u7528Perl\u5c06\u5bfc\u51fa\u6587\u4ef6\u8fdb\u884c\u5904\u7406-&gt;\u63d0\u4ea4\u5468\u62a5-&gt;&#8230; \u5982\u679c\u5c06&#8221;\u5bfc\u51fa\u4e3a&#8221;\u4e4b\u524d\u7684\u624b\u5de5\u6b65\u9aa4\u4e5f\u7701\u7565\u6389\u7684\u8bdd,\u90a3\u624d\u771f\u6b63\u5b9e\u73b0\u4e00\u6b65\u5b8c\u6210..\u7531\u4e8e\u5bf9Perl\u8fd8\u4e0d\u719f\uff0c\u6240\u6709\u6b65\u9aa4\u5c31\u9009\u7528python \u91cd\u65b0\u5199\u4e86\uff01\u90a3\u5c31\u76f4\u63a5\u52a8\u624b\u505a\u5427: \u5206\u6790\uff1a\u6a21\u5757\u4e0a\u5305\u62ec\u767b\u5f55WEB\uff0c\u4e0b\u8f7d\u6587\u4ef6\uff0c\u5bfc\u51fa\u5230EXCEL\u3002 \u524d\u4e24\u4e2a\u6a21\u5757\u90fd\u5f88\u7b80\u5355\uff0c\u7f51\u4e0a\u8d44\u6599\u4e5f\u5f88\u591a\uff1a 1.\u767b\u5f55\uff0c\u7531\u4e8e\u662f\u767b\u5f55\u540e\u4e0b\u8f7d\uff0c\u6240\u4ee5\u9700\u8981\u6a21\u62df\u6d4f\u89c8\u5668\uff0c\u4f7f\u7528cookies\u3002\u8fd9\u91cc\u5c31\u8d34\u51fa\u6d4b\u8bd5\u7684Demon def get_srcfile(begindt,fridaydt): cj= cookielib.CookieJar() opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) opener.addheaders = [(&#8216;User-agent&#8217;,&#8217;Mozilla\/5.0 (compatible; MSIE 7.0; Windows NT 5.1)&#8217;)] params = urllib.urlencode({&#8216;username&#8217;:&#8217;username&#8217;, &#8216;password&#8217;:&#8217;passwd&#8217;, &#8216;Cookies_Time&#8217;: 1, &#8216;IsLogin&#8217;:True}) # with cookies login_page=&#8217;http:\/\/www.xxx.com\/login&#8217; login_data = urllib.urlencode({u&#8221;username&#8221;:u&#8217;wangzhe2&#8242;,u&#8221;password&#8221;:u&#8217;wangzhe2&#8242;}) opener.open(login_page,login_data) &#8230;&#8230; opener.close() 2.\u4e0b\u8f7d\u6587\u4ef6\uff1a \u51cf\u5c11\u6587\u5b57\u91cf\uff0c\u53c2\u770b\u8fd9\u91cc\u5427\uff1ahttp:\/\/outofmemory.cn\/code-snippet\/83\/sanzhong-Python-xiazai-url-save-file-code 3.\u8bfb\u4e0b\u8f7d\u7684\u6587\u4ef6\uff0c\u5e76\u5bfc\u5165\u751f\u6210\u7684excel \u8fd9\u91cc\u4e0d\u5f97\u4e0d\u63d0\u5230xlwt,xlrd,xlutils\u8fd9\u51e0\u4e2a\u5305\u3002 xlrd\uff1a\u8bfbexcel\u6587\u4ef6\uff0c\u4ece\u540d\u5b57\u53ef\u4ee5\u770b\u51fa\u6765\uff0cxls read \u3002\u5730\u5740\uff1ahttps:\/\/pypi.python.org\/pypi\/xlrd [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1074,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,25,5],"tags":[13,26],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.mujins.com\/index.php?rest_route=\/wp\/v2\/posts\/1071"}],"collection":[{"href":"https:\/\/www.mujins.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mujins.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mujins.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mujins.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1071"}],"version-history":[{"count":0,"href":"https:\/\/www.mujins.com\/index.php?rest_route=\/wp\/v2\/posts\/1071\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mujins.com\/index.php?rest_route=\/"}],"wp:attachment":[{"href":"https:\/\/www.mujins.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1071"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mujins.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1071"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mujins.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1071"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}