{"id":12061,"date":"2017-04-11T00:00:00","date_gmt":"2017-04-10T16:00:00","guid":{"rendered":"https:\/\/fgchen.com\/wpedu2\/2017\/04\/11\/%e3%80%90%e7%a8%8b%e5%bc%8f%e8%a8%ad%e8%a8%88%e3%80%91%e3%80%90c%e3%80%91%e9%96%8b%e5%95%9fcsv%e8%b3%87%e6%96%99%e6%aa%94%e6%a1%88-csv%e4%b8%a6%e8%99%95%e7%90%86%e8%b3%87%e6%96%99\/"},"modified":"2026-03-30T14:49:33","modified_gmt":"2026-03-30T06:49:33","slug":"%e3%80%90%e7%a8%8b%e5%bc%8f%e8%a8%ad%e8%a8%88%e3%80%91%e3%80%90c%e3%80%91%e9%96%8b%e5%95%9fcsv%e8%b3%87%e6%96%99%e6%aa%94%e6%a1%88-csv%e4%b8%a6%e8%99%95%e7%90%86%e8%b3%87%e6%96%99","status":"publish","type":"post","link":"https:\/\/fgchen.com\/wpedu\/2017\/04\/%e3%80%90%e7%a8%8b%e5%bc%8f%e8%a8%ad%e8%a8%88%e3%80%91%e3%80%90c%e3%80%91%e9%96%8b%e5%95%9fcsv%e8%b3%87%e6%96%99%e6%aa%94%e6%a1%88-csv%e4%b8%a6%e8%99%95%e7%90%86%e8%b3%87%e6%96%99\/","title":{"rendered":"\u3010\u7a0b\u5f0f\u8a2d\u8a08-C#\u3011\u958b\u555fCSV\u8cc7\u6599\u6a94\u6848(.csv)\u4e26\u8655\u7406\u8cc7\u6599"},"content":{"rendered":"<h1><strong><span style=\"font-size: 18pt\">\u3010\u6559\u5b78\u76ee\u7684\u3011<\/span><\/strong><\/h1>\n\n\u6211\u5011\u8981\u8b80\u5165\u5982\u4e0b\u7684\u8cc7\u6599\uff0c\u6b64\u8cc7\u6599\u6a94\u4ee5\u9017\u9ede\u5206\u9694\u8cc7\u6599\uff0c\u6211\u5011\u8981\u5c07\u8cc7\u6599\u4e00\u884c\u4e00\u884c\u8b80\u51fa\u4f86(\u653e\u5728\u4e00\u500b\u5b57\u4e32)\uff0c\u4e26\u4e14\u4ee5\u9017\u9ede\u65b9\u5f0f\u5c07\u8cc7\u6599\u5206\u958b(\u5b57\u4e32\u9663\u5217)\u3002\n\n<h2><strong><span style=\"font-size: 14pt\">\u3010\u7b2c\u4e00\u500b\u756b\u9762\u3011\u672a\u5206\u5272\u8cc7\u6599<\/span><\/strong><\/h2>\n\n<a href=\"http:\/\/www.fgchen.com\/wp\/%e3%80%90%e7%a8%8b%e5%bc%8f%e8%a8%ad%e8%a8%88%e3%80%91%e3%80%90c%e3%80%91%e9%96%8b%e5%95%9fcsv%e8%b3%87%e6%96%99%e6%aa%94%e6%a1%88-csv%e4%b8%a6%e8%99%95%e7%90%86%e8%b3%87%e6%96%99\/opencsv-1\/\" rel=\"attachment wp-att-4838\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-4838\" src=\"http:\/\/www.fgchen.com\/wp\/wp-content\/uploads\/2017\/04\/openCSV-1.png\" alt=\"\" width=\"457\" height=\"271\" \/><\/a>\n\n<h2><strong><span style=\"font-size: 14pt\">\u3010\u7b2c\u4e8c\u500b\u756b\u9762\u3011\u5206\u5272\u8cc7\u6599<\/span><\/strong><\/h2>\n\n<a href=\"http:\/\/www.fgchen.com\/wp\/%e3%80%90%e7%a8%8b%e5%bc%8f%e8%a8%ad%e8%a8%88%e3%80%91%e3%80%90c%e3%80%91%e9%96%8b%e5%95%9fcsv%e8%b3%87%e6%96%99%e6%aa%94%e6%a1%88-csv%e4%b8%a6%e8%99%95%e7%90%86%e8%b3%87%e6%96%99\/opencsv-2\/\" rel=\"attachment wp-att-4839\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-4839\" src=\"http:\/\/www.fgchen.com\/wp\/wp-content\/uploads\/2017\/04\/openCSV-2.png\" alt=\"\" width=\"457\" height=\"271\" \/><\/a>\n\n<h2>\u6210\u7e3e\u6a94\u4e0b\u8f09\uff1a<a href=\"https:\/\/fgchen.com\/wp\/wp-content\/uploads\/2017\/04\/\u6210\u7e3e\u6a94.csv\" rel=\"attachment wp-att-4834\">\u6210\u7e3e\u6a94<\/a><\/h2>\n\n\u9673X\u9234,75,70,75,75\n\u5289X\u5982,75,70,75,75\n\u738bX\u73b2,75,70,75,75\n\u9ec3X\u5982,80,85,90,60\n\u6797X\u541b,65,80,95,70\n\u5f35X\u60e0,65,80,70,65\n\u738bX\u742a,80,70,65,75\n\u4f59X\u82ac,70,80,50,70\n\u5468X\u8abc,80,80,90,65\n\u9ec3X\u5100,80,80,90,65\n\u9673X\u5999,80,80,75,75\n\u9ec3X\u84ee,80,80,85,65\n\u984fX\u82b3,80,70,90,65\n\u5f35X\u6d32,75,80,90,75\n\u738bX\u8070,65,70,75,45\n\u80e1X\u8679,20,80,70,65\n~~\u4ee5\u4e0b \u7701\u7565~~\n\n<h2><strong><span style=\"font-size: 18pt\">\u3010\u7a0b\u5f0f\u78bc\u3011 <\/span><\/strong><\/h2>\n\n<h3><strong><span style=\"font-size: 18pt\">\u5c08\u6848\u6a94\u4e0b\u8f09\uff1a<a href=\"https:\/\/fgchen.com\/wp\/wp-content\/uploads\/2017\/04\/openCSV.zip\" rel=\"attachment wp-att-4840\">openCSV<\/a><\/span><\/strong><\/h3>\n\n<pre class=\"theme:vs2012 lang:c# decode:true\">using System;\nusing System.Collections.Generic;\nusing System.ComponentModel;\nusing System.Data;\nusing System.Drawing;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\nusing System.Windows.Forms;\nnamespace WindowsFormsApplication2\n{\n    public partial class Form1 : Form\n    {\n        public Form1()\n        {\n            InitializeComponent();\n        }\n        private void button1_Click(object sender, EventArgs e)\n        {\n            tbResult.Text = \"\";\n            \/\/ \u5efa\u7acb\u4e00\u500bOpenFileDialog\u7269\u4ef6\n            OpenFileDialog openFileDialog1 = new OpenFileDialog();\n            \/\/ \u8a2d\u5b9aOpenFileDialog\u5c6c\u6027\n            openFileDialog1.Title = \"\u9078\u64c7\u8981\u958b\u555f\u7684CSV\u6a94\u6848\";\n            openFileDialog1.Filter = \"CSV Files (.csv)|*.csv|All Files (*.*)|*.*\";\n            openFileDialog1.FilterIndex = 1;\n            openFileDialog1.Multiselect = true;\n            \/\/ \u559a\u7528ShowDialog\u65b9\u6cd5\uff0c\u6253\u958b\u5c0d\u8a71\u65b9\u584a\n            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)\n            {\n                string theFile = openFileDialog1.FileName; \/\/\u53d6\u5f97\u6a94\u540d\n                Encoding enc = Encoding.GetEncoding(\"big5\"); \/\/\u8a2d\u5b9a\u6a94\u6848\u7684\u7de8\u78bc\n                string[] readText = System.IO.File.ReadAllLines(theFile, enc); \/\/\u4ee5\u6307\u5b9a\u7684\u7de8\u78bc\u65b9\u5f0f\u8b80\u53d6\u6a94\u6848\n                foreach (string s in readText)\n                {\n                    tbResult.Text += s + \"rn\";\n                }\n            }\n        }\n        private void button2_Click(object sender, EventArgs e)\n        {\n            tbResult.Text = \"\";\n            \/\/ \u5efa\u7acb\u4e00\u500bOpenFileDialog\u7269\u4ef6\n            OpenFileDialog openFileDialog1 = new OpenFileDialog();\n            \/\/ \u8a2d\u5b9aOpenFileDialog\u5c6c\u6027\n            openFileDialog1.Title = \"\u9078\u64c7\u8981\u958b\u555f\u7684CSV\u6a94\u6848\";\n            openFileDialog1.Filter = \"CSV Files (.csv)|*.csv|All Files (*.*)|*.*\";\n            openFileDialog1.FilterIndex = 1;\n            openFileDialog1.Multiselect = true;\n            \/\/ \u559a\u7528ShowDialog\u65b9\u6cd5\uff0c\u6253\u958b\u5c0d\u8a71\u65b9\u584a\n            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)\n            {\n                string theFile = openFileDialog1.FileName; \/\/\u53d6\u5f97\u6a94\u540d\n                Encoding enc = Encoding.GetEncoding(\"big5\"); \/\/\u8a2d\u5b9a\u6a94\u6848\u7684\u7de8\u78bc\n                string[] readText = System.IO.File.ReadAllLines(theFile, enc); \/\/\u4ee5\u6307\u5b9a\u7684\u7de8\u78bc\u65b9\u5f0f\u8b80\u53d6\u6a94\u6848\n                foreach (string s in readText)\n                {\n                    string[] ss = s.Split(','); \/\/\u5c07\u4e00\u5217\u7684\u8cc7\u6599\uff0c\u4ee5\u9017\u865f\u7684\u65b9\u5f0f\u9032\u884c\u8cc7\u6599\u5207\u5272\uff0c\u4e26\u5c07\u8cc7\u6599\u653e\u5165\u4e00\u500b\u5b57\u4e32\u9663\u5217\n                    tbResult.Text += ss[0] + \"  \" + ss[1] + \"  \" + ss[2] + \"  \" + ss[3] + \"  \" + ss[4] + \"rn\";\n                    \/\/\u8cc7\u6599\u5206\u5225\u5728\u53d6\u51fa\u7684\u5b57\u4e32\u9663\u5217\u88cf\uff0c\u59d3\u540d-&gt;ss[0], \u6210\u7e3e1-&gt;ss[1], \u6210\u7e3e2-&gt;ss[2], \u6210\u7e3e3-&gt;ss[3], \u6210\u7e3e4-&gt;ss[4]\n                }\n            }\n        }\n    }\n}\n<\/pre>\n\n&nbsp;\n<span style=\"font-size: 14pt\"><strong>\u3010\u4e00\u7dad\u5b57\u4e32\u9663\u5217-\u5b57\u4e32\u7269\u4ef6\u3011<\/strong><\/span>\n<a href=\"http:\/\/www.fgchen.com\/wp\/%e3%80%90%e7%a8%8b%e5%bc%8f%e8%a8%ad%e8%a8%88%e3%80%91%e3%80%90c%e3%80%91%e9%96%8b%e5%95%9fcsv%e8%b3%87%e6%96%99%e6%aa%94%e6%a1%88-csv%e4%b8%a6%e8%99%95%e7%90%86%e8%b3%87%e6%96%99\/1d-string-array-file-read\/\" rel=\"attachment wp-att-4927\"><img decoding=\"async\" class=\"size-full wp-image-4927 aligncenter\" src=\"http:\/\/www.fgchen.com\/wp\/wp-content\/uploads\/2017\/04\/1D-String-Array-File-Read.png\" alt=\"\" width=\"3375\" height=\"2263\" \/><\/a>\n&nbsp;\n<a href=\"http:\/\/www.fgchen.com\/wp\/%e3%80%90%e7%a8%8b%e5%bc%8f%e8%a8%ad%e8%a8%88%e3%80%91%e3%80%90c%e3%80%91%e9%96%8b%e5%95%9fcsv%e8%b3%87%e6%96%99%e6%aa%94%e6%a1%88-csv%e4%b8%a6%e8%99%95%e7%90%86%e8%b3%87%e6%96%99\/1d-string-array-file-read-split\/\" rel=\"attachment wp-att-4928\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4928 aligncenter\" src=\"http:\/\/www.fgchen.com\/wp\/wp-content\/uploads\/2017\/04\/1D-String-Array-File-Read-Split.png\" alt=\"\" width=\"813\" height=\"504\" \/><\/a>\n&nbsp;\n<span style=\"font-size: 14pt\"><strong>\u5e95\u4e0b\u7684\u6539\u7248\u7a0b\u5f0f\u4fc2\u5c07\u8b80\u51fa\u4f86\u7684\u8cc7\u6599\uff0c\u8f49\u6210\u6d6e\u9ede\u6578\u5f8c\uff0c\u653e\u5165\u4e00\u500b2\u7dad\u7684\u6d6e\u9ede\u6578\u9663\u5217\uff0c\u7136\u5f8c\uff0c\u5c07\u7e3d\u5206\u52a0\u7e3d\u5f8c\uff0c\u653e\u5230\u6700\u5f8c\u4e00\u500b\u6b04\u4f4d(\u6bcf\u5217)\u3002<\/strong><\/span>\n\n<pre class=\"theme:vs2012 lang:c# decode:true \">       private void button2_Click(object sender, EventArgs e)\n        {\n            tbResult.Text = \"\";\n            \/\/ \u5efa\u7acb\u4e00\u500bOpenFileDialog\u7269\u4ef6\n            OpenFileDialog openFileDialog1 = new OpenFileDialog();\n            \/\/ \u8a2d\u5b9aOpenFileDialog\u5c6c\u6027\n            openFileDialog1.Title = \"\u9078\u64c7\u8981\u958b\u555f\u7684CSV\u6a94\u6848\";\n            openFileDialog1.Filter = \"CSV Files (.csv)|*.csv|All Files (*.*)|*.*\";\n            openFileDialog1.FilterIndex = 1;\n            openFileDialog1.Multiselect = true;\n            \/\/ \u559a\u7528ShowDialog\u65b9\u6cd5\uff0c\u6253\u958b\u5c0d\u8a71\u65b9\u584a\n            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)\n            {\n                string theFile = openFileDialog1.FileName; \/\/\u53d6\u5f97\u6a94\u540d\n                Encoding enc = Encoding.GetEncoding(\"big5\"); \/\/\u8a2d\u5b9a\u6a94\u6848\u7684\u7de8\u78bc\n                string[] readText = System.IO.File.ReadAllLines(theFile, enc); \/\/\u4ee5\u6307\u5b9a\u7684\u7de8\u78bc\u65b9\u5f0f\u8b80\u53d6\u6a94\u6848\n                string[] name = new string[readText.Length];\/\/\u5ba3\u544a\u4e00\u500b1\u7dad\u5b57\u4e32\u9663\u5217\uff0c\u4f86\u5132\u5b58\u6240\u6709\u7684\u59d3\u540d\n                double[][] allData = new double[readText.Length][4]; \/\/\u5ba3\u544a\u4e00\u500b2\u7daddouble\u9663\u5217\uff0c\u7528\u4f86\u5132\u5b58\u6240\u6709\u7684\u6210\u7e3e\u8cc7\u6599\uff0c\u7b2c\u4e00\u7dad\u7684\u5927\u5c0f\u662f\u8cc7\u6599\u7684\u5217\u6578(\u7b46\u6578)\n                int line = 0; \/\/\u8868\u7b2c\u5e7e\u884c(\u7b2c\u5e7e\u5217\uff0c\u6bcf\u4e00\u5217\u70ba\u4e00\u500b\u5b78\u751f\u7684\u8cc7\u6599)\n                foreach (string s in readText)\n                {\n                    string[] ss = s.Split(','); \/\/\u5c07\u4e00\u5217\u7684\u8cc7\u6599\uff0c\u4ee5\u9017\u865f\u7684\u65b9\u5f0f\u9032\u884c\u8cc7\u6599\u5207\u5272\uff0c\u4e26\u5c07\u8cc7\u6599\u653e\u5165\u4e00\u500b\u5b57\u4e32\u9663\u5217\n                    name[line] = ss[0]; \/\/\u5207\u51fa\u4f86\u7684\u5b57\u4e32\uff0c\u7b2c0\u500b\u5143\u7d20\u662f\u59d3\u540d\n                    allData[line][0] = double.Parse(ss[1]);\n                    allData[line][1] = double.Parse(ss[2]);\n                    allData[line][2] = double.Parse(ss[3]);\n                    allData[line][3] = double.Parse(ss[4]);\n                    allData[line][4] = allData[line][0] + allData[line][1] + allData[line][2]+ allData[line][3]; \/\/\u5c07\u6bcf\u500b\u4eba\u7684\u6210\u7e3e\u52a0\u8d77\u4f86\u653e\u5728\u6700\u5f8c\u4e00\u6b04\n                    tbResult.Text += name[line] + \"  \" + allData[line][0] + \"  \" + allData[line][1] + \"  \" + allData[line][2] + \"  \" + allData[line][3] + \"  \" + allData[line][4] + \"rn\";\n                    line++; \/\/\u9032\u884c\u4e0b\u4e00\u7b46\u8cc7\u6599\u7684\u8655\u7406\n                    \/\/\u8cc7\u6599\u5206\u5225\u5728\u53d6\u51fa\u7684\u5b57\u4e32\u9663\u5217\u88cf\uff0c\u59d3\u540d-&gt;ss[0], \u6210\u7e3e1-&gt;ss[1], \u6210\u7e3e2-&gt;ss[2], \u6210\u7e3e3-&gt;ss[3], \u6210\u7e3e4-&gt;ss[4]\n                }\n            }\n        }<\/pre>\n\n&nbsp;","protected":false},"excerpt":{"rendered":"<p>\u3010\u6559\u5b78\u76ee\u7684\u3011 \u6211\u5011\u8981\u8b80\u5165\u5982\u4e0b\u7684\u8cc7\u6599\uff0c\u6b64\u8cc7\u6599\u6a94\u4ee5\u9017\u9ede\u5206\u9694\u8cc7\u6599\uff0c\u6211\u5011\u8981\u5c07\u8cc7\u6599\u4e00\u884c\u4e00\u884c &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","fifu_image_url":"","fifu_image_alt":"","footnotes":""},"categories":[266],"tags":[93,131,132,133,134],"class_list":["post-12061","post","type-post","status-publish","format-standard","hentry","category-266","tag-c","tag-csv","tag-file","tag-133","tag-134"],"_links":{"self":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/12061","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/comments?post=12061"}],"version-history":[{"count":1,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/12061\/revisions"}],"predecessor-version":[{"id":13397,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/12061\/revisions\/13397"}],"wp:attachment":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/media?parent=12061"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/categories?post=12061"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/tags?post=12061"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}