Answered by:
Export Data to Excel in C# Plugin

Question
-
Hi ,
I need to export Accounts entity certain columns value , data into excel sheet using plugin c#.
can you send some sample code.
Wednesday, November 6, 2013 10:55 AM
Answers
-
There are many ways.
You can simply populate a dataset with the Account records you want to export and then export that dataset as following.
public class WorkbookEngine
{
public static void CreateWorkbook(DataSet ds, String path)
{
XmlDataDocument xmlDataDoc = new XmlDataDocument(ds);
XslTransform xt = new XslTransform();
StreamReader reader =new StreamReader(typeof (WorkbookEngine).Assembly.GetManifestResourceStream(typeof (WorkbookEngine), “Excel.xsl”));
XmlTextReader xRdr = new XmlTextReader(reader);
xt.Load(xRdr, null, null);
StringWriter sw = new StringWriter();
xt.Transform(xmlDataDoc, null, sw, null);
StreamWriter myWriter = new StreamWriter (path + “\\Report.xls”);
myWriter.Write (sw.ToString());
myWriter.Close ();
}
}Code taken from: http://social.msdn.microsoft.com/Forums/vstudio/en-US/ea02f8e8-edf5-4aca-8c74-ef3a94b5328d/export-dataset-into-excel-sheet-in-c?forum=csharpgeneral
Or you can look at the following.
http://www.codeproject.com/Articles/11171/DataSet-to-Excel-in-Two-steps-with-Different-Style
Don't forget to grant enough privileges to the plugin context user on the folder where you would be saving your excel file.
- Marked as answer by kMAT1 Saturday, August 30, 2014 10:05 AM
Wednesday, November 6, 2013 11:36 AM -
There are many ways.
You can simply populate a dataset with the Account records you want to export and then export that dataset as following.
public class WorkbookEngine
{
public static void CreateWorkbook(DataSet ds, String path)
{
XmlDataDocument xmlDataDoc = new XmlDataDocument(ds);
XslTransform xt = new XslTransform();
StreamReader reader =new StreamReader(typeof (WorkbookEngine).Assembly.GetManifestResourceStream(typeof (WorkbookEngine), “Excel.xsl”));
XmlTextReader xRdr = new XmlTextReader(reader);
xt.Load(xRdr, null, null);
StringWriter sw = new StringWriter();
xt.Transform(xmlDataDoc, null, sw, null);
StreamWriter myWriter = new StreamWriter (path + “\\Report.xls”);
myWriter.Write (sw.ToString());
myWriter.Close ();
}
}Code taken from: http://social.msdn.microsoft.com/Forums/vstudio/en-US/ea02f8e8-edf5-4aca-8c74-ef3a94b5328d/export-dataset-into-excel-sheet-in-c?forum=csharpgeneral
Or you can look at the following.
http://www.codeproject.com/Articles/11171/DataSet-to-Excel-in-Two-steps-with-Different-Style
Don't forget to grant enough privileges to the plugin context user on the folder where you would be saving your excel file.
- Proposed as answer by KashifZeeshan Wednesday, November 6, 2013 11:37 AM
- Marked as answer by kMAT1 Saturday, August 30, 2014 10:05 AM
Wednesday, November 6, 2013 11:36 AM
All replies
-
There are many ways.
You can simply populate a dataset with the Account records you want to export and then export that dataset as following.
public class WorkbookEngine
{
public static void CreateWorkbook(DataSet ds, String path)
{
XmlDataDocument xmlDataDoc = new XmlDataDocument(ds);
XslTransform xt = new XslTransform();
StreamReader reader =new StreamReader(typeof (WorkbookEngine).Assembly.GetManifestResourceStream(typeof (WorkbookEngine), “Excel.xsl”));
XmlTextReader xRdr = new XmlTextReader(reader);
xt.Load(xRdr, null, null);
StringWriter sw = new StringWriter();
xt.Transform(xmlDataDoc, null, sw, null);
StreamWriter myWriter = new StreamWriter (path + “\\Report.xls”);
myWriter.Write (sw.ToString());
myWriter.Close ();
}
}Code taken from: http://social.msdn.microsoft.com/Forums/vstudio/en-US/ea02f8e8-edf5-4aca-8c74-ef3a94b5328d/export-dataset-into-excel-sheet-in-c?forum=csharpgeneral
Or you can look at the following.
http://www.codeproject.com/Articles/11171/DataSet-to-Excel-in-Two-steps-with-Different-Style
Don't forget to grant enough privileges to the plugin context user on the folder where you would be saving your excel file.
- Marked as answer by kMAT1 Saturday, August 30, 2014 10:05 AM
Wednesday, November 6, 2013 11:36 AM -
There are many ways.
You can simply populate a dataset with the Account records you want to export and then export that dataset as following.
public class WorkbookEngine
{
public static void CreateWorkbook(DataSet ds, String path)
{
XmlDataDocument xmlDataDoc = new XmlDataDocument(ds);
XslTransform xt = new XslTransform();
StreamReader reader =new StreamReader(typeof (WorkbookEngine).Assembly.GetManifestResourceStream(typeof (WorkbookEngine), “Excel.xsl”));
XmlTextReader xRdr = new XmlTextReader(reader);
xt.Load(xRdr, null, null);
StringWriter sw = new StringWriter();
xt.Transform(xmlDataDoc, null, sw, null);
StreamWriter myWriter = new StreamWriter (path + “\\Report.xls”);
myWriter.Write (sw.ToString());
myWriter.Close ();
}
}Code taken from: http://social.msdn.microsoft.com/Forums/vstudio/en-US/ea02f8e8-edf5-4aca-8c74-ef3a94b5328d/export-dataset-into-excel-sheet-in-c?forum=csharpgeneral
Or you can look at the following.
http://www.codeproject.com/Articles/11171/DataSet-to-Excel-in-Two-steps-with-Different-Style
Don't forget to grant enough privileges to the plugin context user on the folder where you would be saving your excel file.
- Proposed as answer by KashifZeeshan Wednesday, November 6, 2013 11:37 AM
- Marked as answer by kMAT1 Saturday, August 30, 2014 10:05 AM
Wednesday, November 6, 2013 11:36 AM