.net core项目中常用的类库有哪些

发布时间:2021-08-19 14:04:43 作者:小新
来源:亿速云 阅读:135

这篇文章将为大家详细讲解有关.net core项目中常用的类库有哪些,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

汉字转拼音

1、 HxfPinYin

.net core项目中常用的类库有哪些

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

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

使用

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表格

string sFileName = $"{Guid.NewGuid()}.xlsx";
  FileInfo file = new FileInfo(sFileName);
  string[] title = { "货品编号",
  "货品名称",
  "条码",
  "规格",
  "基本单位",
  "当前库存",
  "库存下限",
  "库存上限"
  };
  using (ExcelPackage package = new ExcelPackage(file))
  {
  ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("库存信息");
  int index = 1;
  foreach (string t in title)
  {
   worksheet.Cells[1, index++].Value = t;
  }
  index = 2;
  foreach (var d in list)
  {
   worksheet.Cells[index,1].Value = d.ProductCode;
   worksheet.Cells[index, 2].Value = d.ProductName;
   worksheet.Cells[index, 3].Value = d.BarCode;
   worksheet.Cells[index, 4].Value = d.SpecValues;
   worksheet.Cells[index, 5].Value = d.BaseUnit;
   worksheet.Cells[index, 6].Value = d.Quantity;
   worksheet.Cells[index, 7].Value = d.DownLimitQuantity;
   worksheet.Cells[index, 8].Value = d.UpLimitQuantity;
   index++;
  }
  package.Save();
  }

pdf操作

1、iTextSharp.LGPLv2.Core

.net core项目中常用的类库有哪些

生成pdf

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();
  }

关于“.net core项目中常用的类库有哪些”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

推荐阅读:
  1. .NET开发笔记:如何将.NET项目迁移到.NET Core
  2. .Net基础体系和跨框架开发普及

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

core

上一篇:JavaScript正则表达式函数有哪些

下一篇:Linux Samba服务器的详细安装配置

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》