当前位置:编程学习 > C#/ASP.NET >>

asp.net gridview如何导出xlsx文件

asp.net gridview如何导出xlsx文件,是要用office2010打开的, 如果导出xls文件每次打开会弹出格式不一致提示,所以想直接导出xlsx文件,谢谢
追问:能否给一下完整的代码? 谢谢
答案:string strFileName = "";
        if (DOPCUn.SelectedIndex == 0)
        {
            try
            {
            ///查询所有镇
            String strQ = " select  a as 单位, b as 编号,";
   DataTable CustomerTable = DBFun.dataTable(strQ);
            ExcelHelper ex = new ExcelHelper();
            //导入所有!(从第一行第一列开始)
            ex.DataTableToExcel(CustomerTable, 1, 1);
            //导出excel名称
            strFileName =DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day +".xls";
            //导出Excel保存的路径!
            string path = Server.MapPath("./") + "ZhenExcel\\" + strFileName;
            if (System.IO.File.Exists(path))
            {   System.IO.File.Delete(path);   }

            ex.OutputFilePath = path;
            ex.OutputExcelFile();
            linkDownLoad0.Enabled = true;
            linkDownLoad0.NavigateUrl = "ZhenExcel\\" + strFileName;
            // js.alert("Excel文件生成成功!");            }
            catch (Exception ex)
            {            }

还需要个excel 类

上一个:ASP.NET 按钮回发问题
下一个:广州asp.net开发实习如何?

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,