I am formatting a DataGridView and exporting to csv like such
private void ExportToCSV()
{
var csvString = formatteddt;
ExportToCSVClass.Save(csvString, "csv");
}
Which this takes everything into csvString to export. And this class will actually perform the export
public static class ExportToCSVClass
{
public static void Save(string content, string extension)
{
var dialog = new SaveFileDialog
{
Title = Resources.SaveCsvTitle,
DefaultExt = extension
};
if (dialog.ShowDialog() == DialogResult.OK && !string.IsNullOrWhiteSpace(dialog.FileName))
{
if (File.Exists(dialog.FileName))
{
try { File.Delete(dialog.FileName); }
catch (Exception)
{
MessageBox.Show(Resources.ErrorCantAccessFile);
return;
}
}
using (var stream = File.CreateText(dialog.FileName))
stream.Write(content);
}
}
}
What I am after is a way to split the csvString into different workbooks if the name is different. For example, the data being output could look like
(this is a copy/paste from the csv)
Joe football win
Joe baseball loose
Joe soccer win
Jack football win
Jack soccer win
Jim football loose
Now after the customization that I want is to have a workbook for eacah name so Joe, Jack and Jim would each have there own workbook. How could this be achieved using C#?
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
14 Points
22 Posts
Format Var DataType to split on Name
Dec 15, 2017 06:13 PM|HiThereItsClaire|LINK
I am formatting a DataGridView and exporting to csv like such
private void ExportToCSV()
{
var csvString = formatteddt;
ExportToCSVClass.Save(csvString, "csv");
}
Which this takes everything into csvString to export. And this class will actually perform the export
public static class ExportToCSVClass
{
public static void Save(string content, string extension)
{
var dialog = new SaveFileDialog
{
Title = Resources.SaveCsvTitle,
DefaultExt = extension
};
if (dialog.ShowDialog() == DialogResult.OK && !string.IsNullOrWhiteSpace(dialog.FileName))
{
if (File.Exists(dialog.FileName))
{
try { File.Delete(dialog.FileName); }
catch (Exception)
{
MessageBox.Show(Resources.ErrorCantAccessFile);
return;
}
}
using (var stream = File.CreateText(dialog.FileName))
stream.Write(content);
}
}
}
What I am after is a way to split the csvString into different workbooks if the name is different. For example, the data being output could look like
(this is a copy/paste from the csv)
Joe football win
Joe baseball loose
Joe soccer win
Jack football win
Jack soccer win
Jim football loose
Now after the customization that I want is to have a workbook for eacah name so Joe, Jack and Jim would each have there own workbook. How could this be achieved using C#?
Star
8670 Points
2882 Posts
Re: Format Var DataType to split on Name
Dec 18, 2017 07:52 AM|Cathy Zou|LINK
Hi HiThereItsClaire,
It seems that your application is WinForms,
If that the case, you could post you thread on WinForms forum for professional support because our forum is webform forum:
You could go to it’s forum by clicking the link below:
https://social.msdn.microsoft.com/Forums/windows/en-US/home?forum=winforms
Thanks for understanding.
Best regards
Cathy
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.