the following code 1 does that. this would prompt for a path at the browser to save the excel sheet and the code 2 doesn't not, it saves at the server side.
Code 1 :
// Set the content type to Excel.
Response.ContentType = "application/vnd.ms-excel";
// Remove the charset from the Content-Type header.
Response.Charset = "";
// Turn off the view state.
this.EnableViewState = false;
StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
// Get the HTML for the control.
DataGrid1.RenderControl(hw);
// Write the HTML back to the browser.
Response.Write(tw.ToString());
// End the response.
Response.End();
Code 2 :
DataSet DS = somevalueDataSet();
XmlDataDocument xdd = new XmlDataDocument(DS);
XslTransform xt = new XslTransform();
string workingdir = AppDomain.CurrentDomain.BaseDirectory + "/" + "xslSheet.xsl";
xt.Load(workingdir);
string dirPath = AppDomain.CurrentDomain.BaseDirectory + "/" + "GeneratedFR";
string filePath = AppDomain.CurrentDomain.BaseDirectory + "/" + "GeneratedFR" + "/" + "Test1.xls";
if (!Directory.Exists(dirPath))
{
Directory.CreateDirectory(dirPath);
}
File.Delete(filePath);
FileStream fs = new FileStream(filePath, FileMode.Create);
using(fs)
{
xt.Transform(xdd,null,fs);
fs.Close();
}
Guru