Пример #1
0
        private void browseButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "CSV Files|*.csv";
            if (DialogResult.OK == ofd.ShowDialog())
            {
                pathTextBox.Text = ofd.FileName;
                string firstLine = null;

                using (StreamReader sr = new StreamReader(ofd.FileName))
                {
                    firstLine = sr.ReadLine();
                }
                string[] titles = CsvContext.GetFields(firstLine, ",");
                RefreshColumns();
                for (int i = 0; i < titles.Length; i++)
                {
                    if (currentConfig.ContainsColumn(titles[i]))
                    {
                        currentConfig.Columns[i].Ordinal = i;
                    }
                }
                mainDataGridView.DataSource = currentConfig.Columns;
                this.Refresh();
            }
        }
Пример #2
0
        public void GetFieldsWithLineBreakTest()
        {
            string line      = "5-Apr-2012,44526880,FOREIGN EXCHANGE - PURCHASE,49000,22250114,IDR,\"77\r\n,553,252.00\",\"9,090.00\",5-Apr-2012";
            string delimiter = ",";

            string[] arr = CsvContext.GetFields(line, delimiter);
            Assert.AreEqual(9, arr.Length);
            Assert.AreEqual("77\r\n,553,252.00", arr[6]);
            Assert.AreEqual("9,090.00", arr[7]);
        }
Пример #3
0
        public void GetFieldsTest()
        {
            string line      = "5-Apr-2012,44526880,FOREIGN EXCHANGE - PURCHASE,49000,22250114,IDR,\"77,553,252.00\",\"9,090.00\",5-Apr-2012";
            string delimiter = ",";

            string[] arr = CsvContext.GetFields(line, delimiter);
            Assert.AreEqual(arr.Length, 9);
            Assert.AreEqual(arr[6], "77,553,252.00");
            Assert.AreEqual(arr[7], "9,090.00");
        }