[ad_1]
I have a C# program that is supposed to generate an output that looks like this:
However, my output currently looks like this:
This is what my code looks like at the moment:
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
using (StreamWriter writer = new StreamWriter(outputPath, false, new UTF8Encoding(true)))
{
writer.WriteLine("");
writer.WriteLine("");
writer.WriteLine(String.Join(",", ",", "H2 2020", ",", ",", ",", "H1 2021", ",", ",", ",", "H2 2021"));
writer.WriteLine(String.Join(",", ",", "Searches", "Impressions", "Net Cost", ",", ",", "Searches", "Impressions", "Net Cost", ",", ",", "Searches", "Impressions", "Net Cost" ));
foreach (OutputRow outputRow in outputRows)
{
writer.WriteLine(String.Join(",", outputRow.Brand, outputRow.SearchesA, outputRow.ImpressionsA, outputRow.NetCostA, ",", ",", outputRow.Brand, outputRow.SearchesB, outputRow.ImpressionsB, outputRow.NetCostB, ",", ",", outputRow.Brand, outputRow.SearchesC, outputRow.ImpressionsC, outputRow.NetCostC));
}
}
After reading other answers on here about skipping cells/adding empty cells in a CSV writer, all one should have to do is add a string with a comma where they want to have an empty cell. As you can see, I’ve gotten the top two rows to look acceptable even though the amount of strings of commas does not match up with the amount of empty cells between the strings of words. My question is: What can I do to add the correct amount of empty cells to make this look like the correct output I’ve posted and why do my comma strings not generate the correct amount of empty cells?
[ad_2]