日期:2014-05-17  浏览次数:20392 次

asp.net 导出excel出现问题了
代码:
        /// <summary>
        /// 导出Excel
        /// </summary>
        /// <param name="ds">数据集</param>
        /// <param name="FileName">表名</param>
        public void CreateExcel(DataSet ds, string FileName)
        {

            HttpResponse resp;
            resp = System.Web.HttpContext.Current.Response;
            resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            resp.AppendHeader("Content-Disposition", "attachment;filename=" + FileName);
            string colHeaders = "", ls_item = "";

            DataTable dt = ds.Tables[0];
            DataRow[] myRow = dt.Select();
            int i = 0;
            int c1 = dt.Columns.Count;

            for (i = 0; i < c1; i++)
            {
                if (i == (c1 - 1))
                {
                    colHeaders += dt.Columns[i].Caption.ToString() + "\n";//换单元格
                }
                else
                {
                    colHeaders += dt.Columns[i].Caption.ToString() + "\t";
                }
            }
            resp.Write(colHeaders);

            foreach (DataRow row in myRow)
            {
                for (i = 0; i < c1; i++)
                {
                    if (i == (c1 -