public void CreateExcel1(DataSet ds, string typeid, string FileName) { HttpResponse resp = System.Web.HttpContext.Current.Response; resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); resp.AppendHeader("Content-Disposition", "attachment;filename=" + FileName); resp.Charset = "UTF-8"; //HttpContext.Current.Response.ContentEncoding =System.Text.Encoding.Default; resp.ContentType = "application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel string colHeaders = "", ls_item = ""; int i = 0; //定义表对象与行对像,同时用DataSet对其值进行初始化 DataTable dt = ds.Tables[0]; DataRow[] myRow = dt.Select(""); // typeid=="1"时导出为EXCEL格式文件;typeid=="2"时导出为XML格式文件 if (typeid == "1") { //取得数据表各列标题,各标题之间以\t分割,最后一个列标题后加回车符 colHeaders += "
" + dt.Columns[i].Caption.ToString() + " | "; //colHeaders +=dt.Columns[i].Caption.ToString() +"\n"; colHeaders += "" + dt.Columns[i].Caption.ToString() + " |
" + row[i].ToString().Replace("\t", "") + " | "; ls_item += "" + row[i].ToString().Replace("\t", "") + " |