Solution to ASP. NET Report problems (with source code)

Source: Internet
Author: User

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! 

 
 
  1. Private StringSubTotal (IntRow,IntNum)
  2. {
  3. StringR = (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. Private StringSumTotal (StringScol,IntFirstrow,IntNum ){
  12.  
  13. StringR = num. ToString ();
  14. StringFr = firstrow. ToString ();
  15. Return "= Sum ("+ Scol + fr +":"+ Scol + r +")";
  16.  
  17. }
  18. Private VoidCreateExcelWorkbook (DataRow [] rows)
  19. {
  20. StringStrCurrentDir = Server. MapPath ("..") +"\ TempReports \\";
  21. StringLicenseFile = MapPath ("..") +"\ XML \ Aspose. Excel. lic";
  22. Excel excel =NewExcel (licenseFile,This);
  23. ;
  24. StringDesignerFile = strCurrentDir +"Cangku2.xls";
  25. Excel. Open (designerFile );
  26. Worksheet sheet = excel. Worksheets ["Sheet1"];
  27. Sheet. Name ="Wuzi";
  28. Cells cells = sheet. Cells;
  29. IntStyleIndex;
  30. StyleIndex = excel. Styles. Add ();
  31. Aspose. Excel. Style stylecell = excel. Styles [styleIndex];
  32. Stylecell. Borders [BorderType. LeftBorder]. LineStyle = CellBorderType. Thin;
  33. Stylecell. Borders [BorderType. TopBorder]. LineStyle = CellBorderType. Thin;
  34. Stylecell. Borders [BorderType. RightBorder]. LineStyle = CellBorderType. Thin;
  35. Stylecell. Borders [BorderType. BottomBorder]. LineStyle = CellBorderType. Thin;
  36. IntIRow = 4;
  37. Foreach(DataRow rowInRows)
  38. {
  39. Cells [iRow, 0]. PutValue (row [0]. ToString ());
  40. Cells [iRow, 1]. PutValue (row [1]. ToString ());
  41. Cells [iRow, 2]. PutValue (row [2]);
  42. Cells [iRow, 3]. PutValue (row [3]);
  43. Cells [iRow, 4]. PutValue (row [4]);
  44. Cells [iRow, 5]. PutValue (row [5]);
  45. Cells [iRow, 6]. PutValue (row [3]);
  46. Cells [iRow, 7]. PutValue (row [6]);
  47. Cells [iRow, 8]. PutValue (row [7]);
  48. Cells [iRow, 9]. PutValue (row [3]);
  49. Cells [iRow, 10]. PutValue (row [8]);
  50. Cells [iRow, 11]. Formula = subTotal (iRow, 0 );
  51. Cells [iRow, 12]. PutValue (row [3]);
  52. Cells [iRow, 13]. Formula = subTotal (iRow, 1 );
  53. IRow ++;
  54. }
  55. StringZj ="Total";
  56. Cells [iRow, 3]. PutValue (zj );
  57. Cells [iRow, 6]. PutValue (zj );
  58. Cells [iRow, 9]. PutValue (zj );
  59. Cells [iRow, 12]. PutValue (zj );
  60. Cells [iRow, 4]. Formula = sumTotal ("E", 5, iRow );
  61. Cells [iRow, 7]. Formula = sumTotal ("H", 5, iRow );
  62. Cells [iRow, 10]. Formula = sumTotal ("K", 5, iRow );
  63. Cells [iRow, 13]. Formula = sumTotal ("N", 5, iRow );
  64. Cells []. PutValue (cpStartDate. SelectedDate. to1_datestring ());
  65. Cells [1, 12]. PutValue (cpEndDate. SelectedDate. to1_datestring ());
  66. Range range = cells. CreateRange (, iRow-4 + );
  67. Range. Style = stylecell;
  68. For(IntI = 0; I <excel. Worksheets. Count; I ++)
  69. {
  70. Sheet = excel. Worksheets [I];
  71. If(Sheet. Name! ="Wuzi")
  72. {
  73. Excel. Worksheets. RemoveAt (I );
  74. I --;
  75. }
  76.  
  77. }
  78. /* Response. Clear (); 
  79. Response. Buffer = true; 
  80. Response. Charset = "GB2312 "; 
  81.  
  82. This. Response. ContentEncoding = System. Text. Encoding. GetEncoding ("GB2312 ");*/ 
  83. Excel. Save (HttpUtility. UrlEncode ("Resource import and export warehouse overview .xls", Encoding. UTF8), SaveType. OpenInBrowser, FileFormatType. Default,This. Response );
  84. }

Edit recommendations]

  1. Introduction to ASP. NET Report controls
  2. Shell functions in ASP. NET Environment
  3. Batch insert data to databases in ASP. NET
  4. ASP. NET sends data to webpages in Post Mode
  5. WEB Application Deployment in ASP. NET 2.0
  6. HttpWorkerRequest object in ASP. NET

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.