ReportHelper.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using Aspose.Cells;
  7. using System.Drawing;
  8. using System.Data;
  9. using System.Reflection;
  10. namespace EMIS.Utility
  11. {
  12. public class NumberMergeModel {
  13. public int first;
  14. public int last;
  15. public string mes;
  16. }
  17. public class ReportHelper
  18. {
  19. string baseFilePath = "~/Config/Report/";
  20. public string GetReportSql(string fileName)
  21. {
  22. string fullPath = baseFilePath + fileName.TrimStart('/');
  23. var physicalFullPath = System.Web.HttpContext.Current.Server.MapPath(fullPath);
  24. var sqlText=File.ReadAllText(physicalFullPath, Encoding.UTF8);
  25. return sqlText;
  26. }
  27. public Workbook GetReportTemple(string fileName) {
  28. string fullPath = baseFilePath + fileName.TrimStart('/');
  29. var physicalFullPath = System.Web.HttpContext.Current.Server.MapPath(fullPath);
  30. Workbook wb = new Workbook(physicalFullPath);
  31. return wb;
  32. }
  33. public Style BuildBorderStyle(Workbook wk) {
  34. var style = wk.CreateStyle();
  35. style.VerticalAlignment = TextAlignmentType.Center;
  36. style.HorizontalAlignment = TextAlignmentType.Center;
  37. style.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin;
  38. style.Borders[Aspose.Cells.BorderType.TopBorder].Color = Color.Black;
  39. style.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
  40. style.Borders[Aspose.Cells.BorderType.BottomBorder].Color = Color.Black;
  41. style.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin;
  42. style.Borders[Aspose.Cells.BorderType.RightBorder].Color = Color.Black;
  43. style.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
  44. style.Borders[Aspose.Cells.BorderType.LeftBorder].Color = Color.Black;
  45. return style;
  46. }
  47. public Style BuildBorderStyleAndSize(Workbook wk)
  48. {
  49. var style = wk.CreateStyle();
  50. style.VerticalAlignment = TextAlignmentType.Center;
  51. style.HorizontalAlignment = TextAlignmentType.Center;
  52. style.Font.Size = 18;//文字大小
  53. style.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin;
  54. style.Borders[Aspose.Cells.BorderType.TopBorder].Color = Color.Black;
  55. style.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
  56. style.Borders[Aspose.Cells.BorderType.BottomBorder].Color = Color.Black;
  57. style.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin;
  58. style.Borders[Aspose.Cells.BorderType.RightBorder].Color = Color.Black;
  59. style.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
  60. style.Borders[Aspose.Cells.BorderType.LeftBorder].Color = Color.Black;
  61. return style;
  62. }
  63. /// <summary>
  64. /// 连续数字合并
  65. /// </summary>
  66. /// <param name="array"></param>
  67. /// <returns></returns>
  68. public string SetNumberMerge(List<int> array) {
  69. List<string> texts = new List<string>();
  70. var array1 = array.Distinct().OrderBy(a => a).ToList();
  71. if (array1.Count < 3) {
  72. return string.Join(",", array1.Select(s=>s.ToString()).ToArray());
  73. }
  74. int first = array1.First(), last = array1.First();
  75. for (int i = 1; i <array.Count; i++) {
  76. if (first == last) {
  77. last = array1[i];
  78. continue;
  79. }
  80. if (first < last) {
  81. if (array1[i] - last == 1)
  82. {
  83. last = array1[i];
  84. }
  85. else
  86. {
  87. //last = array1[i];
  88. if (last - first == 1)
  89. {
  90. texts.Add(first.ToString());
  91. texts.Add(last.ToString());
  92. }
  93. else {
  94. texts.Add(first.ToString() + "-" + last.ToString());
  95. }
  96. first = array1[i];
  97. last = first;
  98. }
  99. }
  100. }
  101. if (first == last) {
  102. texts.Add(first.ToString());
  103. }
  104. if (first < last) {
  105. if (last - first == 1)
  106. {
  107. texts.Add(first.ToString());
  108. texts.Add(last.ToString());
  109. }
  110. else
  111. {
  112. texts.Add(first.ToString() + "-" + last.ToString());
  113. }
  114. }
  115. return string.Join(",",texts.ToArray());
  116. }
  117. }
  118. }