问题描述
public void ToTxtAll(string userid) { try { DataSet ds = AppClient.App.HRUserManager.toText(userid); string excelString = "编号t姓名t起始时间tt终止时间tt工作单位t职务t职级n"; foreach (DataRow dr in ds.Tables[0].Rows) { excelString += dr["id"].ToString() + "t" + dr["username"].ToString() + "t" + dr["startdate"].ToString() + "t"; excelString += dr["enddate"].ToString() + "t" + dr["company"].ToString() + "t" + dr["duty"].ToString() + "t"; excelString += dr["post"].ToString() + "n"; } HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Buffer = false; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8; HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode("工作简历信息.txt")); HttpContext.Current.Response.ContentType = "text/plain"; this.EnableViewState = false; HttpContext.Current.Response.Write(excelString.ToString()); HttpContext.Current.Response.End(); } catch (Exception ex) { ClientScript.RegisterClientScriptBlock(Page.GetType(), "提示", "<script>alert('导出数据出现错误!')</script>"); } } 问题补充:非常感谢,问题解决了,再问一个问题,就是身份证号导入EXCEL表格中怎么成了科学计数法的形式,如何解决?? public void ToExcelAlls() { try { DataSet ds = AppClient.App.HRUserManager.toExcel(); string excelString = "编号t人员库t部门t姓名t性别t出生日期t身份证号t工龄t健康状况t中断工作年限t进入现单位方式t"; excelString += "离退休时间t学位t全日制学历t毕业院校t单位t政治面貌t入党时间t民族t籍贯t出生地t参加工作时间t"; excelString += "进入本单位工作时间t现任职务名称t现任职务层次t任现职级时间t现学历n"; foreach (DataRow dr in ds.Tables[0].Rows) { excelString += dr["Listid"].ToString() + "t" + dr["PersonK"].ToString() + "t" + dr["Department"].ToString() + "t"; excelString += dr["HName"].ToString() + "t" + dr["Sex"].ToString() + "t" + dr["Birthday"].ToString() + "t"; excelString += "'" + dr["Code"].ToString() + "t" + dr["Workage"].ToString() + "t" + dr["Health"].ToString() + "t"; excelString += dr["Endworkdate"].ToString() + "t" + dr["Fashion"].ToString() + "t" + dr["Retirementdate"].ToString() + "t"; excelString += dr["Degree"].ToString() + "t" + dr["Fulltimexueli"].ToString() + "t" + dr["Bschool"].ToString() + "t"; excelString += dr["Company"].ToString() + "t" + dr["Zzmm"].ToString() + "t" + dr["Rdtime"].ToString() + "t"; excelString += dr["Nation"].ToString() + "t" + dr["Native"].ToString() + "t" + dr["Birthplace"].ToString() + "t"; excelString += dr["Firstworkdate"].ToString() + "t" + dr["Secondworkdate"].ToString() + "t" + dr["Duty"].ToString() + "t"; excelString += dr["Grade"].ToString() + "t" + dr["Agelimit"].ToString() + "t" + dr["Firstxueli"].ToString() + "n"; } HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("人员信息列表.xls")); HttpContext.Current.Response.ContentType = "application/ms-excel"; HttpContext.Current.Response.Write(excelString); HttpContext.Current.Response.End(); } catch (Exception ex) { ClientScript.RegisterClientScriptBlock(Page.GetType(), "提示", "<script>alert('导出数据出现错误!')</script>"); } }
解决方案
解决了,居然不给分。
解决方案二:
excelString += dr["post"].ToString() + "rn"; 加一个r就可以了。