当前位置: 移动技术网 > IT编程>开发语言>.net > .net core项目中常用的几款类库详解(值得收藏)

.net core项目中常用的几款类库详解(值得收藏)

2018年04月28日  | 移动技术网IT编程  | 我要评论

玫瑰的翻版情人,沁阳那些事,信阳区号

前言

至2002微软公司推出.net平台已近15年,在互联网快速迭代的浪潮中,许多语言已被淘汰,同时也有更多新的语言涌现,但 .net 依然坚挺的站在系统开发平台的一线阵营中,并且随着.net core正式版的到来,迎来新一轮春天。

本文主要给大家介绍了关于.net core项目中常用的几款类库的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧。

汉字转拼音

1、 hxfpinyin

这是我自己根据网上大神提供的源码,再。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 = { "货品编号",
  "货品名称",
  "条码",
  "规格",
  "基本单位",
  "当前库存",
  "库存下限",
  "库存上限"
  };
  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 = { "货品编号",
  "货品名称",
  "条码",
  "规格",
  "基本单位",
  "当前库存",
  "库存下限",
  "库存上限"
  };
  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();
  }

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对移动技术网的支持。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网