NPOI.Core 川长思鸟来 2021-07-04 21:43 418阅读 0赞 该项目是`POI Java`项目的`.NET Core`版本。 使用`NPOI`,您可以非常轻松地读取/写入`Office 2003/2007`文件。 ### NPOI Core here, NPOI elsewhere ### 该项目适用于`NPOI Core`。 `NPOI`仍处于 [https://github.com/tonyqus/npoi][https_github.com_tonyqus_npoi] ### What is NPOI Core? ### `NPOI Core`是`NPOI`的`.NET Core`版本。 <table> <thead> <tr> <th>Assembly</th> <th>Module/Namespace</th> <th>Summary</th> </tr> </thead> <tbody> <tr> <td>Npoi.Core.dll</td> <td>Npoi.Core.POIFS</td> <td>OLE2/ActiveX文档属性读写库</td> </tr> <tr> <td>Npoi.Core.dll</td> <td>Npoi.Core.DDF</td> <td>Microsoft Office Drawing读写库</td> </tr> <tr> <td>Npoi.Core.dll</td> <td>Npoi.Core.HPSF</td> <td>OLE2/ActiveX文档读写库</td> </tr> <tr> <td>Npoi.Core.dll</td> <td>Npoi.Core.HSSF</td> <td>Microsoft Excel BIFF(Excel 97-2003)格式读写库</td> </tr> <tr> <td>Npoi.Core.dll</td> <td>Npoi.Core.SS</td> <td>Excel公用接口及Excel公式计算引擎</td> </tr> <tr> <td>Npoi.Core.dll</td> <td>Npoi.Core.Util</td> <td>基础类库,提供了很多实用功能,可用于其他读写文件格式项目的开发</td> </tr> <tr> <td>Npoi.Core.OOXML.dll</td> <td>Npoi.Core.XSSF</td> <td>Excel 2007(xlsx)格式读写库</td> </tr> <tr> <td>Npoi.Core.OOXML.dll</td> <td>Npoi.Core.XWPF</td> <td>Word 2007(docx)格式读写库</td> </tr> <tr> <td>Npoi.Core.OpenXml4Net.dll</td> <td>Npoi.Core.OpenXml4Net</td> <td>OpenXml底层zip包读写库</td> </tr> <tr> <td>Npoi.Core.OpenXmlFormats.dll</td> <td>Npoi.Core.OpenXmlFormats</td> <td>微软Office OpenXml对象关系库</td> </tr> </tbody> </table> ### Getting Started ### #### Export Excel #### var newFile = @"newbook.core.xlsx"; using (var fs = new FileStream(newFile, FileMode.Create, FileAccess.Write)) { IWorkbook workbook = new XSSFWorkbook(); ISheet sheet1 = workbook.CreateSheet("Sheet1"); sheet1.AddMergedRegion(new CellRangeAddress(0, 0, 0, 10)); var rowIndex = 0; IRow row = sheet1.CreateRow(rowIndex); row.Height = 30 * 80; row.CreateCell(0).SetCellValue("this is content, very long content, very long content, very long content, very long content"); sheet1.AutoSizeColumn(0); rowIndex++; var sheet2 = workbook.CreateSheet("Sheet2"); var style1 = workbook.CreateCellStyle(); style1.FillForegroundColor = HSSFColor.Blue.Index2; style1.FillPattern = FillPattern.SolidForeground; var style2 = workbook.CreateCellStyle(); style2.FillForegroundColor = HSSFColor.Yellow.Index2; style2.FillPattern = FillPattern.SolidForeground; var cell2 = sheet2.CreateRow(0).CreateCell(0); cell2.CellStyle = style1; cell2.SetCellValue(0); cell2 = sheet2.CreateRow(1).CreateCell(0); cell2.CellStyle = style2; cell2.SetCellValue(1); workbook.Write(fs); } #### Export Word #### var newFile2 = @"newbook.core.docx"; using (var fs = new FileStream(newFile2, FileMode.Create, FileAccess.Write)) { XWPFDocument doc = new XWPFDocument(); var p0 = doc.CreateParagraph(); p0.Alignment = ParagraphAlignment.CENTER; XWPFRun r0 = p0.CreateRun(); r0.FontFamily = "microsoft yahei"; r0.FontSize = 18; r0.IsBold = true; r0.SetText("This is title"); var p1 = doc.CreateParagraph(); p1.Alignment = ParagraphAlignment.LEFT; p1.IndentationFirstLine = 500; XWPFRun r1 = p1.CreateRun(); r1.FontFamily = "·ÂËÎ"; r1.FontSize = 12; r1.IsBold = true; r1.SetText("This is content, content content content content content content content content content"); doc.Write(fs); } [https_github.com_tonyqus_npoi]: https://github.com/tonyqus/npoi
还没有评论,来说两句吧...