ASP. NET projects all encounter ASP. NET Report problems. I am very disgusted with the complicated Chinese-style reports. I can't help it. Customers have demands! Naturally, if you want to use DCOM to directly operate EXCEL, you can be confused. Although the security is poor and resources are wasted heavily, you can use it in the LAN.
But I always hate the unfinished EXCEL process on the server ...... Be sure to kill the enemy! Google once, the ASP. NET Report problem exists both in China and abroad today. The solution is also available in Windows XP, but I did not kill it in WINDOWS 2003 for a whole day. So, I really want to kill myself. Later, someone recommended a control ASPOSE to solve the ASP. NET Report problem. This is a strong tool, and the server does not need to install EXCEL. This is a good result! It's a good word to use this stuff for laziness!
- Private StringSubTotal (IntRow,IntNum)
- {
- StringR = (row + 1). ToString ();
- If(Num = 0)//
- {
- Return "= C"+ R +"+ F"+ R +"-I"+ R;
- }
- Else
- Return "= E"+ R +"+ H"+ R +"-K"+ R;
- }
- Private StringSumTotal (StringScol,IntFirstrow,IntNum ){
-
- StringR = num. ToString ();
- StringFr = firstrow. ToString ();
- Return "= Sum ("+ Scol + fr +":"+ Scol + r +")";
-
- }
- Private VoidCreateExcelWorkbook (DataRow [] rows)
- {
- StringStrCurrentDir = Server. MapPath ("..") +"\ TempReports \\";
- StringLicenseFile = MapPath ("..") +"\ XML \ Aspose. Excel. lic";
- Excel excel =NewExcel (licenseFile,This);
- ;
- StringDesignerFile = strCurrentDir +"Cangku2.xls";
- Excel. Open (designerFile );
- Worksheet sheet = excel. Worksheets ["Sheet1"];
- Sheet. Name ="Wuzi";
- Cells cells = sheet. Cells;
- IntStyleIndex;
- StyleIndex = excel. Styles. Add ();
- Aspose. Excel. Style stylecell = excel. Styles [styleIndex];
- Stylecell. Borders [BorderType. LeftBorder]. LineStyle = CellBorderType. Thin;
- Stylecell. Borders [BorderType. TopBorder]. LineStyle = CellBorderType. Thin;
- Stylecell. Borders [BorderType. RightBorder]. LineStyle = CellBorderType. Thin;
- Stylecell. Borders [BorderType. BottomBorder]. LineStyle = CellBorderType. Thin;
- IntIRow = 4;
- Foreach(DataRow rowInRows)
- {
- Cells [iRow, 0]. PutValue (row [0]. ToString ());
- Cells [iRow, 1]. PutValue (row [1]. ToString ());
- Cells [iRow, 2]. PutValue (row [2]);
- Cells [iRow, 3]. PutValue (row [3]);
- Cells [iRow, 4]. PutValue (row [4]);
- Cells [iRow, 5]. PutValue (row [5]);
- Cells [iRow, 6]. PutValue (row [3]);
- Cells [iRow, 7]. PutValue (row [6]);
- Cells [iRow, 8]. PutValue (row [7]);
- Cells [iRow, 9]. PutValue (row [3]);
- Cells [iRow, 10]. PutValue (row [8]);
- Cells [iRow, 11]. Formula = subTotal (iRow, 0 );
- Cells [iRow, 12]. PutValue (row [3]);
- Cells [iRow, 13]. Formula = subTotal (iRow, 1 );
- IRow ++;
- }
- StringZj ="Total";
- Cells [iRow, 3]. PutValue (zj );
- Cells [iRow, 6]. PutValue (zj );
- Cells [iRow, 9]. PutValue (zj );
- Cells [iRow, 12]. PutValue (zj );
- Cells [iRow, 4]. Formula = sumTotal ("E", 5, iRow );
- Cells [iRow, 7]. Formula = sumTotal ("H", 5, iRow );
- Cells [iRow, 10]. Formula = sumTotal ("K", 5, iRow );
- Cells [iRow, 13]. Formula = sumTotal ("N", 5, iRow );
- Cells []. PutValue (cpStartDate. SelectedDate. to1_datestring ());
- Cells [1, 12]. PutValue (cpEndDate. SelectedDate. to1_datestring ());
- Range range = cells. CreateRange (, iRow-4 + );
- Range. Style = stylecell;
- For(IntI = 0; I <excel. Worksheets. Count; I ++)
- {
- Sheet = excel. Worksheets [I];
- If(Sheet. Name! ="Wuzi")
- {
- Excel. Worksheets. RemoveAt (I );
- I --;
- }
-
- }
- /* Response. Clear ();
- Response. Buffer = true;
- Response. Charset = "GB2312 ";
-
- This. Response. ContentEncoding = System. Text. Encoding. GetEncoding ("GB2312 ");*/
- Excel. Save (HttpUtility. UrlEncode ("Resource import and export warehouse overview .xls", Encoding. UTF8), SaveType. OpenInBrowser, FileFormatType. Default,This. Response );
- }
Edit recommendations]
- Introduction to ASP. NET Report controls
- Shell functions in ASP. NET Environment
- Batch insert data to databases in ASP. NET
- ASP. NET sends data to webpages in Post Mode
- WEB Application Deployment in ASP. NET 2.0
- HttpWorkerRequest object in ASP. NET