.net core項(xiàng)目中常用的幾款類庫詳解(值得收藏)
前言
至2002微軟公司推出.NET平臺(tái)已近15年,在互聯(lián)網(wǎng)快速迭代的浪潮中,許多語言已被淘汰,同時(shí)也有更多新的語言涌現(xiàn),但 .Net 依然堅(jiān)挺的站在系統(tǒng)開發(fā)平臺(tái)的一線陣營(yíng)中,并且隨著.NET Core正式版的到來,迎來新一輪春天。
本文主要給大家介紹了關(guān)于.net core項(xiàng)目中常用的幾款類庫的相關(guān)內(nèi)容,分享出來供大家參考學(xué)習(xí),下面話不多說了,來一起看看詳細(xì)的介紹吧。
漢字轉(zhuǎn)拼音
1、 HxfPinYin
這是我自己根據(jù)網(wǎng)上大神提供的源碼,再。net core 框架下編譯出的類庫
主要提供漢字轉(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
生成excel表格
string sFileName = $"{Guid.NewGuid()}.xlsx"; FileInfo file = new FileInfo(sFileName); string[] title = { "貨品編號(hào)", "貨品名稱", "條碼", "規(guī)格", "基本單位", "當(dāng)前庫存", "庫存下限", "庫存上限" }; 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 = { "貨品編號(hào)", "貨品名稱", "條碼", "規(guī)格", "基本單位", "當(dāng)前庫存", "庫存下限", "庫存上限" }; 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(); }
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問大家可以留言交流,謝謝大家對(duì)腳本之家的支持。
相關(guān)文章
ASP.NET MVC 從IHttp到頁面輸出的實(shí)例代碼
MVCHandler應(yīng)該算是MVC真正開始的地方。MVCHandler實(shí)現(xiàn)了IHttpHandler接口,ProcessRequest便是方法入口2013-09-09asp.net下判斷用戶什么時(shí)候離開,以什么方式離開
asp.net下判斷用戶什么時(shí)候離開,以什么方式離開...2007-03-03asp.net實(shí)現(xiàn)文件無刷新上傳方法匯總
本文給大家介紹的是asp.net實(shí)現(xiàn)文件無刷新上傳的2種方法,分別是使用swfupload插件和uploadify插件,講述的十分細(xì)致全面,附上示例,有需要的小伙伴可以參考下。2015-06-06ASP.NET泛型三之使用協(xié)變和逆變實(shí)現(xiàn)類型轉(zhuǎn)換
這篇文章介紹了ASP.NET使用協(xié)變和逆變實(shí)現(xiàn)泛型類型轉(zhuǎn)換的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-08-08.Net Core+Angular Cli/Angular4開發(fā)環(huán)境搭建教程
這篇文章主要為大家詳細(xì)介紹了.Net Core+Angular Cli/Angular4開發(fā)環(huán)境搭建教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06ASP.NET對(duì)SQLServer的通用數(shù)據(jù)庫訪問類
這篇文章主要實(shí)現(xiàn)了ASP.NET對(duì)SQLServer的通用數(shù)據(jù)庫訪問類2016-02-02wireshark抓取本地回環(huán)數(shù)據(jù)包和取出數(shù)據(jù)的方法
這篇文章主要介紹了wireshark抓取本地回環(huán)數(shù)據(jù)包和取出數(shù)據(jù)的方法,需要的朋友可以參考下2014-02-02ASP.NET Core3.1 Ocelot認(rèn)證的實(shí)現(xiàn)
這篇文章主要介紹了ASP.NET Core3.1 Ocelot認(rèn)證的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11