123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using Aspose.Cells;
- using System.Drawing;
- using System.Data;
- using System.Reflection;
- namespace EMIS.Utility
- {
- public class NumberMergeModel {
- public int first;
- public int last;
- public string mes;
- }
-
- public class ReportHelper
- {
- string baseFilePath = "~/Config/Report/";
- public string GetReportSql(string fileName)
- {
- string fullPath = baseFilePath + fileName.TrimStart('/');
- var physicalFullPath = System.Web.HttpContext.Current.Server.MapPath(fullPath);
- var sqlText=File.ReadAllText(physicalFullPath, Encoding.UTF8);
- return sqlText;
- }
- public Workbook GetReportTemple(string fileName) {
- string fullPath = baseFilePath + fileName.TrimStart('/');
- var physicalFullPath = System.Web.HttpContext.Current.Server.MapPath(fullPath);
- Workbook wb = new Workbook(physicalFullPath);
- return wb;
- }
- public Style BuildBorderStyle(Workbook wk) {
- var style = wk.CreateStyle();
- style.VerticalAlignment = TextAlignmentType.Center;
- style.HorizontalAlignment = TextAlignmentType.Center;
- style.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin;
- style.Borders[Aspose.Cells.BorderType.TopBorder].Color = Color.Black;
- style.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
- style.Borders[Aspose.Cells.BorderType.BottomBorder].Color = Color.Black;
- style.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin;
- style.Borders[Aspose.Cells.BorderType.RightBorder].Color = Color.Black;
- style.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
- style.Borders[Aspose.Cells.BorderType.LeftBorder].Color = Color.Black;
- return style;
- }
- public Style BuildBorderStyleAndSize(Workbook wk)
- {
- var style = wk.CreateStyle();
- style.VerticalAlignment = TextAlignmentType.Center;
- style.HorizontalAlignment = TextAlignmentType.Center;
- style.Font.Size = 18;//文字大小
- style.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin;
- style.Borders[Aspose.Cells.BorderType.TopBorder].Color = Color.Black;
- style.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
- style.Borders[Aspose.Cells.BorderType.BottomBorder].Color = Color.Black;
- style.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin;
- style.Borders[Aspose.Cells.BorderType.RightBorder].Color = Color.Black;
- style.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
- style.Borders[Aspose.Cells.BorderType.LeftBorder].Color = Color.Black;
-
- return style;
- }
- /// <summary>
- /// 连续数字合并
- /// </summary>
- /// <param name="array"></param>
- /// <returns></returns>
- public string SetNumberMerge(List<int> array) {
- List<string> texts = new List<string>();
-
- var array1 = array.Distinct().OrderBy(a => a).ToList();
- if (array1.Count < 3) {
- return string.Join(",", array1.Select(s=>s.ToString()).ToArray());
- }
- int first = array1.First(), last = array1.First();
- for (int i = 1; i <array.Count; i++) {
- if (first == last) {
- last = array1[i];
- continue;
-
- }
- if (first < last) {
- if (array1[i] - last == 1)
- {
- last = array1[i];
- }
- else
- {
- //last = array1[i];
- if (last - first == 1)
- {
- texts.Add(first.ToString());
- texts.Add(last.ToString());
-
- }
- else {
- texts.Add(first.ToString() + "-" + last.ToString());
- }
- first = array1[i];
- last = first;
- }
-
- }
-
- }
- if (first == last) {
- texts.Add(first.ToString());
- }
- if (first < last) {
- if (last - first == 1)
- {
- texts.Add(first.ToString());
- texts.Add(last.ToString());
- }
- else
- {
- texts.Add(first.ToString() + "-" + last.ToString());
- }
- }
- return string.Join(",",texts.ToArray());
-
- }
- }
- }
|