You must Sign In to post a response.
  • Category: .NET

    Export dataset into excel file

    The forum thread has not been reviewed by Editors yet. Readers are advised to use their best judgement before accessing this thread.
    This thread will be reviewed shortly.
    If you think this thread contain inappropriate content, please report to webmaster.
    Hi
    i have a dataset and i have to bind the datas into a excel file....
    so anyone can send the related material..
  • #322
    Hi,

    Please check this link. I hope this will help you.

    http://www.dotnetjohn.com/articles.aspx?articleid=36

    Cheers!!!
    maheshsarath

  • #323
    hi

    i saw this article already...anyway thanx for ur effort...
    i am not using datagrid...
    so tell me without using data grid

  • #2365
    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

  • #48641
    Hi Gururaj,
    there is a restriction in excel sheet that u cant put more than 64000 rows in one sheet. u need to create multiple sheets.
    so in code1 which is saving the file on userside how can u handle this. I know how to create multiple sheets and save serverside (here is the link -http://www.codeproject.com/dotnet/ExportToExcel.asp)
    but i wanted it to save the file on user click. please help

  • #118109
    Simple dude

    Process.Start(filename);

  • #165489
    what is xslSheet.xsl in the above code?

  • #203847
    http://www.dotnetspider.com/Question16141.aspx?cachekey=37
    Regards
    Mr.Rajesh
    Software Engg.


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.