The default csv export from c# like: RoomName | EquipmentName | EquipmentCode
Room1 - Television - E01
Room1 - Microwave - E02
Room2 - Television - E01
Now how can I export csv file.
How can I do that with csvWriter C# ? Please help, thanks.
I'm using a class I've found in code project and it has been useful for me. I'm kind of new programming but it is working very well! In the link below is the code I have used, just make a class and copy the code into it, include it in your main form code and start using it. You can find examples of usage in there.
https://www.codeproject.com/Articles/415732/Reading-and-Writing-CSV-Files-in-Csharp
It is not my code, it was found in the link provided :) I hope I helped you! Any question, don't hesitate to contact me I will be glad to help, right know I'm working on a project that is exporting and importing data from a csv file using this class.
Edit: Here is an example of the output and can be opened using Excel, just save it with the csv extension using the file IO of C# in visual studio Also to save the file as csv you can do it from code or from save file dialog properties.
saveFileDialog1.FileName = "CSVDATA" + DateTime.Now.ToString("yyMMdd");
saveFileDialog1.ShowDialog();
string PathName = Path.GetFullPath(saveFileDialog1.FileName);
string FileName1 = Path.GetFileName(PathName);
using (CsvFileWriter Writer = new CsvFileWriter(FileName1))
{
CsvRow Header = new CsvRow();
Header.Add(string.Format("{0}", "#2:30:UPD!"));
Writer.WriteRow(Header);
CsvRow NewRow = new CsvRow();
for (int j = 0; j < Array.GetLength(0); j++)
{
NewRow.Add(string.Format("{0}", ("" + Array[j]).PadLeft(5, '0')));
if (j == 14 || j == 29)
{
Writer.WriteRow(NewRow);
NewRow.Clear();
}
}
}
Output: (Just example I'm new formating code here in SO D:, its 15 values per row.)
#2:30:UPD!
00001,65506,00010,00010,00001,00001,00001
00000,04000,03000,00600,03500,00900,00900,00150
00400,00050,00080,00001,00030,00100,00040
00100,00000,00000,00000,00000,00300,00000,00000
I hope I was able to help you! Anything else I'll be glad to help, also sorry for the messy code, just needed it to work that time...