Gridview查询得到数据后,根据日期在服务器端生成了相应的EXCEL文档,我想生成文档后直接就打该文档,应如何写代码呢。

解决方案 »

  1.   

    打开EXCEL模板赋值到单元格
     Excel.Application app = new Application();
            Excel._Workbook book;
            Excel._Worksheet sheet;
            book = (Excel._Workbook)app.Workbooks.Open(strPath, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); book.Save();
            book.Close(null, null, null);
            app.Workbooks.Close();
            app.Quit();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(book);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(sheet);
            sheet = null;
            book = null;
            app = null;
    输出实现下载
    或gridview导出EXCEL
      

  2.   

    下述是用GemBox控件实现的 
    ExcelFile excelFile = new ExcelFile();
            ExcelWorksheet sheet = excelFile.Worksheets.Add("报表");
            int columns = GridView1.Columns.Count;
            int rows = GridView1.Rows.Count;        sheet.Cells[1, 0].Value = GridView1.Rows[0].Cells[0].Text;
            
            string temp_path = Server.MapPath("xls_files");
            string tick = DateTime.Now.Ticks.ToString();
           string save_path = temp_path + "\\"+ tick + ".xls";
           excelFile.SaveXls(save_path);
    //上述代码已经在服务器上生成一个EXCEL文档,我想在生成EXCEL文档后能在客户端直接弹出一个打开,保存该文档的对话框,下载到客户端,不知怎么实现。
      

  3.   

    3楼的没理解我的意思,我的意思是一个button.click就要实现查询数据生成EXCEL文档并在服务器上保存完后自动就在客户端弹出打开、保存该文档。
      

  4.   

    首先,我不建议你保存excel的
    因为excel只能保存65K多条。
    所以我一般都保存为csv格式的,我处理的数据随便一搞就几十万
      

  5.   

    已自己解决实现导出到EXCEL 复杂报表及简单的名册导出均已实现。