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

asp.net 导出(下载)Excel xp、win7 兼容
服务器上 .net 2008 / excel 2003
C# code

            respObj.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            respObj.AppendHeader("Content-Disposition", "attachment;filename=" + strFileName);
            string strColHeaders = "", strLstItem = "";
            int i = 0;
            DataSet dstObj = GetDataSet(strSQL, strTableName);
            DataTable dtblObj = dstObj.Tables[0];
            DataRow[] drowObj = dtblObj.Select("");
            // strTypeID=="1"
            if (strTypeID == "1")
            {
                for (i = 0; i <= dtblObj.Columns.Count - 2; i++)
                {
                    strColHeaders += dtblObj.Columns[i].Caption.ToString() + "\t";
                }
                strColHeaders += dtblObj.Columns[i].Caption.ToString() + "\n";
                respObj.Write(strColHeaders);

                foreach (DataRow drowObjTmp in drowObj)
                {
                    for (i = 0; i <= dtblObj.Columns.Count - 2; i++)
                    {
                        strLstItem += drowObjTmp[i].ToString() + "\t";
                    }
                    strLstItem += drowObjTmp[i].ToString() + "\n";
                    respObj.Write(strLstItem);
                    strLstItem = "";
                }
            }


问题 win7 导出的Excel 打不开 有什么办法?