{"id":382182,"date":"2024-06-29T04:06:48","date_gmt":"2024-06-29T04:06:48","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=382182"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=382182","title":{"rendered":"<span>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 C# \u0438 NPOI \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u0430\u0439\u043b\u0430\u043c\u0438 Excel<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/32d\/8b1\/d3d\/32d8b1d3db0c98c3096aef7c0188d9a9.png\" width=\"1200\" height=\"630\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/32d\/8b1\/d3d\/32d8b1d3db0c98c3096aef7c0188d9a9.png\"\/><\/figure>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 NPOI?<\/h2>\n<p>NPOI &#8212; \u044d\u0442\u043e .NET-\u0432\u0435\u0440\u0441\u0438\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430 POI \u043d\u0430 Java, \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <a href=\"http:\/\/poi.apache.org\/\" rel=\"noopener noreferrer nofollow\">http:\/\/poi.apache.org\/<\/a>. POI \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c \u0441 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0432\u0430\u043c \u0447\u0438\u0442\u0430\u0442\u044c\/\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b xls(x), doc(x), ppt(x). \u041e\u043d \u0438\u043c\u0435\u0435\u0442 \u0448\u0438\u0440\u043e\u043a\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435.<br \/> \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u043b\u044f:<\/p>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0442\u0447\u0435\u0442\u0430 Excel \u0431\u0435\u0437 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u043f\u0430\u043a\u0435\u0442\u0430 Microsoft Office \u0438 \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b, \u0447\u0435\u043c \u0432\u044b\u0437\u043e\u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 Microsoft Excel ActiveX \u0432 \u0444\u043e\u043d\u043e\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435;<\/p>\n<\/li>\n<li>\n<p>\u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u0430 \u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 Excel, Word \u0438 PowerPoint;<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043b\u0438\u0441\u0442\u043e\u0432 Excel, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0445 \u0444\u043e\u0440\u043c\u0443\u043b\u044b.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0441\u044c \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c \u0432\u0430\u0441 \u0441 \u0442\u0435\u043c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c, \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0444\u0430\u0439\u043b\u044b .XLSX \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c NPOI \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 C#.<\/p>\n<h2>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 NOPI \u0447\u0435\u0440\u0435\u0437 NuGet<\/h2>\n<p>PM>Install-Package NPOI<\/p>\n<h2>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0438\u043c\u0435\u043d NPOI<\/h2>\n<pre><code>using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using NPOI.SS.Util; using NPOI.HSSF.Util;<\/code><\/pre>\n<h2>\u041f\u0440\u0438\u043c\u0435\u0440 1. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 Excel \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/h2>\n<pre><code>\/\/ \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0439 \u0440\u0430\u0431\u043e\u0447\u0435\u0439 \u043a\u043d\u0438\u0433\u0438 IWorkbook workbook = new XSSFWorkbook();  \/\/ \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043b\u0438\u0441\u0442\u0430 ISheet sheet = workbook.CreateSheet(\"Sheet1\");  \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u044f\u0447\u0435\u0439\u043a\u0438 IRow row = sheet.CreateRow(0); row.CreateCell(0).SetCellValue(\"\u041f\u0440\u0438\u0432\u0435\u0442\"); row.CreateCell(1).SetCellValue(\"\u041c\u0438\u0440\");  \/\/ \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 Excel using (FileStream fileStream = new FileStream(\"path\/file.xlsx\", FileMode.Create)) {     workbook.Write(fileStream, false); }<\/code><\/pre>\n<h2>\u041f\u0440\u0438\u043c\u0435\u0440 2. \u0427\u0442\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 Excel<\/h2>\n<pre><code>\/\/ \u041e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0440\u0430\u0431\u043e\u0447\u0435\u0439 \u043a\u043d\u0438\u0433\u0438 IWorkbook workbook; using (FileStream fileStream = new FileStream(\"path\/file.xlsx\", FileMode.Open, FileAccess.Read)) {     workbook = new XSSFWorkbook(fileStream); }  \/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043b\u0438\u0441\u0442\u0430 ISheet sheet = workbook.GetSheetAt(0);  \/\/ \u0427\u0442\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u044f\u0447\u0435\u0439\u043a\u0438 IRow row = sheet.GetRow(0); string cellValue = row.GetCell(0).StringCellValue;  \/\/ \u0412\u044b\u0432\u043e\u0434 \u0434\u0430\u043d\u043d\u044b\u0445 \u044f\u0447\u0435\u0439\u043a\u0438 Console.WriteLine(cellValue);<\/code><\/pre>\n<h2>\u041f\u0440\u0438\u043c\u0435\u0440 3. \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435 Excel<\/h2>\n<pre><code>\/\/ \u041e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0440\u0430\u0431\u043e\u0447\u0435\u0439 \u043a\u043d\u0438\u0433\u0438 IWorkbook workbook; using (FileStream fileStream = new FileStream(\"path\/file.xlsx\", FileMode.Open, FileAccess.ReadWrite)) {     workbook = new XSSFWorkbook(fileStream); }  \/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043b\u0438\u0441\u0442\u0430 ISheet sheet = workbook.GetSheetAt(0);  \/\/ \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u044f\u0447\u0435\u0439\u043a\u0438 IRow row = sheet.GetRow(0); row.GetCell(0).SetCellValue(\"\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\");  \/\/ \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 Excel using (FileStream fileStream = new FileStream(\"path\/file.xlsx\", FileMode.Create)) {     workbook.Write(fileStream, false); }<\/code><\/pre>\n<h2>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438<\/h2>\n<p><strong>\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u044f\u0447\u0435\u0435\u043a:<\/strong><\/p>\n<pre><code>\/\/ \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b CellRangeAddress: \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430, \u043a\u043e\u043d\u0435\u0447\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430, \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446, \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, 0));<\/code><\/pre>\n<p><strong>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u044f:<\/strong><\/p>\n<pre><code>\/\/ \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u0442\u0438\u043b\u044f ICellStyle cellStyle = workbook.CreateCellStyle(); \/\/ \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u044f cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center; \/\/ \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u044f cellStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center; \/\/ \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043e\u0442\u0441\u0442\u0443\u043f\u0430 cellStyle.Indention = 3; \/\/ \u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0435\u0440\u0435\u043d\u043e\u0441 \u0442\u0435\u043a\u0441\u0442\u0430 cellStyle.WrapText = true; \/\/ \u0423\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0448\u0440\u0438\u0444\u0442\u0430 \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u044f\u0447\u0435\u0439\u043a\u0438 cellStyle.ShrinkToFit = true; \/\/ \u0412\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430 cellStyle.Rotation = 90; \/\/ \u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u0442\u0438\u043b\u044f sheet.GetRow(0).GetCell(0).CellStyle = cellStyle;<\/code><\/pre>\n<p><strong>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0448\u0440\u0438\u0444\u0442\u0430:<\/strong><\/p>\n<pre><code>\/\/ \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0448\u0440\u0438\u0444\u0442\u0430 IFont font = workbook.CreateFont(); \/\/ \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0448\u0440\u0438\u0444\u0442\u0430 font.FontName = \"Times New Roman\"; \/\/ \u0416\u0438\u0440\u043d\u044b\u0439 \u0448\u0440\u0438\u0444\u0442 font.IsBold = true; \/\/ \u041a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u0448\u0440\u0438\u0444\u0442 font.IsItalic = true; \/\/ \u0420\u0430\u0437\u043c\u0435\u0440 \u0448\u0440\u0438\u0444\u0442\u0430 font.FontHeightInPoints = 14; \/\/ \u041f\u043e\u0434\u0447\u0435\u0440\u043a\u043d\u0443\u0442\u044b\u0439 \u0448\u0440\u0438\u0444\u0442 font.Underline = FontUnderlineType.Single; \/\/ \u0426\u0432\u0435\u0442 \u0448\u0440\u0438\u0444\u0442\u0430 font.Color = HSSFColor.Black.Index; \/\/ \u0417\u0430\u0447\u0435\u0440\u043a\u043d\u0443\u0442\u044b\u0439 \u0448\u0440\u0438\u0444\u0442 font.IsStrikeout = true; \/\/ \u0412\u0435\u0440\u0445\u043d\u0438\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \/\/font.TypeOffset = FontSuperScript.Super; \/\/ \u041d\u0438\u0436\u043d\u0438\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \/\/font.TypeOffset = FontSuperScript.Sub; \/\/ \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u0442\u0438\u043b\u044f ICellStyle cellStyle = workbook.CreateCellStyle(); cellStyle.SetFont(font); \/\/ \u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u0442\u0438\u043b\u044f sheet.GetRow(0).GetCell(0).CellStyle = cellStyle;<\/code><\/pre>\n<p><strong>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0446\u0432\u0435\u0442\u0430 \u0437\u0430\u043b\u0438\u0432\u043a\u0438 \u044f\u0447\u0435\u0439\u043a\u0438:<\/strong><\/p>\n<pre><code>\/\/ \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u0442\u0438\u043b\u044f ICellStyle cellStyle = workbook.CreateCellStyle(); \/\/ \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0446\u0432\u0435\u0442\u0430 cellStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Pink.Index; cellStyle.FillPattern = FillPattern.SolidForeground; \/\/ \u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u0442\u0438\u043b\u044f sheet.GetRow(0).GetCell(0).CellStyle = cellStyle;<\/code><\/pre>\n<p><strong>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0432\u044b\u0441\u043e\u0442\u044b \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0448\u0438\u0440\u0438\u043d\u044b \u0441\u0442\u043e\u043b\u0431\u0446\u0430:<\/strong><\/p>\n<pre><code>\/\/ \u0412\u044b\u0441\u043e\u0442\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 row.Height = 25 * 20; \/\/ \u0428\u0438\u0440\u0438\u043d\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 sheet.SetColumnWidth(0, 18 * 256);<\/code><\/pre>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/745696\/\"> https:\/\/habr.com\/ru\/articles\/745696\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><\/figure>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 NPOI?<\/h2>\n<p>NPOI &#8212; \u044d\u0442\u043e .NET-\u0432\u0435\u0440\u0441\u0438\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430 POI \u043d\u0430 Java, \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <a href=\"http:\/\/poi.apache.org\/\" rel=\"noopener noreferrer nofollow\">http:\/\/poi.apache.org\/<\/a>. POI \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c \u0441 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0432\u0430\u043c \u0447\u0438\u0442\u0430\u0442\u044c\/\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b xls(x), doc(x), ppt(x). \u041e\u043d \u0438\u043c\u0435\u0435\u0442 \u0448\u0438\u0440\u043e\u043a\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435.<br \/> \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u043b\u044f:<\/p>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0442\u0447\u0435\u0442\u0430 Excel \u0431\u0435\u0437 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u043f\u0430\u043a\u0435\u0442\u0430 Microsoft Office \u0438 \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b, \u0447\u0435\u043c \u0432\u044b\u0437\u043e\u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 Microsoft Excel ActiveX \u0432 \u0444\u043e\u043d\u043e\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435;<\/p>\n<\/li>\n<li>\n<p>\u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u0430 \u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 Excel, Word \u0438 PowerPoint;<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043b\u0438\u0441\u0442\u043e\u0432 Excel, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0445 \u0444\u043e\u0440\u043c\u0443\u043b\u044b.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0441\u044c \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c \u0432\u0430\u0441 \u0441 \u0442\u0435\u043c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c, \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0444\u0430\u0439\u043b\u044b .XLSX \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c NPOI \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 C#.<\/p>\n<h2>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 NOPI \u0447\u0435\u0440\u0435\u0437 NuGet<\/h2>\n<p>PM>Install-Package NPOI<\/p>\n<h2>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0438\u043c\u0435\u043d NPOI<\/h2>\n<pre><code>using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using NPOI.SS.Util; using NPOI.HSSF.Util;<\/code><\/pre>\n<h2>\u041f\u0440\u0438\u043c\u0435\u0440 1. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 Excel \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/h2>\n<pre><code>\/\/ \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0439 \u0440\u0430\u0431\u043e\u0447\u0435\u0439 \u043a\u043d\u0438\u0433\u0438 IWorkbook workbook = new XSSFWorkbook();  \/\/ \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043b\u0438\u0441\u0442\u0430 ISheet sheet = workbook.CreateSheet(\"Sheet1\");  \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u044f\u0447\u0435\u0439\u043a\u0438 IRow row = sheet.CreateRow(0); row.CreateCell(0).SetCellValue(\"\u041f\u0440\u0438\u0432\u0435\u0442\"); row.CreateCell(1).SetCellValue(\"\u041c\u0438\u0440\");  \/\/ \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 Excel using (FileStream fileStream = new FileStream(\"path\/file.xlsx\", FileMode.Create)) {     workbook.Write(fileStream, false); }<\/code><\/pre>\n<h2>\u041f\u0440\u0438\u043c\u0435\u0440 2. \u0427\u0442\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 Excel<\/h2>\n<pre><code>\/\/ \u041e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0440\u0430\u0431\u043e\u0447\u0435\u0439 \u043a\u043d\u0438\u0433\u0438 IWorkbook workbook; using (FileStream fileStream = new FileStream(\"path\/file.xlsx\", FileMode.Open, FileAccess.Read)) {     workbook = new XSSFWorkbook(fileStream); }  \/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043b\u0438\u0441\u0442\u0430 ISheet sheet = workbook.GetSheetAt(0);  \/\/ \u0427\u0442\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u044f\u0447\u0435\u0439\u043a\u0438 IRow row = sheet.GetRow(0); string cellValue = row.GetCell(0).StringCellValue;  \/\/ \u0412\u044b\u0432\u043e\u0434 \u0434\u0430\u043d\u043d\u044b\u0445 \u044f\u0447\u0435\u0439\u043a\u0438 Console.WriteLine(cellValue);<\/code><\/pre>\n<h2>\u041f\u0440\u0438\u043c\u0435\u0440 3. \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435 Excel<\/h2>\n<pre><code>\/\/ \u041e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0440\u0430\u0431\u043e\u0447\u0435\u0439 \u043a\u043d\u0438\u0433\u0438 IWorkbook workbook; using (FileStream fileStream = new FileStream(\"path\/file.xlsx\", FileMode.Open, FileAccess.ReadWrite)) {     workbook = new XSSFWorkbook(fileStream); }  \/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043b\u0438\u0441\u0442\u0430 ISheet sheet = workbook.GetSheetAt(0);  \/\/ \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u044f\u0447\u0435\u0439\u043a\u0438 IRow row = sheet.GetRow(0); row.GetCell(0).SetCellValue(\"\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\");  \/\/ \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 Excel using (FileStream fileStream = new FileStream(\"path\/file.xlsx\", FileMode.Create)) {     workbook.Write(fileStream, false); }<\/code><\/pre>\n<h2>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438<\/h2>\n<p><strong>\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u044f\u0447\u0435\u0435\u043a:<\/strong><\/p>\n<pre><code>\/\/ \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b CellRangeAddress: \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430, \u043a\u043e\u043d\u0435\u0447\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430, \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446, \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, 0));<\/code><\/pre>\n<p><strong>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u044f:<\/strong><\/p>\n<pre><code>\/\/ \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u0442\u0438\u043b\u044f ICellStyle cellStyle = workbook.CreateCellStyle(); \/\/ \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u044f cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center; \/\/ \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u044f cellStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center; \/\/ \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043e\u0442\u0441\u0442\u0443\u043f\u0430 cellStyle.Indention = 3; \/\/ \u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0435\u0440\u0435\u043d\u043e\u0441 \u0442\u0435\u043a\u0441\u0442\u0430 cellStyle.WrapText = true; \/\/ \u0423\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0448\u0440\u0438\u0444\u0442\u0430 \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u044f\u0447\u0435\u0439\u043a\u0438 cellStyle.ShrinkToFit = true; \/\/ \u0412\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430 cellStyle.Rotation = 90; \/\/ \u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u0442\u0438\u043b\u044f sheet.GetRow(0).GetCell(0).CellStyle = cellStyle;<\/code><\/pre>\n<p><strong>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0448\u0440\u0438\u0444\u0442\u0430:<\/strong><\/p>\n<pre><code>\/\/ \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0448\u0440\u0438\u0444\u0442\u0430 IFont font = workbook.CreateFont(); \/\/ \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0448\u0440\u0438\u0444\u0442\u0430 font.FontName = \"Times New Roman\"; \/\/ \u0416\u0438\u0440\u043d\u044b\u0439 \u0448\u0440\u0438\u0444\u0442 font.IsBold = true; \/\/ \u041a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u0448\u0440\u0438\u0444\u0442 font.IsItalic = true; \/\/ \u0420\u0430\u0437\u043c\u0435\u0440 \u0448\u0440\u0438\u0444\u0442\u0430 font.FontHeightInPoints = 14; \/\/ \u041f\u043e\u0434\u0447\u0435\u0440\u043a\u043d\u0443\u0442\u044b\u0439 \u0448\u0440\u0438\u0444\u0442 font.Underline = FontUnderlineType.Single; \/\/ \u0426\u0432\u0435\u0442 \u0448\u0440\u0438\u0444\u0442\u0430 font.Color = HSSFColor.Black.Index; \/\/ \u0417\u0430\u0447\u0435\u0440\u043a\u043d\u0443\u0442\u044b\u0439 \u0448\u0440\u0438\u0444\u0442 font.IsStrikeout = true; \/\/ \u0412\u0435\u0440\u0445\u043d\u0438\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \/\/font.TypeOffset = FontSuperScript.Super; \/\/ \u041d\u0438\u0436\u043d\u0438\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \/\/font.TypeOffset = FontSuperScript.Sub; \/\/ \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u0442\u0438\u043b\u044f ICellStyle cellStyle = workbook.CreateCellStyle(); cellStyle.SetFont(font); \/\/ \u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u0442\u0438\u043b\u044f sheet.GetRow(0).GetCell(0).CellStyle = cellStyle;<\/code><\/pre>\n<p><strong>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0446\u0432\u0435\u0442\u0430 \u0437\u0430\u043b\u0438\u0432\u043a\u0438 \u044f\u0447\u0435\u0439\u043a\u0438:<\/strong><\/p>\n<pre><code>\/\/ \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u0442\u0438\u043b\u044f ICellStyle cellStyle = workbook.CreateCellStyle(); \/\/ \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0446\u0432\u0435\u0442\u0430 cellStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Pink.Index; cellStyle.FillPattern = FillPattern.SolidForeground; \/\/ \u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u0442\u0438\u043b\u044f sheet.GetRow(0).GetCell(0).CellStyle = cellStyle;<\/code><\/pre>\n<p><strong>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0432\u044b\u0441\u043e\u0442\u044b \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0448\u0438\u0440\u0438\u043d\u044b \u0441\u0442\u043e\u043b\u0431\u0446\u0430:<\/strong><\/p>\n<pre><code>\/\/ \u0412\u044b\u0441\u043e\u0442\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 row.Height = 25 * 20; \/\/ \u0428\u0438\u0440\u0438\u043d\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 sheet.SetColumnWidth(0, 18 * 256);<\/code><\/pre>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/745696\/\"> https:\/\/habr.com\/ru\/articles\/745696\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-382182","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/382182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=382182"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/382182\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=382182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=382182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=382182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}