服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服务器之家 - 编程语言 - ASP.NET教程 - .net core项目中常用的几款类库详解(值得收藏)

.net core项目中常用的几款类库详解(值得收藏)

2020-05-25 14:08易兒善 ASP.NET教程

这篇文章主要给大家介绍了关于.net core项目中常用的几款类库的相关资料,文章通过示例代码介绍的非常详细,对大家学习或者使用.net core具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。

前言

至2002微软公司推出.NET平台已近15年,在互联网快速迭代的浪潮中,许多语言已被淘汰,同时也有更多新的语言涌现,但 .Net 依然坚挺的站在系统开发平台的一线阵营中,并且随着.NET Core正式版的到来,迎来新一轮春天。

本文主要给大家介绍了关于.net core项目中常用的几款类库的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧。

汉字转拼音

1、 HxfPinYin

.net core项目中常用的几款类库详解(值得收藏)

这是我自己根据网上大神提供的源码,再。net core 框架下编译出的类库

主要提供汉字转拼音的功能。

使用

?
1
2
3
4
5
6
7
8
9
10
11
12
public static class Pinyin
 {
 public static string ConvertEncoding(string text, Encoding srcEncoding, Encoding dstEncoding);
 public static string GetChineseText(string pinyin);
 public static string GetChineseText(string pinyin, Encoding encoding);
 public static string GetInitials(string text);
 public static string GetInitials(string text, Encoding encoding);
 public static string GetPinyin(string text);
 public static string GetPinyin(string text, Encoding encoding);
 public static string GetPinyin(char ch);
 public static string GetPinyin(char ch, Encoding encoding);
 }

excel操作

1、EPPlus.Core

.net core项目中常用的几款类库详解(值得收藏)

生成excel表格

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
string sFileName = $"{Guid.NewGuid()}.xlsx";
  FileInfo file = new FileInfo(sFileName);
  string[] src="/uploads/allimg/200525/14095LP6-2.png" />

生成pdf

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
string tempFilePath = $"{Guid.NewGuid()}.pdf";
  string[] title = { "货品编号",
  "货品名称",
  "条码",
  "规格",
  "基本单位",
  "当前库存",
  "库存下限",
  "库存上限"
  };
  using (FileStream wfs = new FileStream(tempFilePath, FileMode.OpenOrCreate)) {
  //PageSize.A4.Rotate();当需要把PDF纸张设置为横向时
  Document docPDF = new Document(PageSize.A4,10, 10, 20,20);
  PdfWriter write = PdfWriter.GetInstance(docPDF, wfs);
  docPDF.Open();
  //在这里需要注意的是,itextsharp不支持中文字符,想要显示中文字符的话需要自己设置字体
  BaseFont bsFont = BaseFont.CreateFont(@"C:\Windows\Fonts\simsun.ttc,0", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
  Font font = new Font(bsFont);
 
  float[] clos = new float[] { 40,40,40,20,20,30,30,30};// 宽度
  PdfPTable tablerow1 = new PdfPTable(clos);
  foreach (string t in title)
  {
   PdfPCell cell = new PdfPCell(new Paragraph(t, font));
   cell.MinimumHeight = 4f;
   tablerow1.AddCell(cell);
  }
  foreach (var d in list)
  {
   tablerow1.AddCell(new PdfPCell(new Paragraph(d.ProductCode, font)));
   tablerow1.AddCell(new PdfPCell(new Paragraph(d.ProductName, font)));
   tablerow1.AddCell(new PdfPCell(new Paragraph(d.BarCode, font)));
   tablerow1.AddCell(new PdfPCell(new Paragraph(d.SpecValues, font)));
   tablerow1.AddCell(new PdfPCell(new Paragraph(d.BaseUnit, font)));
   tablerow1.AddCell(new PdfPCell(new Paragraph(d.Quantity.ToString(), font)));
   tablerow1.AddCell(new PdfPCell(new Paragraph(d.DownLimitQuantity.ToString(), font)));
   tablerow1.AddCell(new PdfPCell(new Paragraph(d.UpLimitQuantity.ToString(), font)));
  }
  docPDF.Add(tablerow1);//将表格添加到pdf文档中
  docPDF.Close();//关闭
  write.Close();
  wfs.Close();
  }

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对服务器之家的支持。

原文链接:http://www.jianshu.com/p/fec63cade243

延伸 · 阅读

精彩推荐