{"id":3650,"date":"2023-08-30T22:37:07","date_gmt":"2023-08-30T14:37:07","guid":{"rendered":"https:\/\/www.bytetape.com\/?p=3650"},"modified":"2023-09-01T22:49:36","modified_gmt":"2023-09-01T14:49:36","slug":"%e7%94%a8vba%e8%bd%bb%e6%9d%be%e6%90%9e%e5%ae%9abase64%e7%bc%96%e7%a0%81%e4%b8%8e%e8%a7%a3%e7%a0%81%ef%bc%81","status":"publish","type":"post","link":"https:\/\/www.bytetape.com\/?p=3650","title":{"rendered":"\u7528VBA\u8f7b\u677e\u641e\u5b9aBase64\u7f16\u7801\u4e0e\u89e3\u7801\uff01"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u55e8\uff0c\u4eb2\u7231\u7684\u7801\u519c\u5c0f\u4f19\u4f34\u4eec\uff01\u6b22\u8fce\u6765\u5230\u6211\u7684\u535a\u5ba2\uff0c\u4eca\u5929\u6211\u4eec\u8981\u804a\u4e00\u4e2a\u5728\u7f51\u7edc\u6570\u636e\u4f20\u9012\u4e2d\u9891\u7e41\u7528\u5230\u7684\u5c0f\u6280\u5de7\u2014\u2014Base64\u7f16\u7801\u4e0e\u89e3\u7801\u3002\u522b\u7740\u6025\uff0c\u6211\u4f1a\u7528\u7b80\u5355\u7684\u8bdd\u8bed\uff0c\u624b\u628a\u624b\u6559\u4f60\u5982\u4f55\u7528VBA\u5b9e\u73b0\u8fd9\u4e24\u4e2a\u9177\u70ab\u7684\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u53ef\u80fd\u4f1a\u95ee\uff0c\u4ec0\u4e48\u662fBase64\u5462\uff1f\u522b\u62c5\u5fc3\uff0c\u6211\u4f1a\u7528\u901a\u4fd7\u6613\u61c2\u7684\u65b9\u5f0f\u4e3a\u4f60\u89e3\u91ca\u3002\u5728\u8ba1\u7b97\u673a\u4e16\u754c\u91cc\uff0c\u6211\u4eec\u7ecf\u5e38\u9700\u8981\u5728\u4e0d\u540c\u7684\u8bbe\u5907\u3001\u7cfb\u7edf\u4e4b\u95f4\u4f20\u9012\u6570\u636e\u3002\u4f46\u662f\u6709\u4e9b\u6570\u636e\u53ef\u80fd\u5305\u542b\u4e86\u4e0d\u80fd\u76f4\u63a5\u4f20\u8f93\u7684\u5b57\u7b26\uff0c\u6bd4\u5982\u4e8c\u8fdb\u5236\u6570\u636e\u3002\u8fd9\u65f6\u5019\uff0cBase64\u5c31\u95ea\u4eae\u767b\u573a\u4e86\uff01\u5b83\u662f\u4e00\u79cd\u5c06\u4e8c\u8fdb\u5236\u6570\u636e\u8f6c\u6362\u6210\u53ef\u6253\u5370\u5b57\u7b26\u7684\u7f16\u7801\u65b9\u5f0f\uff0c\u65b9\u4fbf\u6570\u636e\u5728\u7f51\u7edc\u4e0a\u4f20\u9012\u3002\u540c\u65f6\uff0cBase64\u7f16\u7801\u4e5f\u80fd\u8ba9\u6211\u4eec\u8f7b\u677e\u5904\u7406\u90a3\u4e9b\u8ba9\u4eba\u5934\u75bc\u7684\u7279\u6b8a\u5b57\u7b26\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5e9f\u8bdd\u4e0d\u591a\u8bf4\uff0c\u8ba9\u6211\u4eec\u6765\u770b\u770b\u5982\u4f55\u7528VBA\u5b9e\u73b0Base64\u7f16\u7801\u5427\uff01\u4ee5\u4e0b\u662f\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"visualbasic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">'Base64\u7f16\u7801\nPrivate Function Base64Encode(sText As String) As String\n  Dim oXML As Object\n  Dim oNode As Object\n\n  Set oXML = CreateObject(\"Msxml2.DOMDocument.3.0\")\n  Set oNode = oXML.CreateElement(\"base64\")\n\n  oNode.DataType = \"bin.base64\"\n  oNode.nodeTypedValue = StreamStringToBinary(sText)\n  Base64Encode = oNode.Text\n\n  Set oNode = Nothing\n  Set oXML = Nothing\nEnd Function\n\nPrivate Function StreamStringToBinary(sText As String) As Variant\n  Dim ado As Object\n  Set ado = CreateObject(\"ADODB.Stream\")\n  \n  ado.Type = 2 ' adTypeText\n  ado.Charset = \"utf-8\"\n  ado.Open\n  ado.WriteText sText\n  ado.Position = 0\n  ado.Type = 1 ' adTypeBinary\n  StreamStringToBinary = ado.Read\n  ado.Close\n  \n  Set ado = Nothing\nEnd Function<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0a\u4ee3\u7801\u4f1a\u5c06\u4f60\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u6210Base64\u7f16\u7801\u3002\u662f\u4e0d\u662f\u5f88\u7b80\u5355\uff1f\u4e0d\u8fc7\u7b49\u7b49\uff0c\u5982\u679c\u4f60\u62c5\u5fc3\u8981\u4f20\u8f93\u7684\u6570\u636e\u9700\u8981\u4fdd\u5bc6\uff0c\u522b\u79bb\u5f00\uff01Base64\u53ea\u662f\u7f16\u7801\uff0c\u4e0d\u662f\u52a0\u5bc6\u3002\u8981\u4fdd\u8bc1\u6570\u636e\u7684\u673a\u5bc6\u6027\uff0c\u4f60\u8fd8\u9700\u8981\u5176\u4ed6\u52a0\u5bc6\u63aa\u65bd\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u6765\u8c08\u8c08\u89e3\u7801\u3002\u6536\u5230\u4e86\u7ecf\u8fc7Base64\u7f16\u7801\u7684\u6570\u636e\uff0c\u53ef\u522b\u624b\u8db3\u65e0\u63aa\u3002VBA\u4e5f\u80fd\u5e2e\u4f60\u5feb\u901f\u89e3\u7801\uff0c\u8fd8\u539f\u6210\u539f\u59cb\u5b57\u7b26\u4e32\u3002\u5e9f\u8bdd\u4e0d\u591a\u8bf4\uff0c\u6765\u770b\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"visualbasic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">'Base64\u89e3\u7801\nPrivate Function Base64Decode(sBase64 As String) As String\n  Dim oXML As Object\n  Dim oNode As Object\n  \n  Set oXML = CreateObject(\"Msxml2.DOMDocument.3.0\")\n  Set oNode = oXML.CreateElement(\"base64\")\n  \n  oNode.DataType = \"bin.base64\"\n  oNode.Text = sBase64\n  Base64Decode = StreamBinaryToString(oNode.nodeTypedValue)\n  \n  Set oNode = Nothing\n  Set oXML = Nothing\nEnd Function\n\nPrivate Function StreamBinaryToString(abData As Variant) As String\n  Dim ado As Object\n  Set ado = CreateObject(\"ADODB.Stream\")\n  \n  ado.Type = 1 ' adTypeBinary\n  ado.Open\n  ado.Write abData\n  ado.Position = 0\n  ado.Type = 2 ' adTypeText\n  ado.Charset = \"utf-8\"\n  StreamBinaryToString = ado.ReadText\n  \n  Set ado = Nothing\nEnd Function<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0a\u4ee3\u7801\u5c06Base64\u7f16\u7801\u8fd8\u539f\u6210\u539f\u59cb\u5b57\u7b26\u4e32\u3002\u662f\u4e0d\u662f\u89c9\u5f97\u8fd9\u5c31\u50cf\u9b54\u672f\u822c\u7684\u64cd\u4f5c\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u55ef\uff0c\u662f\u4e0d\u662f\u89c9\u5f97\u6709\u70b9\u610f\u601d\uff1fBase64\u7f16\u7801\u4e0e\u89e3\u7801\u5728\u7f51\u7edc\u6570\u636e\u4f20\u9012\u4e2d\u53ef\u662f\u4e2a\u5927\u6709\u7528\u5904\u7684\u5bb6\u4f19\u3002\u4f46\u522b\u5fd8\u4e86\uff0c\u5b83\u5e76\u4e0d\u662f\u4e07\u80fd\u7684\u3002\u5728\u4f20\u8f93\u654f\u611f\u4fe1\u606f\u65f6\uff0c\u4e00\u5b9a\u8981\u7ed3\u5408\u5176\u4ed6\u5b89\u5168\u63aa\u65bd\uff0c\u786e\u4fdd\u6570\u636e\u7684\u4fdd\u5bc6\u6027\u4e0e\u5b8c\u6574\u6027\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u597d\u5566\uff0c\u4eca\u5929\u7684\u5c0f\u6559\u7a0b\u5c31\u5230\u8fd9\u91cc\u3002\u5e0c\u671b\u4f60\u4eec\u559c\u6b22\u8fd9\u7bc7\u6587\u7ae0\uff0c\u4e5f\u80fd\u5728\u5b9e\u9645\u5de5\u4f5c\u4e2d\u8fd0\u7528\u8fd9\u4e9b\u5c0f\u6280\u5de7\u3002\u5982\u679c\u4f60\u6709\u4efb\u4f55\u95ee\u9898\u6216\u8005\u60f3\u6cd5\uff0c\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u4e0e\u6211\u4e92\u52a8\u54e6\uff01\u611f\u8c22\u4f60\u4eec\u7684\u652f\u6301\uff0c\u6211\u4eec\u4e0b\u671f\u518d\u89c1\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u55e8\uff0c\u4eb2\u7231\u7684\u7801\u519c\u5c0f\u4f19\u4f34\u4eec\uff01\u6b22\u8fce\u6765\u5230\u6211\u7684\u535a\u5ba2&#8230; <\/p>\n","protected":false},"author":1,"featured_media":3651,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[40],"tags":[58,36,59,60],"class_list":["post-3650","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vba","tag-base64","tag-vba","tag-59","tag-60"],"_links":{"self":[{"href":"https:\/\/www.bytetape.com\/index.php?rest_route=\/wp\/v2\/posts\/3650","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bytetape.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bytetape.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bytetape.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bytetape.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3650"}],"version-history":[{"count":1,"href":"https:\/\/www.bytetape.com\/index.php?rest_route=\/wp\/v2\/posts\/3650\/revisions"}],"predecessor-version":[{"id":3652,"href":"https:\/\/www.bytetape.com\/index.php?rest_route=\/wp\/v2\/posts\/3650\/revisions\/3652"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bytetape.com\/index.php?rest_route=\/wp\/v2\/media\/3651"}],"wp:attachment":[{"href":"https:\/\/www.bytetape.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bytetape.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bytetape.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}