private void ImportCSVAsDict(CsvLib.CsvStreamReader csvreader) { for (int i = 2; i <= csvreader.RowCount; i++) { if (csvreader.ColCount > 1) { Node newNode = AddNode("dict"); PlistNodeData data = newNode.Tag as PlistNodeData; data.key = csvreader[i, 1]; newNode.Text = data.key; for (int j = 2; j <= csvreader.ColCount; j++) { AddNodeAndValue(newNode, csvreader[1, j], csvreader[i, j]); } } } }
private void ImportCSVAsArray(CsvLib.CsvStreamReader csvreader, Node parent) { for (int i = 2; i <= csvreader.RowCount; i++) { if (csvreader.ColCount > 1) { Node newNode = AddNode(); for (int j = 1; j <= csvreader.ColCount; j++) { AddNodeAndValue(newNode, csvreader[1, j], csvreader[i, j]); } } else { AddNodeAndValue(parent, csvreader[1, 1], csvreader[i, 1]); } } }
private void ImportCSV(Node parent, Constant.NodeTypeDefine parenttype) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "(CSV 逗号分隔文件)|*.csv"; if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { CsvLib.CsvStreamReader csvreader = new CsvLib.CsvStreamReader(dlg.FileName, Encoding.Default); if (parent == null) { ImportCSVAsDict(csvreader); return; } if (parenttype == Constant.NodeTypeDefine.array) { ImportCSVAsArray(csvreader, parent); } else if (parenttype == Constant.NodeTypeDefine.dict) { ImportCSVAsDict(csvreader); } } }