溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

.net core項(xiàng)目中常用的類庫(kù)有哪些

發(fā)布時(shí)間:2021-08-19 14:04:43 來(lái)源:億速云 閱讀:152 作者:小新 欄目:開(kāi)發(fā)技術(shù)

這篇文章將為大家詳細(xì)講解有關(guān).net core項(xiàng)目中常用的類庫(kù)有哪些,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

漢字轉(zhuǎn)拼音

1、 HxfPinYin

.net core項(xiàng)目中常用的類庫(kù)有哪些

這是我自己根據(jù)網(wǎng)上大神提供的源碼,再。net core 框架下編譯出的類庫(kù)

主要提供漢字轉(zhuǎn)拼音的功能。

使用

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項(xiàng)目中常用的類庫(kù)有哪些

生成excel表格

string sFileName = $"{Guid.NewGuid()}.xlsx";
  FileInfo file = new FileInfo(sFileName);
  string[] title = { "貨品編號(hào)",
  "貨品名稱",
  "條碼",
  "規(guī)格",
  "基本單位",
  "當(dāng)前庫(kù)存",
  "庫(kù)存下限",
  "庫(kù)存上限"
  };
  using (ExcelPackage package = new ExcelPackage(file))
  {
  ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("庫(kù)存信息");
  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項(xiàng)目中常用的類庫(kù)有哪些

生成pdf

string tempFilePath = $"{Guid.NewGuid()}.pdf";
  string[] title = { "貨品編號(hào)",
  "貨品名稱",
  "條碼",
  "規(guī)格",
  "基本單位",
  "當(dāng)前庫(kù)存",
  "庫(kù)存下限",
  "庫(kù)存上限"
  };
  using (FileStream wfs = new FileStream(tempFilePath, FileMode.OpenOrCreate)) {
  //PageSize.A4.Rotate();當(dāng)需要把PDF紙張?jiān)O(shè)置為橫向時(shí)
  Document docPDF = new Document(PageSize.A4,10, 10, 20,20);
  PdfWriter write = PdfWriter.GetInstance(docPDF, wfs);
  docPDF.Open();
  //在這里需要注意的是,itextsharp不支持中文字符,想要顯示中文字符的話需要自己設(shè)置字體 
  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();//關(guān)閉
  write.Close();
  wfs.Close();
  }

關(guān)于“.net core項(xiàng)目中常用的類庫(kù)有哪些”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI