.net core項目中常用的幾款類庫詳解(值得收藏)
前言
至2002微軟公司推出.NET平臺已近15年,在互聯(lián)網(wǎng)快速迭代的浪潮中,許多語言已被淘汰,同時也有更多新的語言涌現(xiàn),但 .Net 依然堅挺的站在系統(tǒng)開發(fā)平臺的一線陣營中,并且隨著.NET Core正式版的到來,迎來新一輪春天。
本文主要給大家介紹了關于.net core項目中常用的幾款類庫的相關內(nèi)容,分享出來供大家參考學習,下面話不多說了,來一起看看詳細的介紹吧。
漢字轉拼音
1、 HxfPinYin

這是我自己根據(jù)網(wǎng)上大神提供的源碼,再。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

生成excel表格
string sFileName = $"{Guid.NewGuid()}.xlsx";
FileInfo file = new FileInfo(sFileName);
string[] title = { "貨品編號",
"貨品名稱",
"條碼",
"規(guī)格",
"基本單位",
"當前庫存",
"庫存下限",
"庫存上限"
};
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

生成pdf
string tempFilePath = $"{Guid.NewGuid()}.pdf";
string[] title = { "貨品編號",
"貨品名稱",
"條碼",
"規(guī)格",
"基本單位",
"當前庫存",
"庫存下限",
"庫存上限"
};
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();
}
總結
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學習或者工作具有一定的參考學習價值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。
相關文章
asp.net 數(shù)據(jù)庫的連接和datatable類
asp.net下數(shù)據(jù)庫的連接與數(shù)據(jù)庫datatable類實現(xiàn)代碼。2009-05-05
asp.net實現(xiàn)數(shù)據(jù)從DataTable導入到Excel文件并創(chuàng)建表的方法
這篇文章主要介紹了asp.net實現(xiàn)數(shù)據(jù)從DataTable導入到Excel文件并創(chuàng)建表的方法,涉及asp.net基于DataTable的數(shù)據(jù)庫及excel操作相關技巧,需要的朋友可以參考下2015-12-12
System.Timers.Timer定時執(zhí)行程序示例代碼
如果是某個邏輯功能的定時,可以將code放到邏輯功能的類的靜態(tài)構造函數(shù)中,在該邏輯類第一次執(zhí)行時,靜態(tài)構造函數(shù)會被調用,則定時自然啟動2013-06-06
The remote procedure call failed and did not execute的解決辦法
打開IIS隨便訪問一個.asp文件,提示The remote procedure call failed and did not execute2009-11-11
Asp.net mvc驗證用戶登錄之Forms實現(xiàn)詳解
這篇文章主要為大家詳細介紹了Asp.net mvc驗證用戶登錄之Forms實現(xiàn),具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-10-10

