【发布时间】:2017-10-20 09:10:26
【问题描述】:
我目前正在使用下面的代码来比较两个 csv 文件。我可以在文件中选择一列,它将比较该列中的行,然后将不正确和正确的行写入另一个 csv 文件。但现在我想更改文本“这一行不一样”的颜色,使其更加明显。我该怎么做?
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
{
}
}
}
}
【问题讨论】:
-
这是一个 CSV 文件。它将无法存储 Excel 特定信息,例如背景颜色。