A detailed explanation of several class libraries commonly used in. Net core project (worth collecting)

Time:2020-1-14

Preface

It has been nearly 15 years since Microsoft launched. Net platform in 2002. In the wave of rapid Internet iteration, many languages have been eliminated, and more new languages have emerged. But. Net is still firmly standing in the front-line camp of system development platform, and with the arrival of the official version of. Net core, it ushers in a new round of spring.

This article mainly introduces the related contents of several class libraries commonly used in the. Net core project, and shares them for your reference and study. I won’t say much next, let’s take a look at the detailed introduction.

Chinese character to Pinyin

1、 HxfPinYin

This is my own source code provided by the online God. Net core framework compiled class library

It mainly provides the function of converting Chinese characters to Pinyin.

Use


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 operation

1、EPPlus.Core

Generate excel table

string sFileName = $"{Guid.NewGuid()}.xlsx";
  FileInfo file = new FileInfo(sFileName);
  String [] title = {"item no.",
  "Item name",
  Barcode,
  "Specifications",
  "Basic units",
  "Current inventory",
  "Inventory floor",
  "Inventory cap"
  };
  using (ExcelPackage package = new ExcelPackage(file))
  {
  Excelworksheetworksheet = package.workbook.worksheets.add ("inventory information");
  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 operation

1、iTextSharp.LGPLv2.Core

Generate pdf

string tempFilePath = $"{Guid.NewGuid()}.pdf";
  String [] title = {"item no.",
  "Item name",
  Barcode,
  "Specifications",
  "Basic units",
  "Current inventory",
  "Inventory floor",
  "Inventory cap"
  };
  using (FileStream wfs = new FileStream(tempFilePath, FileMode.OpenOrCreate)) {
  //PageSize. A4. Rotate(); when PDF paper needs to be set to landscape
  Document docPDF = new Document(PageSize.A4,10, 10, 20,20);
  PdfWriter write = PdfWriter.GetInstance(docPDF, wfs);
  docPDF.Open();
  //Note here that itextsharp does not support Chinese characters. If you want to display Chinese characters, you need to set your own font 
  BaseFont bsFont = BaseFont.CreateFont(@"C:\Windows\Fonts\simsun.ttc,0", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
  Font font = new Font(bsFont);

  Float [] close = new float [] {40,40,40,20,20,30,30,30}; // width
  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); // add table to PDF document
  Docpdf. Close(); // close
  write.Close();
  wfs.Close();
  }

summary

The above is the whole content of this article. I hope that the content of this article has a certain reference learning value for everyone’s study or work. If you have any questions, you can leave a message and exchange. Thank you for your support for developepaar.