I’m trying to export lists using the CSV tool, however can’t work out how to combine them whilst retaining the grouping of data in the second list.
Essentially the excel I am trying to make is the building name and the facade sizes on that building (For the example’s sake, some buildings have 5 facades, some 3 etc)
What I’m currently trying to do:
In order to combine two lists while retaining the grouping of data in the second list, you can use the Join method in C#.
Here is an example:
List<string> list1 = new List<string>() { "A", "B", "C" };
List<string> list2 = new List<string>() { "1", "2", "3" };
var result = list1.Join(list2, x => 1, y => 1, (x, y) => new { x, y });
//This will combine the two lists into a single list of anonymous objects, each containing an element //from list1 and an element from list2.
//You can then use the `result` list to export the data to CSV using CsvHelper library
using (var writer = new StreamWriter("path/to/file.csv"))
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
{
csv.WriteRecords(result);
}
File.WriteAllLines("path/to/file.csv", result.Select(x => x.x + "," + x.y));
Sorry @Japhy , is there a way to add placeholders to multiple branches at once? I have a list with 41 branches and each have a variety of numbers inside (range from 4 to 14), So would ideally would look for a way of automating this addition of placeholders rather than manually enter them!
(This is the list I am trying to input into the solution you gave above):
How do you write the data to a CSV file? So far i’ve only found panel → stream data. Looking for a way to write the file into a directory with a button.