/// <summary> /// 导出业绩的个人数据 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult showexcelone(string id) { try { string idFrom64 = DecodeBase6("gb2312", id); string[] idArray = idFrom64.Split(new char[] { ';' }); Account account = (Account)Session["Account"]; //List<TGSEXPORTOUTACHIVE> totalmodels = new List<TGSEXPORTOUTACHIVE>();; //List<TGSEXPORTOUTACHIVE> tempmodels = null; DataSet tempmodels = null; DataSet totalmodels = null; if (account.AREAID.ToString() == "0") for (int i = 4; i <= 35; i++) { tempmodels = SP.TGSExportOutAchiveDS(i, idArray[0].ToString(), DateTime.Parse(idArray[1].ToString()), DateTime.Parse(idArray[2].ToString())); //for (int j = 0; j < tempmodels.Count; j++) // totalmodels.Add(tempmodels[j]); if (i == 4) totalmodels = tempmodels; totalmodels.Merge(tempmodels); } else if (account.AREAID.ToString() == "1" || account.AREAID.ToString() == "2" || account.AREAID.ToString() == "3") { List<TGSAREASHOW> AreaList = SP.TgsAreaShow(int.Parse(account.AREAID.ToString())).ToList(); int j = 0; foreach (TGSAREASHOW ar in AreaList) { tempmodels = SP.TGSExportOutAchiveDS(int.Parse(ar.AREAID.ToString()), idArray[0].ToString(), DateTime.Parse(idArray[1].ToString()), DateTime.Parse(idArray[2].ToString())); if (j == 0) totalmodels = tempmodels; totalmodels.Merge(tempmodels); j++; //for (int j = 0; j < tempmodels.Count; j++) // totalmodels.Add(tempmodels[j]); //if (i == 4) // totalmodels = tempmodels; //totalmodels.Merge(tempmodels); } } else totalmodels = SP.TGSExportOutAchiveDS(int.Parse(account.AREAID.ToString()), idArray[0].ToString(), DateTime.Parse(idArray[1].ToString()), DateTime.Parse(idArray[2].ToString())); DataView dv = new DataView(totalmodels.Tables[0]);//将DataSet转换成DataView if (totalmodels != null) { CreateExcelone("OutachiveExcelOne.xls", dv); // return View(); return null; } //return View(); return null; } catch (System.Exception e) { return null; } } /// <summary> /// 导出个人数据(通过excel) /// </summary> /// <param name="FileName"></param> /// <param name="dv"></param> public static void CreateExcelone(string FileName, DataView dv) { //HttpResponse resp; //resp = System.Web.HttpContext.Current.Response; //resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); //resp.AppendHeader("Content-Disposition", "attachment;filename=" + FileName); //string colHeaders = ""; //string ls_item = ""; //colHeaders = "大区" + "/t" + "办事处" + "/t" + "姓名" + "/t" + "职位" + "/t" + "帐号" + "/t" + "入职日期" + "/t" + "离职日期" + "/t" + "基础工作(打卡网吧)" + "/t" + "基础工作(打卡次数)" + "/t" + "基础工作(投票)" + "/t" + "直接推广(绑定)" + "/t" + "直接推广(领取)" + "/t" + "直接推广(有效)" + "/t" + "直接推广(消费)" + "/t" + "直接推广(金额)" + "/t" + "间接推广(消费)" + "/t" + "间接推广(金额)" + "/t" + "线上推广(绑定)" + "/t" + "线上推广(领取)" + "/t" + "线上推广(消费)" + "/t" + "线上推广(金额)" + "/t" + "其他推广(绑定)" + "/t" + "其他推广(领取)" + "/t" + "其他推广(有效)" + "/t" + "其他推广(消费)" + "/t" + "其他推广(金额)" + "/t" + "录入网吧" + "/t" + "绑定网吧" + "/t" + "锁定网吧" + "/t" + "考核次数" + "/t" + "考核得分" + "/t" + "活动次数" + "/t" + "活动评估" + "/t" + "帐号封停" +"/n"; //resp.Write(colHeaders); //for (int i = 0; i < models.Count; i++) //{ // ls_item += models[i].ZONENAME + "/t"; // ls_item += models[i].AREANAME + "/t"; // ls_item += models[i].USERNAME + "/t"; // ls_item += models[i].PLACENAME + "/t"; // ls_item += models[i].UACCOUNT + "/t"; // ls_item += models[i].ENTERTIME + "/t"; // ls_item += models[i].DIMISSIONTIME + "/t"; // ls_item += models[i].CINNETBAR + "/t"; // ls_item += models[i].CINTIMES + "/t"; // ls_item += models[i].VOTETIMES + "/t"; // ls_item += models[i].BINDNUM + "/t"; // ls_item += models[i].ZJGETNUM + "/t"; // ls_item += models[i].ZJAVAILNUM + "/t"; // ls_item += models[i].ZJCONSNUM + "/t"; // ls_item += models[i].ZJCONSSUM + "/t"; // ls_item += models[i].IDCONSNUM + "/t"; // ls_item += models[i].IDCONSSUM + "/t"; // ls_item += models[i].BINDNUM + "/t"; // ls_item += models[i].XTGETNUM + "/t"; // ls_item += models[i].XTCONSNUM + "/t"; // ls_item += models[i].XTCONSSUM + "/t"; // ls_item += models[i].BINDNUM + "/t"; // ls_item += models[i].QTGETNUM + "/t"; // ls_item += models[i].QTAVAILNUM + "/t"; // ls_item += models[i].QTCONSNUM + "/t"; // ls_item += models[i].QTCONSSUM + "/t"; // ls_item += models[i].APPLYNUM + "/t"; // ls_item += models[i].BINDNUM + "/t"; // ls_item += models[i].LOCKNUM + "/t"; // ls_item += models[i].CS + "/t"; // ls_item += models[i].POINT + "/t"; // ls_item += models[i].ACTTIMES + "/t"; // ls_item += models[i].ACTGRADE + "/t"; // ls_item += models[i].BANNUM + "/t"; // ls_item += "/n"; //} //ls_item += "/n"; //ls_item += "/n"; //ls_item += "/n"; //ls_item += "数据说明: " + "/n"; //ls_item += "·打卡网吧:该推广人员打卡的网吧数量,一个网吧在一天内无论推广员打几次卡都只统计为一次。" + "/n"; //ls_item += "·打卡次数:该推广人员打卡总次数,同网吧同天的多次打卡最多统计2次。" + "/n"; //ls_item += "·投票:同一IP每款游戏每天只计算一次。投票统计只区分帐号,不论是否在推广员绑定或锁定的网吧内进行。" + "/n"; //ls_item += "·线上推广:线推帐号业绩,非线推帐号则为零 " + "/n"; //ls_item += "·其它推广:推广员帐号产生的非地推业绩 " + "/n"; //ls_item += "·绑定:该帐号被玩家(久游通行证)绑定的数量 " + "/n"; //ls_item += "·领取:该帐号被玩家绑定后发生新手卡道具领取的数量。单款游戏单独统计。 " + "/n"; //ls_item += "·有效:根据游戏和推广阶段分别定义的有效用户数量,如无特殊定义则等同与消费数。 " + "/n"; //ls_item += "·消费:有效用户中将M币划分或直接消费的用户数量 " + "/n"; //ls_item += "·录入网吧:所查询的结束日期时由该推广员录入并已通过审核的网吧数量。 " + "/n"; //ls_item += "·绑定网吧:所查询的结束日期时该推广员绑定的网吧数量" + "/n"; //ls_item += "·锁定网吧:所查询的结束日期时该推广员锁定的网吧数量 " + "/n"; //ls_item += "·考核次数:查询周期内该推广员下属网吧被考核的次数,包含主管考核和督察考核。" + "/n"; //ls_item += "·活动次数:查询周期内该推广员执行活动的次数,以执行完毕的活动(有评估结果)为准。 " + "/n"; //ls_item += "·帐号封停:查询周期内该推广员帐号被封停的天数。" + "/n"; //ls_item += "·网吧主管帐号数据为其下属推广人员数据的总和" + "/n"; //resp.Write(ls_item); //resp.End(); try { int sheetRows = 65535;//设置Sheet的行数,此为最大上限,本来是65536,因表头要占去一行 int sheetCount = (dv.Table.Rows.Count - 1) / sheetRows + 1;//计算Sheet数 GC.Collect();//垃圾回收 Application excel; _Workbook xBk; _Worksheet xSt = null; excel = new ApplicationClass(); xBk = excel.Workbooks.Add(true); //定义循环中要使用的变量 int dvRowStart; int dvRowEnd; int rowIndex = 0; int colIndex = 0; //对全部Sheet进行操作 for (int sheetIndex = 0; sheetIndex < sheetCount; sheetIndex++) { //初始化Sheet中的变量 rowIndex = 1; colIndex = 1; //计算起始行 dvRowStart = sheetIndex * sheetRows; dvRowEnd = dvRowStart + sheetRows - 1; if (dvRowEnd > dv.Table.Rows.Count - 1) { dvRowEnd = dv.Table.Rows.Count - 1; } //创建一个Sheet if (null == xSt) { xSt = (_Worksheet)xBk.Worksheets.Add(Type.Missing, Type.Missing, 1, Type.Missing); } else { xSt = (_Worksheet)xBk.Worksheets.Add(Type.Missing, xSt, 1, Type.Missing); } //设置Sheet的名称 xSt.Name = "个人数据"; if (sheetCount > 1) { xSt.Name += ((int)(sheetIndex + 1)).ToString(); } //取得标题 foreach (DataColumn col in dv.Table.Columns) { //设置标题格式 //xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex]).Interior.ColorIndex = 19; //设置标题居中对齐 //xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex]).Font.Bold = true;//设置标题为粗体 //填值,并进行下一列 switch (col.ColumnName) { case "ZONENAME": excel.Cells[rowIndex, colIndex++] = "大区"; break; case "AREANAME": excel.Cells[rowIndex, colIndex++] = "办事处"; break; case "USERNAME": excel.Cells[rowIndex, colIndex++] = "姓名"; break; case "PLACENAME": excel.Cells[rowIndex, colIndex++] = "职位"; break; case "UACCOUNT": excel.Cells[rowIndex, colIndex++] = "帐号"; break; case "ENTERTIME": excel.Cells[rowIndex, colIndex++] = "入职日期"; break; case "DIMISSIONTIME": excel.Cells[rowIndex, colIndex++] = "离职日期"; break; case "ZJGETNUM": excel.Cells[rowIndex, colIndex] = "直接推广"; xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 3]).Select(); xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 3]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; excel.Cells[rowIndex + 1, colIndex++] = "领取"; break; case "ZJAVAILNUM": excel.Cells[rowIndex + 1, colIndex++] = "有效"; break; case "ZJCONSNUM": excel.Cells[rowIndex + 1, colIndex++] = "消费"; break; case "ZJCONSSUM": excel.Cells[rowIndex + 1, colIndex++] = "金额"; break; case "IDCONSNUM": excel.Cells[rowIndex, colIndex] = "间接推广"; xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 1]).Select(); xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 1]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; excel.Cells[rowIndex + 1, colIndex++] = "消费"; break; case "IDCONSSUM": excel.Cells[rowIndex + 1, colIndex++] = "金额"; break; case "XTGETNUM": excel.Cells[rowIndex, colIndex] = "线上推广"; xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 2]).Select(); xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 2]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; excel.Cells[rowIndex + 1, colIndex++] = "领取"; break; case "XTCONSNUM": excel.Cells[rowIndex + 1, colIndex++] = "消费"; break; case "XTCONSSUM": excel.Cells[rowIndex + 1, colIndex++] = "金额"; break; case "QTGETNUM": excel.Cells[rowIndex, colIndex] = "其他推广"; xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 3]).Select(); xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 3]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; excel.Cells[rowIndex + 1, colIndex++] = "领取"; break; case "QTAVAILNUM": excel.Cells[rowIndex + 1, colIndex++] = "有效"; break; case "QTCONSNUM": excel.Cells[rowIndex + 1, colIndex++] = "消费"; break; case "QTCONSSUM": excel.Cells[rowIndex + 1, colIndex++] = "金额"; break; //case "EXECNUM": // excel.Cells[rowIndex, colIndex++] = "执行"; // break; //case "DIMNUM": // excel.Cells[rowIndex, colIndex++] = "离职"; // break; //case "NOVNUM": // excel.Cells[rowIndex, colIndex++] = "见习"; // break; case "APPLYNUM": excel.Cells[rowIndex, colIndex++] = "申请网吧"; break; //case "FREENUM": // excel.Cells[rowIndex, colIndex++] = "游离网吧"; // break; case "BINDNUM": excel.Cells[rowIndex, colIndex++] = "绑定网吧"; break; case "LOCKNUM": excel.Cells[rowIndex, colIndex++] = "锁定网吧"; break; case "CINTIMES": excel.Cells[rowIndex, colIndex] = "基础工作"; xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 2]).Select(); xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 2]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; excel.Cells[rowIndex + 1, colIndex++] = "打卡次数"; break; case "VOTETIMES": excel.Cells[rowIndex + 1, colIndex++] = "投票"; break; case "CINNETBAR": excel.Cells[rowIndex + 1, colIndex++] = "打卡网吧"; break; case "ACTIVENUM": excel.Cells[rowIndex, colIndex++] = "消费"; break; case "BANNUM": excel.Cells[rowIndex, colIndex++] = "帐号封停"; break; case "ACTTIMES": excel.Cells[rowIndex, colIndex++] = "活动次数"; break; case "ACTGRADE": excel.Cells[rowIndex, colIndex++] = "活动评估"; break; case "POINT": excel.Cells[rowIndex, colIndex++] = "考核得分"; break; case "CS": excel.Cells[rowIndex, colIndex++] = "考核次数"; break; case "AREAID": excel.Cells[rowIndex, colIndex++] = "办事处ID"; break; } //excel.Cells[rowIndex, colIndex++] = col.ColumnName; } //取得表格中数量 int drvIndex; rowIndex++; for (drvIndex = dvRowStart; drvIndex <= dvRowEnd; drvIndex++) { DataRowView row = dv[drvIndex]; //新起一行,当前单元格移至行首 rowIndex++; colIndex = 1; foreach (DataColumn col in dv.Table.Columns) { //if (col.DataType == System.Type.GetType("System.DateTime")) //{ // excel.Cells[rowIndex, colIndex] = (Convert.ToDateTime(row[col.ColumnName].ToString())).ToString("yyyy-MM-dd"); //} //else if (col.DataType == System.Type.GetType("System.String")) //{ // excel.Cells[rowIndex, colIndex] = "'" + row[col.ColumnName].ToString(); //} //else //{ excel.Cells[rowIndex, colIndex] = row[col.ColumnName].ToString(); //} colIndex++; } } //使用最佳宽度 Range allDataWithTitleRange = xSt.get_Range(excel.Cells[1, 1], excel.Cells[rowIndex, colIndex - 1]); allDataWithTitleRange.Select(); allDataWithTitleRange.Columns.AutoFit(); allDataWithTitleRange.Borders.LineStyle = 1;//将导出Excel加上边框 rowIndex++; rowIndex++; rowIndex++; colIndex = 1; excel.Cells[rowIndex, colIndex] = "数据说明: " + "/n"; xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).Select(); xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; rowIndex++; excel.Cells[rowIndex, colIndex] = "·打卡网吧:该推广人员打卡的网吧数量,一个网吧在一天内无论推广员打几次卡都只统计为一次。" + "/n"; xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).Select(); xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; rowIndex++; excel.Cells[rowIndex, colIndex] = "·打卡次数:该推广人员打卡总次数,同网吧同天的多次打卡最多统计2次。" + "/n"; xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).Select(); xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; rowIndex++; excel.Cells[rowIndex, colIndex] = "·投票:同一IP每款游戏每天只计算一次。投票统计只区分帐号,不论是否在推广员绑定或锁定的网吧内进行。" + "/n"; xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).Select(); xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; rowIndex++; excel.Cells[rowIndex, colIndex] = "·线上推广:线推帐号业绩,非线推帐号则为零 " + "/n"; xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).Select(); xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; rowIndex++; excel.Cells[rowIndex, colIndex] = "·其它推广:推广员帐号产生的非地推业绩 " + "/n"; xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).Select(); xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; rowIndex++; excel.Cells[rowIndex, colIndex] = "·绑定:该帐号被玩家(久游通行证)绑定的数量 " + "/n"; xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).Select(); xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; rowIndex++; excel.Cells[rowIndex, colIndex] = "·领取:该帐号被玩家绑定后发生新手卡道具领取的数量。单款游戏单独统计。 " + "/n"; xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).Select(); xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; rowIndex++; excel.Cells[rowIndex, colIndex] = "·有效:根据游戏和推广阶段分别定义的有效用户数量,如无特殊定义则等同与消费数。 " + "/n"; xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).Select(); xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; rowIndex++; excel.Cells[rowIndex, colIndex] = "·消费:有效用户中将M币划分或直接消费的用户数量 " + "/n"; xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).Select(); xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; rowIndex++; excel.Cells[rowIndex, colIndex] = "·录入网吧:所查询的结束日期时由该推广员录入并已通过审核的网吧数量。 " + "/n"; xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).Select(); xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; rowIndex++; excel.Cells[rowIndex, colIndex] = "·绑定网吧:所查询的结束日期时该推广员绑定的网吧数量" + "/n"; xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).Select(); xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; rowIndex++; excel.Cells[rowIndex, colIndex] = "·锁定网吧:所查询的结束日期时该推广员锁定的网吧数量 " + "/n"; xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).Select(); xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; rowIndex++; excel.Cells[rowIndex, colIndex] = "·考核次数:查询周期内该推广员下属网吧被考核的次数,包含主管考核和督察考核。" + "/n"; xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).Select(); xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; rowIndex++; excel.Cells[rowIndex, colIndex] = "·活动次数:查询周期内该推广员执行活动的次数,以执行完毕的活动(有评估结果)为准。 " + "/n"; xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).Select(); xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; rowIndex++; excel.Cells[rowIndex, colIndex] = "·帐号封停:查询周期内该推广员帐号被封停的天数。" + "/n"; xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).Select(); xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; rowIndex++; excel.Cells[rowIndex, colIndex] = "·网吧主管帐号数据为其下属推广人员数据的总和" + "/n"; xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).Select(); xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex + 20]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection; rowIndex++; } //设置导出文件在服务器上的文件夹 string exportDir = "~/ExcelFile/";//注意:该文件夹您须事先在服务器上建好才行 //设置文件在服务器上的路径 string absFileName = System.Web.HttpContext.Current.Server.MapPath(System.IO.Path.Combine(exportDir, FileName)); xBk.SaveCopyAs(absFileName); xBk.Close(false, null, null); excel.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(xBk); System.Runtime.InteropServices.Marshal.ReleaseComObject(excel); System.Runtime.InteropServices.Marshal.ReleaseComObject(xSt); xBk = null; excel = null; xSt = null; GC.Collect(); HttpContext curContext = System.Web.HttpContext.Current; curContext.Response.ContentType = "application/vnd.ms-excel"; curContext.Response.ContentEncoding = System.Text.Encoding.Default; curContext.Response.AppendHeader("Content-Disposition", ("attachment;filename=" + FileName)); curContext.Response.Charset = ""; curContext.Response.WriteFile(absFileName); curContext.Response.Flush(); curContext.Response.End(); } catch (System.Exception e) { } }