在server2003 iis上发布程序,导出Excel功能本机可下载,其他机器访问无法下载。
应该是服务器设置的问题,不是程序的问题。
下载代码是这样的
public void outexcel(DataTable table, string tablename)
        {
            HttpResponse resp;
            resp = Page.Response;
            resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            resp.AddHeader("Content-Disposition",
                "attachment; filename=" + System.Web.HttpUtility.UrlEncode(tablename, System.Text.Encoding.UTF8) + ".xls");
            string colHeaders = "", ls_item = "";
            int i = 0;
            DataTable dt = table;
            DataRow[] myRow = dt.Select("");
            for (i = 0; i < dt.Columns.Count; i++)
            {
                colHeaders += dt.Columns[i].ColumnName.ToString() + "\t";            }
            colHeaders += "\n";
            resp.Write(colHeaders);
            foreach (DataRow row in myRow)
            {
                for (i = 0; i < dt.Columns.Count; i++)
                {
                    ls_item += row[i].ToString() + "\t";                }
                ls_item += "\n";                resp.Write(ls_item);
                ls_item = "";
            }
            resp.End();
        }

解决方案 »

  1.   

    我也刚遇到此问题,运行项目没问题,发布到iis上就不行啦
      

  2.   

    加上try catch看看什么错误信息
      

  3.   

    myxls
    实在不行的话,用这个组件试试,这个组件不依赖EXCEL
    public static void ExportToTable(System.Data.DataTable dtData, string filename)
            {
                XlsDocument xls = new XlsDocument();
                Worksheet sheet = xls.Workbook.Worksheets.AddNamed(filename);//状态栏标题名称            int rowNum = dtData.Rows.Count;            int columnNum = dtData.Columns.Count;            int rowIndex = 1;            int columnIndex = 0;            //生成格式列
                ColumnInfo colInfo = new ColumnInfo(xls, sheet);
                colInfo.ColumnIndexStart = 0;
                colInfo.ColumnIndexEnd = Convert.ToUInt16(columnNum);
                colInfo.Width = 20 * 256;            sheet.AddColumnInfo(colInfo);            //绑定标题
                Cell cell = null;
                foreach (DataColumn dc in dtData.Columns)
                {
                    columnIndex++;                cell = sheet.Cells.AddValueCell(rowIndex, columnIndex, dc.ColumnName);
                    //cell.HorizontalAlignment = HorizontalAlignments.Centered;
                    //cell.Font.Weight = FontWeight.Bold;
                    //cell.PatternColor = Colors.Default30;
                    //cell.RightLineColor = Colors.Black;
                    //cell.RightLineStyle = 1;
                    //cell.BottomLineColor = Colors.Black;
                    //cell.BottomLineStyle = 1;
                    //cell.TopLineColor = Colors.Black;
                    //cell.TopLineStyle = 1;                cell.HorizontalAlignment = HorizontalAlignments.Centered;
                    cell.VerticalAlignment = VerticalAlignments.Centered;
                    cell.Pattern = 1;
                    cell.PatternColor = Colors.EgaBlue;
                    cell.UseBorder = true;
                    cell.TopLineStyle = 1;
                    cell.TopLineColor = Colors.Black;
                    cell.BottomLineStyle = 1;
                    cell.BottomLineColor = Colors.Black;
                    cell.LeftLineStyle = 1;
                    cell.LeftLineColor = Colors.Black;
                    cell.RightLineStyle = 1;
                    cell.RightLineColor = Colors.Black;
                    cell.Font.Bold = true;
                    cell.Font.Height = 11 * 20;
                    cell.Font.ColorIndex = 1;            }            //绑定子项数据
                for (int i = 0; i < rowNum; i++)
                {                rowIndex++;                columnIndex = 0;                for (int j = 0; j < columnNum; j++)
                    {                    columnIndex++;                    cell = sheet.Cells.AddValueCell(rowIndex, columnIndex, dtData.Rows[i][j].ToString());
                        cell.HorizontalAlignment = HorizontalAlignments.Centered;
                        cell.TextWrapRight = true;
                        cell.VerticalAlignment = VerticalAlignments.Top;
                        if (j == 0)
                        {
                            cell.LeftLineColor = Colors.Black;
                            cell.LeftLineStyle = 1;
                        }                    cell.RightLineColor = Colors.Black;
                        cell.RightLineStyle = 1;
                        cell.BottomLineColor = Colors.Black;
                        cell.BottomLineStyle = 1;                }            }            //导出
                xls.FileName = filename;
                xls.Send();
            }