2017-10-20 2 views
0

私は現在、以下のコードを使用して2つのcsvファイルを比較しています。私はファイル内の列を選択し、その列の行を比較し、正しくない行を別のcsvファイルに書き込みます。しかし今、私は色が変わって、この行は同じではないので、もっと目立つようにしたい。これどうやってするの?C#はExcelのカラーテキスト

public void comparing(int selectedRow, string filenaname, string filename2) 
    { 
      List<string> lines = new List<string>(); 
      List<string> lines2 = new List<string>(); 
     try 
     { 
      StreamReader reader = new StreamReader(System.IO.File.OpenRead(filename)); 
      StreamReader read = new StreamReader(System.IO.File.OpenRead(filename2)); 
      List<string> lijnen = new List<string>(); 
      string line; 
      string line2; 
      string differencesFile= @"C:\Users\Mylan\Desktop\differences.csv"; 

      while ((line = reader.ReadLine()) != null && (line2 = read.ReadLine()) != null) 
       { 

       string[] split = line.Split(Convert.ToChar(csvSeperator)); 
       string[] split2 = line2.Split(Convert.ToChar(csvSeperator)); 


       if (split[selectedRow] != split2[selectedRow]) 
       { 
        lijnen.Add("This row is not the same:, " + line); 
       } 
       else if(test == test2) 
       { 
        System.Windows.Forms.MessageBox.Show("The whole file is the same"); 
        break; 
       } 
       else 
       { 
        lines.Add("This row is the same:, " + line); 
       }        
       } 
      System.IO.File.WriteAllLines(differencesFile, lines); 
      System.Diagnostics.Process.Start(differencesFile); 
      reader.Dispose(); 
      read.Dispose();   
     } 
     catch 
     { 

     } 
     } 
    } 
} 
+7

これはCSVファイルです。背景色などExcel固有の情報を保存することはできません。 –

答えて

1

CSVファイルではできないと思います。 Excelは値だけを読み込み、列でこれらを区切ります。

あなたはコードで直接Excelファイルを作成したい場合は、例えばオープンXMLを使用する必要があります。これは私が(余りにおよびPowerPointファイル)、編集Excelファイルを作成するために使用するものである https://msdn.microsoft.com/en-gb/library/office/bb448854.aspx を。初めはややこしいですが、それは解決策です...

関連する問題