[Solved] How to load a value from a DataTable to Excel programmatically? [closed]


There are many ways to export Dataset into Excel.
Here is a very simple function to export data without using excel object and other messy stuff.
XSL Transformation is applied to dataset and XML for excel is generated.
You have to pass it the DataSet to export and path to where file should be generated.

 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 ();
 }
}

The links below contain more information that may help you:
http://www.codeproject.com/Tips/406704/Export-DataTable-to-Excel-with-Formatting-in-Cshar

Have a nice day.

solved How to load a value from a DataTable to Excel programmatically? [closed]