.net core項(xiàng)目中常用的幾款類庫(kù)詳解(值得收藏)
前言
至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)目中常用的幾款類庫(kù)的相關(guān)內(nèi)容,分享出來供大家參考學(xué)習(xí),下面話不多說了,來一起看看詳細(xì)的介紹吧。
漢字轉(zhuǎn)拼音
1、 HxfPinYin

這是我自己根據(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

生成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

生成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();
}
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問大家可以留言交流,謝謝大家對(duì)腳本之家的支持。
相關(guān)文章
Asp.net防重復(fù)提交機(jī)制實(shí)現(xiàn)方法
在Button或其他控件加上下面兩個(gè)屬性:UseSubmitBehavior="false"及OnClientClick設(shè)置控件為不可用即可,感興趣的朋友可以參考下哈2013-04-04
asp.net 數(shù)據(jù)庫(kù)的連接和datatable類
asp.net下數(shù)據(jù)庫(kù)的連接與數(shù)據(jù)庫(kù)datatable類實(shí)現(xiàn)代碼。2009-05-05
asp.net ajax實(shí)現(xiàn)無刷新驗(yàn)證碼
實(shí)現(xiàn)ajax無刷新驗(yàn)證碼首先需要兩個(gè)aspx頁(yè)面,第一個(gè)用來展示,另一個(gè)用來后臺(tái)刷新驗(yàn)證碼2011-10-10
asp.net實(shí)現(xiàn)數(shù)據(jù)從DataTable導(dǎo)入到Excel文件并創(chuàng)建表的方法
這篇文章主要介紹了asp.net實(shí)現(xiàn)數(shù)據(jù)從DataTable導(dǎo)入到Excel文件并創(chuàng)建表的方法,涉及asp.net基于DataTable的數(shù)據(jù)庫(kù)及excel操作相關(guān)技巧,需要的朋友可以參考下2015-12-12
System.Timers.Timer定時(shí)執(zhí)行程序示例代碼
如果是某個(gè)邏輯功能的定時(shí),可以將code放到邏輯功能的類的靜態(tài)構(gòu)造函數(shù)中,在該邏輯類第一次執(zhí)行時(shí),靜態(tài)構(gòu)造函數(shù)會(huì)被調(diào)用,則定時(shí)自然啟動(dòng)2013-06-06
The remote procedure call failed and did not execute的解決辦法
打開IIS隨便訪問一個(gè).asp文件,提示The remote procedure call failed and did not execute2009-11-11
Asp.net mvc驗(yàn)證用戶登錄之Forms實(shí)現(xiàn)詳解
這篇文章主要為大家詳細(xì)介紹了Asp.net mvc驗(yàn)證用戶登錄之Forms實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10
ASP.NET 動(dòng)態(tài)寫入服務(wù)器端控件
使用Asp.net進(jìn)行開發(fā)時(shí),因?yàn)槟承┬枨笤?,需要在?yè)面中動(dòng)態(tài)添加控件。當(dāng)然,這些控件可以是普通的html標(biāo)簽,也可以是Asp.net獨(dú)有的服務(wù)器端控件。2009-04-04

