Program.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using Aspose.Cells;
  2. using Bowin.Common.Encoder.DES;
  3. using Bowin.Common.Encoder.HmacSHA1;
  4. using Bowin.Common.Office;
  5. using Bowin.Common.Utility;
  6. using Bowin.Common.WebModels;
  7. using NPOI.SS.Formula.Functions;
  8. using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Drawing;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Linq.Expressions;
  15. using System.Net;
  16. using System.Text;
  17. namespace Bowin.Common.Test
  18. {
  19. class Program
  20. {
  21. private static Style GetImportantStyle(Workbook workbook)
  22. {
  23. var style = workbook.CreateStyle();
  24. style.ForegroundColor = Color.Red;
  25. style.Pattern = BackgroundType.Solid;
  26. style.Font.Underline = Aspose.Cells.FontUnderlineType.Single;
  27. return style;
  28. }
  29. //private bool TryMatchAdd(IList<decimal> sourceList, ref decimal targetValue)
  30. //{
  31. // var addSourceList = sourceList.ToList();
  32. // addSourceList.Add(0M);
  33. // foreach (decimal source in addSourceList)
  34. // {
  35. // var newValue = targetValue + source;
  36. // if (newValue == 16224)
  37. // {
  38. // return true;
  39. // }
  40. // }
  41. //}
  42. static void Main(string[] args)
  43. {
  44. //var stream = new FileStream(@"D:\测试Aspose.xlsx", FileMode.Open);
  45. //var pictureStream = File.Open(@"I:\照片\DSC_0002.JPG", FileMode.Open);
  46. //var excel = new AsposeExcelHelper();
  47. //var excelNewStream = excel.ExportToTemplate(stream, new List<PageItem>
  48. //{
  49. // new PageItem
  50. // {
  51. // CellItemList = new List<CellItem>
  52. // {
  53. // new AsposeCellItem { Row = 3, Col = 1, Value = "单位名称:测试单位" },
  54. // new AsposeCellItem { Row = 3, Col = 4, Value = "打印时间:马上" },
  55. // new AsposeCellItem { Row = 4, Col = 1, Value = "结算时间:下次再说" },
  56. // new AsposeCellItem { Row = 4, Col = 4, Value = "联系电话:不知道" },
  57. // new AsposeCellItem { Row = 8, Col = 5, Value = "123456" }
  58. // },
  59. // ListItemList = new List<ListItem>
  60. // {
  61. // new AsposeListItem { StartRow = 7, StartColumn = 0, EndColumn = 5, Values = new string[][] {
  62. // new string[] { "1", "船1", "1000", "普通作业", "201706050001", "120000" },
  63. // new string[] { "2", "船2", "800", "普通作业", "201706050001", "3400" },
  64. // new string[] { "3", "船3", "50", "普通作业", "201706050001", "56" }
  65. // }, StyleList = new List<AsposeExcelCellStyle> {
  66. // new AsposeExcelCellStyle { ColumnIndex = 2, RowIndex = 1, StyleFunc = GetImportantStyle } ,
  67. // new AsposeExcelCellStyle { ColumnIndex = 1, RowIndex = 2, StyleFunc = GetImportantStyle }
  68. // }
  69. // }
  70. // },
  71. // PictureItemList = new List<PictureItem>
  72. // {
  73. // new PictureItem
  74. // {
  75. // StartRow = 10,
  76. // EndRow = 19,
  77. // StartColumn = 1,
  78. // EndColumn = 4,
  79. // Picture = pictureStream
  80. // }
  81. // }
  82. // }
  83. //});
  84. //var fs = File.OpenText(@"C:\Users\reicarose\Downloads\银行工资表 (3).txt");
  85. //var t = fs.ReadToEnd();
  86. //var excelFile = new FileStream(@"D:\测试Aspose结果.xlsx", FileMode.OpenOrCreate, FileAccess.ReadWrite);
  87. //excelNewStream.WriteTo(excelFile);
  88. //excelFile.Flush();
  89. //excelFile.Close();
  90. //var excel = new AsposeExcelHelper();
  91. //var dt = excel.Import(@"D:\测试Excel.xlsx");
  92. //double totalYears = DateHelper.GetYearSpan(new DateTime(2005, 5, 5), new DateTime(2020, 9, 16));
  93. //var pdfStream = ExcelToPDF.Export(excelNewStream);
  94. //var pdfFile = new FileStream(@"D:\测试Aspose.pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite);
  95. //var pdfByte = pdfStream.ToArray();
  96. //pdfFile.Write(pdfByte);
  97. //pdfFile.Flush();
  98. //pdfFile.Close();
  99. //var stream = new FileStream(@"D:\测试Aspose.xlsx", FileMode.Open);
  100. //var pdfStream = ExcelToPDF.Export(stream);
  101. //var pdfFile = new FileStream(@"D:\测试Aspose.pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite);
  102. //var pdfByte = pdfStream.ToArray();
  103. //pdfFile.Write(pdfByte);
  104. //pdfFile.Flush();
  105. //pdfFile.Close();
  106. //var s = HmacSHA1.HMACSHA1Encoder.Encode("sk", "\ntimestamp:1625653256663");
  107. //var startTime = TimeSpan.Parse("00:00:00");
  108. //var endTime = TimeSpan.Parse("08:00:00");
  109. //var webHeaders = new Dictionary<string, string>();
  110. //var timstamps = Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds).ToString();
  111. //webHeaders.Add("timestamp", timstamps);
  112. //webHeaders.Add("authorization", "e2d1a7e91a7d4cf39a83f0ab1222eef0" + ":" + HMACSHA1Encoder.Encode("4203b64dd5d44ff1adce449a8f6450d0", "\ntimestamp:" + timstamps));
  113. var systemID = "55ce2b0450082a7145b5ee9fd36dc3d9a81b13f8960b83ab9a0847efb597dd0f";
  114. var secret = "a6cb3528";
  115. var des = new DesAccessor();
  116. var key = Encoding.UTF8.GetBytes(secret).Take(8).ToArray();
  117. var iv = key;
  118. var tokenString = systemID + "|" + DateTime.Now.ToString("MMyyyyddmmHHss");
  119. var encToken = des.Encrypt(tokenString, key, iv);
  120. var webHeaders = new WebHeaderCollection();
  121. webHeaders.Add("auth-key", encToken);
  122. webHeaders.Add("auth-system", systemID);
  123. HttpWebRequest client = (HttpWebRequest)WebRequest.Create("http://localhost:5003/service/Employee/GetSailorList");
  124. client.Headers = webHeaders;
  125. client.Method = "POST";
  126. using (var response = client.GetResponse())
  127. {
  128. var stream = response.GetResponseStream();
  129. var reader = new StreamReader(stream, Encoding.UTF8);
  130. var responseText = reader.ReadToEnd();
  131. }
  132. }
  133. }
  134. }