自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

ASP.NET報表問題的解決方法(附源碼)

開發(fā) 后端
做ASP.NET項目都會碰到ASP.NET報表問題,中國式報表的繁瑣讓我很是反感,可沒法子啊,客戶有需求!后來有人推薦了個控件ASPOSE解決ASP.NET報表問題,這玩意強,服務(wù)端都不用裝EXCEL,效果不錯!想偷懶的用這玩意,一個字——爽!

做ASP.NET項目都會碰到ASP.NET報表問題,中國式報表的繁瑣讓我很是反感,可沒法子啊,客戶有需求!自然而然想用DCOM直接操作EXCEL,馬馬虎虎算是成了,雖說安全性不好,資源浪費嚴重,畢竟在局域網(wǎng)中使用,湊合吧。

不過總是討厭在服務(wù)端那個沒有結(jié)束的EXCEL進程……一定要把敵人殺死!google了一把,原來當(dāng)今中外都有這個ASP.NET報表問題。解決方案也有,Windows XP下搞定,但我在WINDOWS 2003下搞了整整一天也沒殺死,得,真想自個殺了。后來有人推薦了個控件ASPOSE解決ASP.NET報表問題,這玩意強,服務(wù)端都不用裝EXCEL,效果不錯!想偷懶的用這玩意,一個字——爽! 

  1. private string subTotal(int row ,int num)  
  2.         {   
  3.             string r = (row+1).ToString();  
  4.          if( num == 0)//  
  5.          {  
  6.              return "=C"+r+"+F"+r+"-I"+r;  
  7.          }  
  8.         else 
  9.             return "=E"+r+"+H"+r+"-K"+r;  
  10.               
  11.         }  
  12.         private string sumTotal(string scol,int firstrow,int num){  
  13.  
  14.         string r = num.ToString();  
  15.             string fr = firstrow.ToString();  
  16.             return "=Sum("+scol+fr+":"+scol+r+")";  
  17.  
  18.         }  
  19.         private void CreateExcelWorkbook(DataRow[] rows)  
  20.         {  
  21.             string strCurrentDir = Server.MapPath("..") + "\\TempReports\\";  
  22.             string licenseFile = MapPath("..") + "\\XML\\Aspose.Excel.lic";               
  23.             Excel excel = new Excel(licenseFile, this);  
  24.         ;  
  25.             string designerFile = strCurrentDir+"cangku2.xls";  
  26.                         excel.Open(designerFile);  
  27.             Worksheet sheet = excel.Worksheets["Sheet1"];  
  28.             sheet.Name = "wuzi";  
  29.             Cells cells = sheet.Cells;  
  30.             int styleIndex;  
  31.               
  32.             styleIndex = excel.Styles.Add();  
  33.             Aspose.Excel.Style stylecell = excel.Styles[styleIndex];  
  34.             stylecell.Borders[BorderType.LeftBorder].LineStyle=CellBorderType.Thin;  
  35.             stylecell.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;  
  36.             stylecell.Borders[BorderType.RightBorder].LineStyle=CellBorderType.Thin;  
  37.             stylecell.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;  
  38.             int iRow =4;  
  39.             foreach(DataRow row in rows)  
  40.             {  
  41.             cells[iRow,0].PutValue(row[0].ToString());  
  42.             cells[iRow,1].PutValue(row[1].ToString());  
  43.             cells[iRow,2].PutValue(row[2]);  
  44.             cells[iRow,3].PutValue( row[3]);  
  45.             cells[iRow,4].PutValue(row[4]);  
  46.             cells[iRow,5].PutValue(row[5]);  
  47.             cells[iRow,6].PutValue(row[3]);  
  48.             cells[iRow,7].PutValue(row[6]);  
  49.             cells[iRow,8].PutValue(row[7]);  
  50.             cells[iRow,9].PutValue(row[3]);  
  51.             cells[iRow,10].PutValue(row[8]);  
  52.             cells[iRow,11].Formula=subTotal(iRow,0);  
  53.             cells[iRow,12].PutValue(row[3]);  
  54.             cells[iRow,13].Formula=subTotal(iRow,1);  
  55.             iRow++;  
  56.                 }  
  57.             string zj="總計";  
  58.                 cells[iRow,3].PutValue(zj);  
  59.                  cells[iRow,6].PutValue(zj);  
  60.                  cells[iRow,9].PutValue(zj);  
  61.                cells[iRow,12].PutValue(zj);  
  62.                 cells[iRow,4].Formula=sumTotal("E",5,iRow);  
  63.                 cells[iRow,7].Formula=sumTotal("H",5,iRow);  
  64.                 cells[iRow,10].Formula=sumTotal("K",5,iRow);  
  65.                 cells[iRow,13].Formula=sumTotal("N",5,iRow);  
  66.                 cells[1,8].PutValue(cpStartDate.SelectedDate.ToShortDateString());  
  67.                 cells[1,12].PutValue(cpEndDate.SelectedDate.ToShortDateString());  
  68.             Range range = cells.CreateRange(4,0,iRow-4+1,14);  
  69.                 range.Style = stylecell;  
  70.             for(int i = 0; i < excel.Worksheets.Count ; i ++)  
  71.             {  
  72.                 sheet = excel.Worksheets[i];  
  73.                 if(sheet.Name != "wuzi")  
  74.                 {  
  75.              excel.Worksheets.RemoveAt(i);  
  76.                     i --;  
  77.                 }  
  78.  
  79.             }  
  80.                 /*Response.Clear();  
  81.           Response.Buffer= true;  
  82.           Response.Charset="GB2312";  
  83.  
  84.         this.Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");*/ 
  85.               
  86.         excel.Save(HttpUtility.UrlEncode("物資進出庫匯總.xls",Encoding.UTF8), SaveType.OpenInBrowser,FileFormatType.Default,this.Response);  
  87. }  

【編輯推薦】

  1. 淺談ASP.NET報表控件
  2. ASP.NET環(huán)境下的Shell函數(shù)
  3. 在ASP.NET中向數(shù)據(jù)庫批量插入數(shù)據(jù)
  4. ASP.NET用Post方式向網(wǎng)頁發(fā)送數(shù)據(jù)
  5. ASP.NET 2.0部署WEB應(yīng)用程序淺析
  6. ASP.NET中的HttpWorkerRequest對像
責(zé)任編輯:老楊 來源: 模板天下
相關(guān)推薦

2009-07-22 17:50:14

2009-07-27 16:19:59

ASP.NET報表控件

2009-07-29 09:29:06

ASP.NET水晶報表

2009-07-23 10:06:29

2009-07-28 12:35:37

querystring

2009-07-28 13:26:34

Render方法ASP.NET

2009-08-06 15:56:40

ASP.NET Coo

2009-08-12 18:19:46

ASP.NET報表打印

2009-07-20 16:04:37

ASP.NET fra

2009-07-22 09:11:02

Action方法ASP.NET MVC

2009-08-05 18:47:55

ASP.NET服務(wù)器

2009-08-25 17:42:41

ASP.NET新手問題

2009-08-02 11:48:58

ASP.NET水晶報表ASP.NET

2009-07-30 13:57:39

ASP.NET水晶報表ASP.NET

2009-07-23 10:08:24

asp.net mvc

2009-07-27 17:51:58

WCF服務(wù)ASP.NET

2009-07-29 14:02:41

ASP.NET項目

2009-07-22 17:45:35

ASP.NET教程

2009-08-03 14:22:33

什么是ASP.NET

2009-07-28 17:17:19

ASP.NET概述
點贊
收藏

51CTO技術(shù)棧公眾號