Combine CSV Files without Duplicating Headings using C#


  1. Not a faster way but if the columns of the different csv files are partially mismatched then the below will solve the problem
    Also included are the helper classes containing the methods to move the data from column to row-based format then to csv format.

    1. On the line that reads, “File.ReadLines(filePaths[i]).Skip(1).Select(line => line.Split(splitter)).ForEach(spline =>” I’m getting the error below. Does anyone know what is wrong? Unfortunately my Linq is rusty.

      Error CS1061 ‘IEnumerable<string[]>’ does not contain a definition for ‘ForEach’ and no accessible extension method ‘ForEach’ accepting a first argument of type ‘IEnumerable<string[]>’ could be found (are you missing a using directive or an assembly reference?)

      Thanks in advance

  2. Author

    That sounds very useful, Declan. Thanks for sharing the code!

  3. very cool, i was just writing this exact thing myself, and your idea of merging mismatched header is genius

  4. is there a reason this would not work with an XLSX, as apposed to CSV? i changed the file extension type within the code, and attempted to combine excel spreadsheets instead, but the file keeps getting “corrupted” when attempting to open, however, when attempted with a CSV it worked fine.

  5. UwU i wonder right now, did we get other way to do this? or have library for it? But in anway this post have helped me much :3 Thanks guys

Leave a Reply (Markdown formatting available)

This site uses Akismet to reduce spam. Learn how your comment data is processed.