【问题标题】:C# excel color textC# excel 彩色文本
【发布时间】: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 特定信息,例如背景颜色。

标签: c# excel csv


【解决方案1】:

我认为用 CSV 文件做你想做的事是不可能的。 Excel 只读取值并将它们分隔在列中,仅此而已。

如果您想直接通过代码创建 Excel 文件,您需要使用例如 Open XML : https://msdn.microsoft.com/en-gb/library/office/bb448854.aspx 这是我用来创建、编辑 Excel 文件(以及 Powerpoint 文件)的工具。一开始有点棘手,但它是一个解决方案......

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-10
    • 2017-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-19
    • 2016-06-19
    相关资源
    最近更新 更多