当前位置: 首页>>代码示例>>C#>>正文


C# CsvWriter.WriteCsv方法代码示例

本文整理汇总了C#中CsvWriter.WriteCsv方法的典型用法代码示例。如果您正苦于以下问题:C# CsvWriter.WriteCsv方法的具体用法?C# CsvWriter.WriteCsv怎么用?C# CsvWriter.WriteCsv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CsvWriter的用法示例。


在下文中一共展示了CsvWriter.WriteCsv方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExportCsv

        public void ExportCsv()
        {
            Setup(TestUtil.GetTestFile("relay\\relay.ppen"));
            string tempOutputFile = TestUtil.GetTestFile("relay\\doublebranch_temp.csv");
            string baselineFile = TestUtil.GetTestFile("relay\\doublebranch_baseline.csv");

            var teamAssignment = new RelayVariations(eventDB, CourseId(4), 143, 6);
            var csvWriter = new CsvWriter();
            csvWriter.WriteCsv(tempOutputFile, teamAssignment);

            TestUtil.CompareTextFileBaseline(tempOutputFile, baselineFile);

            File.Delete(tempOutputFile);
        }
开发者ID:petergolde,项目名称:PurplePen,代码行数:14,代码来源:RelayVariationsTests.cs

示例2: button1_Click

        /// <summary>
        /// Create a new CSV file from the result
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            try {
            List<string> diffOfHeaders = new List<string>();
            if (CSVFile2Headers.Count <= CSVFile1Headers.Count)
               diffOfHeaders = CSVFile1Headers.Except(CSVFile2Headers).ToList();
            else
               diffOfHeaders = CSVFile2Headers.Except(CSVFile1Headers).ToList();

            List<List<string>> results = new List<List<string>>();

            if (RecordsOfCSVFile1.Count <= RecordsOfCSVFile2.Count) {
               for (int i = 0; i <= RecordsOfCSVFile2.Count - 1; i++) {
                  if (i <= RecordsOfCSVFile1.Count - 1) {
                     for (int k = 0; k <= RecordsOfCSVFile2[i].Count - 1; k++) {
                        if (RecordsOfCSVFile2[i][k] != RecordsOfCSVFile1[i][k]) {
                           results.Add(RecordsOfCSVFile2[i]);
                        }
                     }
                  }
                  else {
                     results.Add(RecordsOfCSVFile2[i]);
                  }
               }
            }

            /*
            if (RecordsOfCSVFile2.Count <= RecordsOfCSVFile1.Count) {
               for (int i = 0; i <= RecordsOfCSVFile1.Count - 1; i++) {
                  if (i < RecordsOfCSVFile2.Count) {
                     var resultOfRecords = RecordsOfCSVFile2[i].Except(RecordsOfCSVFile1[i]).Union(RecordsOfCSVFile1[i].Except(RecordsOfCSVFile2[i])).ToList();
                     if (resultOfRecords.Count > 0) {
                        results.Add(RecordsOfCSVFile1[i]);
                     }
                  }
                  else {
                     results.Add(RecordsOfCSVFile1[i]);
                  }
               }

               for (int i = 0; i <= RecordsOfCSVFile2.Count - 1; i++) {
                  if (i < RecordsOfCSVFile1.Count) {
                     var resultOfRecords = RecordsOfCSVFile1[i].Except(RecordsOfCSVFile2[i]).ToList();
                     if (resultOfRecords.Count > 0) {
                        results.Add(RecordsOfCSVFile2[i]);
                     }
                  }
                  else {
                     results.Add(RecordsOfCSVFile2[i]);
                  }
               }
            }
            else {
               for (int i = 0; i <= RecordsOfCSVFile2.Count - 1; i++) {
                  if (i < RecordsOfCSVFile1.Count) {
                     var resultOfRecords = RecordsOfCSVFile2[i].Except(RecordsOfCSVFile1[i]).ToList();
                     if (resultOfRecords.Count > 0) {
                        results.Add(RecordsOfCSVFile1[i]);
                     }
                  }
                  else {
                     results.Add(RecordsOfCSVFile2[i]);

                  }
               }
            }
            */
            if (results.Count == 0) {
               MessageBox.Show("There is no difference between the two files being compared");
               return;
            }
            DataTable dtDifferenceTable = ConvertListToDataTable(results);
            dataGridView3.DataSource = dtDifferenceTable.DefaultView;
            CsvWriter cw = new CsvWriter();

            string fileName = CSVOutputFile;
            //var t = new Thread((ThreadStart)(() =>
            //{
            //   SaveFileDialog saveFileDialogue = new SaveFileDialog();
            //   saveFileDialogue.Filter = "CSV Files (*.csv)|*.csv|All files (*.*)|*.*;";// "CSV files (*.csv)";
            //   if (saveFileDialogue.ShowDialog() == DialogResult.Cancel)
            //      return;

            //   fileName = saveFileDialogue.FileName;
            //}));

            //t.SetApartmentState(ApartmentState.STA);
            //t.Start();
            //t.Join();
            if (!string.IsNullOrEmpty(fileName)) {
               cw.WriteCsv(dtDifferenceTable, fileName, Encoding.Default);
               MessageBox.Show("Data Exported");
            }
             }
             catch (Exception) {
//.........这里部分代码省略.........
开发者ID:khatrikhimanshu95,项目名称:CSVComparer,代码行数:101,代码来源:Form1.cs


注:本文中的CsvWriter.WriteCsv方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。