none
Calculating deltas between two .csv files and outputting a third file using C# RRS feed

  • Question

  • I have almost no programming background.

    I'm attempting to write a computer program in visual studio using C# that compares two large .csv files that should be almost identical in each cell.  Some columns have characters and some have number data.  I need to leave the character columns alone and calculate the deltas between the numeric data columns.  Then output it all to a third file... Preferably one that highlights differences greater than some amount.

    Just creating the third output file in the same location as the 2 original files is fine.

    I havent been able to find any good advice so far.  Please help,

    Wednesday, June 1, 2016 4:10 PM

Answers

  • Hi jreynolds311,

    According to your description, I suggest that you could import CSV file to Excel sheet:
    Excel.Application excelApp = new Excel.Application();
    excelApp.Visible = true;
    Excel.Workbook wb = excelApp.Workbooks.Add();
    
    Excel.Worksheet ws = wb.Worksheets[1];
    Console.WriteLine(ws.Name);
    Excel.QueryTable qt=ws.QueryTables.Add("TEXT;"+csvFile,ws.get_Range("$A$1"));
    qt.TextFileParseType = Excel.XlTextParsingType.xlDelimited;
    qt.TextFileCommaDelimiter = true;
    qt.Refresh();
    qt.Delete();
    then you could detect cell value type and compare cells in excel and highlight the cells that are different.

    For more information, click here to refer about How to compare cells in excel and highlight the cells that are different

    • Marked as answer by David_JunFeng Tuesday, June 14, 2016 2:08 PM
    Thursday, June 2, 2016 4:53 AM

All replies

  • If you have no programming background you need a year or two to solve this. At least. There is no Push-Button solution (if that was the case then everyone would be experts without any need for education or practice)  but there are tools to help you. Have a look at Beyond Compare, http://www.scootersoftware.com/


    Best regards, George

    Wednesday, June 1, 2016 4:15 PM
  • I have been studying through an intro to C# book for a few weeks now, so I understand the basics of OOP but I dont know the syntax involved in reading and comparing data files.  I know I'll need a class to read the data files, identify the columns that are properties and a method to compare the two files separate from the program itself. But the actual syntax itself isn't covered for something like this in my book.

    I am unable to access the internet from the network I am using and I can't download or add third-party tools to the network, so it's on me to write an app that does this.  My programmer co-workers insist it's very easy and a good starter project.  

    Wednesday, June 1, 2016 7:14 PM
  • Hi jreynolds311,

    According to your description, I suggest that you could import CSV file to Excel sheet:
    Excel.Application excelApp = new Excel.Application();
    excelApp.Visible = true;
    Excel.Workbook wb = excelApp.Workbooks.Add();
    
    Excel.Worksheet ws = wb.Worksheets[1];
    Console.WriteLine(ws.Name);
    Excel.QueryTable qt=ws.QueryTables.Add("TEXT;"+csvFile,ws.get_Range("$A$1"));
    qt.TextFileParseType = Excel.XlTextParsingType.xlDelimited;
    qt.TextFileCommaDelimiter = true;
    qt.Refresh();
    qt.Delete();
    then you could detect cell value type and compare cells in excel and highlight the cells that are different.

    For more information, click here to refer about How to compare cells in excel and highlight the cells that are different

    • Marked as answer by David_JunFeng Tuesday, June 14, 2016 2:08 PM
    Thursday, June 2, 2016 4:53 AM