Export Grid view to excel and save excel file to folder

前端 未结 7 745
Happy的楠姐
Happy的楠姐 2020-12-16 06:05

I want to save excel file which export data of grid view. I have written code to export gridview data to excel but I don\'t know how to save exported file.

Following

相关标签:
7条回答
  • 2020-12-16 06:46

    You can do this:

    private void ExportGridView()
    {
        System.IO.StringWriter sw = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
    
        // Render grid view control.
        gvFiles.RenderControl(htw);
    
        // Write the rendered content to a file.
        string renderedGridView = sw.ToString();
        System.IO.File.WriteAllText(@"C:\Path\On\Server\ExportedFile.xlsx", renderedGridView);
    }
    
    0 讨论(0)
提交回复
热议问题