{"id":405574,"date":"2024-06-29T18:24:21","date_gmt":"2024-06-29T18:24:21","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=405574"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=405574","title":{"rendered":"<span>Tutorial: \u043a\u0430\u043a \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u0441 Interop Word API \u043d\u0430 Open XML SDK<\/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<p>\u0421 \u0432\u044b\u0445\u043e\u0434\u043e\u043c .NET5 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0435 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u0434 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c \u0438\u0437-\u0437\u0430 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u043e\u0442 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u0438\u043b\u0438 \u043d\u0430\u0439\u0442\u0438 \u0438\u043c \u0437\u0430\u043c\u0435\u043d\u0443, \u0442\u043e \u043e\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 Microsoft.Office.Interop.Word.dll \u043e\u0447\u0435\u043d\u044c \u0441\u043b\u043e\u0436\u043d\u043e \u043e\u0442\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f. Microsoft \u043d\u0435 \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0441 .NET Core\/5+, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b Word \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Open XML SDK.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/82d\/dfc\/838\/82ddfc838b4b0fdee879a22a335c2f5a.png\" width=\"450\" height=\"255\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/82d\/dfc\/838\/82ddfc838b4b0fdee879a22a335c2f5a.png\"\/><figcaption><\/figcaption><\/figure>\n<h3>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h3>\n<p>Office Open XML, \u0442\u0430\u043a\u0436\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 \u043a\u0430\u043a OpenXML \u0438\u043b\u0438 OOXML, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 XML \u0434\u043b\u044f \u043e\u0444\u0438\u0441\u043d\u044b\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u044b, \u0444\u0438\u0433\u0443\u0440\u044b \u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b. \u0412 \u0438\u044e\u043d\u0435 2014 \u0433\u043e\u0434\u0430 Microsoft \u0432\u044b\u043f\u0443\u0441\u0442\u0438\u043b\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 Open XML SDK \u043d\u0430 <a href=\"https:\/\/github.com\/OfficeDev\/Open-XML-SDK\">GitHub<\/a> \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0442\u0430\u043a\u0438\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u043c.<\/p>\n<p>\u0423 \u044d\u0442\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0435\u0441\u0442\u044c \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u044b\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430:<\/p>\n<ul>\n<li>\n<p>\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u0430 \u0441 .NET 5+,<\/p>\n<\/li>\n<li>\n<p>\u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 Microsoft Office,<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0441\u043e\u043a\u0430\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b,<\/p>\n<\/li>\n<li>\n<p>\u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434.<\/p>\n<\/li>\n<\/ul>\n<p>\u0411\u0435\u0437 \u043c\u0438\u043d\u0443\u0441\u043e\u0432 \u0442\u043e\u0436\u0435 \u043d\u0435 \u043e\u0431\u043e\u0448\u043b\u043e\u0441\u044c:<\/p>\n<ul>\n<li>\n<p>\u0441\u043b\u043e\u0436\u043d\u044b\u0439 API,<\/p>\n<\/li>\n<li>\n<p>\u0441\u043a\u0443\u0434\u043d\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u042d\u0442\u0438 \u043c\u0438\u043d\u0443\u0441\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430. \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u044d\u0442\u043e \u0438 \u0441\u0442\u0430\u043b\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u043e\u0439 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430.<\/p>\n<p>\u0410 \u0432\u043e\u0442 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043f\u043b\u044e\u0441\u043e\u043c. \u0415\u0441\u043b\u0438 \u0431\u044b \u043a\u043e\u0434 COM-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0431\u044b\u043b \u043e\u0442\u043a\u0440\u044b\u0442, \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043f\u043e\u043c\u043e\u0433\u043b\u043e \u0431\u044b \u0441 \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043d\u0430 .NET Core\/5+. \u041a\u0440\u043e\u043c\u0435 \u043f\u0440\u0438\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u043e\u0434 \u0434\u0430\u0451\u0442 \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0438 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0438 \u0443\u044f\u0437\u0432\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 \u0445\u043e\u0442\u044f \u0431\u044b \u0441\u043e\u043e\u0431\u0449\u0430\u0442\u044c \u043e \u043d\u0438\u0445. \u041a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u043e\u0447\u0435\u043d\u044c <a href=\"https:\/\/pvs-studio.com\/ru\/blog\/posts\/cpp\/0762\/\">\u0432\u0430\u0436\u043d\u043e<\/a> \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043b\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 <a href=\"https:\/\/pvs-studio.com\/ru\/blog\/posts\/csharp\/0777\/\">\u0430\u0443\u0434\u0438\u0442 \u043a\u043e\u0434\u0430<\/a> Open XML SDK \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u0435 \u0441 \u044d\u0442\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439.<\/p>\n<h3>\u0411\u043e\u043b\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 Office<\/h3>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 Office \u0431\u044b\u043b\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043e \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u0441\u043e\u0444\u0442\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u043c\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c\u0438. \u042d\u0442\u043e \u043f\u043b\u0430\u0433\u0438\u043d\u044b \u0434\u043b\u044f Word, Excel, Outlook. \u041c\u043d\u043e\u0433\u0438\u0435 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u043d\u0430\u0434\u0435\u043b\u0430\u043b\u0438 \u0441\u0435\u0431\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u0445 \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u0432 \u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u043e\u0442\u0447\u0451\u0442\u043e\u0432 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 Word. \u0410 3 \u0438\u044e\u043b\u044f 2021 \u0433\u043e\u0434\u0430 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u0441\u0442\u0440\u0430\u0448\u043d\u043e\u0435 \u2013 \u0432\u0441\u0435 \u0442\u0438\u043a\u0435\u0442\u044b \u043f\u0440\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 .NET 5+ \u0432 VSTO \/ COM, \u0440\u0430\u0437\u0431\u0440\u043e\u0441\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0440\u0430\u0437\u043d\u044b\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c, \u0431\u044b\u043b\u0438 \u0432 \u043e\u0434\u043d\u043e\u0447\u0430\u0441\u044c\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u044b \u0441 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u0435\u043b\u0435\u0439 Microsoft \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u0440\u043e\u0434\u0430:<\/p>\n<blockquote>\n<p>&#8230;The VSTO\/COM Add-Ins platform is very important to Microsoft, and we plan to continue to support it in Office with .NET Framework 4.8 as the last major version&#8230;VSTO\/COM Add-Ins cannot be created with .NET Core and .NET 5+. This is because .NET Core\/.NET 5+ cannot work together with .NET Framework in the same process and may lead to add-in load failures. Microsoft will not be updating VSTO or the COM Add-in platform to use .NET Core or .NET 5+&#8230; <\/p>\n<\/blockquote>\n<p>\u041f\u043e \u0438\u0445 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 .NET 5+ \u043d\u0435 \u043f\u0440\u0435\u0434\u0432\u0438\u0434\u0438\u0442\u0441\u044f. \u0412\u043e\u0442 \u043e\u0434\u043d\u0430 \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u0434\u0438\u0441\u043a\u0443\u0441\u0441\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0435\u0449\u0451 \u0434\u043e\u043b\u0433\u043e \u043d\u0435 \u043f\u0440\u0435\u043a\u0440\u0430\u0449\u0430\u043b\u0430\u0441\u044c \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f: &#171;<a href=\"https:\/\/developercommunity.visualstudio.com\/t\/Please-port-Visual-Studio-Tools-For-Offi\/757925\">Please port Visual Studio Tools For Office (VSTO) to .NET 5\/7, to enable VSTO add-in development in C# in .Net 5\/7<\/a>&#171;.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u0432 \u0441\u043e\u0432\u0441\u0435\u043c \u0432\u0441\u0451 \u043f\u043b\u043e\u0445\u043e \u2013 \u0438\u043c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0430 Office JavaScript API (\u0441\u043e\u0432\u0441\u0435\u043c \u0434\u0440\u0443\u0433\u043e\u0439 \u044f\u0437\u044b\u043a, API \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u0438 \u043c\u0430\u043b\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0431\u044b\u043b\u043e), \u0442\u043e \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u0437 C# \u043a\u043e\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 Open XML SDK (<a href=\"https:\/\/www.nuget.org\/packages\/Open-XML-SDK\">nuget<\/a>).<\/p>\n<h3>\u041e\u0441\u043d\u043e\u0432\u044b<\/h3>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u0440\u0430\u0437\u0431\u043e\u0440\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u043d\u044f\u0442\u044c, \u0441 \u0447\u0435\u043c \u0432\u043e\u043e\u0431\u0449\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u044d\u0442\u0438 \u0434\u0432\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0438 \u0432 \u0447\u0451\u043c \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0438\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432.<\/p>\n<p>Word \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u2014 \u044d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u0437\u0430\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0445 xml-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u0412\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043f\u043e\u0434 \u0442\u0435\u0433\u0430\u043c\u0438.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444 \u0432\u043d\u0443\u0442\u0440\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"xml\">&lt;w:p w:rsidR=\"007D2247\" w:rsidRDefault=\"009A4B44\"          xmlns:w=\"http:\/\/schemas.openxmlformats.org\/wordprocessingml\/2006\/main\">   &lt;w:r>     &lt;w:t>\u0442\u0435\u0441\u0442&lt;\/w:t>   &lt;\/w:r>   &lt;w:bookmarkStart w:name=\"_GoBack\" w:id=\"0\" \/>   &lt;w:bookmarkEnd w:id=\"0\" \/> &lt;\/w:p><\/code><\/pre>\n<p>\u0421\u0431\u043e\u0440\u043a\u0430 Interop.Word \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0430\u0431\u0441\u0442\u0440\u0430\u0433\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043e\u0442 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438 \u0447\u0430\u0441\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0443\u0447\u0430\u0441\u0442\u043a\u043e\u043c \u2013 Range \u2013 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430. \u0410 Open XML SDK \u0438\u0434\u0451\u0442 \u043f\u043e \u043f\u0443\u0442\u0438 \u043e\u0442\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u043e\u0434\u0435. \u041f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u044b <em>&lt;w:p><\/em>, \u0443\u0447\u0430\u0441\u0442\u043a\u0438 \u0442\u0435\u043a\u0441\u0442\u0430 <em>&lt;w:t><\/em> \u0438 \u0432\u0441\u0451 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u043e\u0434\u0435. \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u0442\u0435 \u0442\u0435\u043b\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430, \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444 \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 &#171;\u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u0439&#187;, \u0442\u043e \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043a\u0443\u0434\u0430.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/98c\/320\/1bd\/98c3201bdf57ce8c0a48c04767888a3c.png\" width=\"300\" height=\"293\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/98c\/320\/1bd\/98c3201bdf57ce8c0a48c04767888a3c.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430 \u0441\u043a\u0440\u0438\u043d\u0448\u043e\u0442\u0435 \u043a\u0430\u043a \u0440\u0430\u0437 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0430 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044f\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0434\u043b\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 Word \u2013 document.xml. \u042d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u0430\u043c\u043e \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430.<\/p>\n<p>\u0421\u043a\u0440\u0438\u043d\u0448\u043e\u0442 \u0441\u0434\u0435\u043b\u0430\u043d \u0432 \u043e\u0447\u0435\u043d\u044c \u043d\u0443\u0436\u043d\u043e\u0439 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Open XML \u0443\u0442\u0438\u043b\u0438\u0442\u0435 Open XML SDK 2.5 Productivity Tool. \u041a \u043c\u043e\u043c\u0435\u043d\u0442\u0443 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438 \u044d\u0442\u0430 \u0443\u0442\u0438\u043b\u0438\u0442\u0430 \u0431\u044b\u043b\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0430 \u0441 \u0441\u0430\u0439\u0442\u0430 Microsoft, \u0430 \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 <a href=\"https:\/\/github.com\/OfficeDev\/Open-XML-SDK\">Open-XML-SDK<\/a> \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043d\u0435\u043a\u0438\u0439 <a href=\"https:\/\/github.com\/rmboggs\/DocxToSource\">DocxToSource<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u0442\u0430\u0442\u044c \u0437\u0430\u043c\u0435\u043d\u043e\u0439 \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0435\u0433\u043e Productivity Tool. \u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u0430 \u0437\u0430\u043c\u0435\u043d\u0430 \u0432\u0441\u0451 \u0435\u0449\u0451 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u043e\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u043a\u0430 \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u0439\u0442\u0438 \u0441\u0442\u0430\u0440\u044b\u0439 \u0434\u043e\u0431\u0440\u044b\u0439 Productivity Tool. \u0421\u0442\u0430\u0440\u0430\u044f \u0443\u0442\u0438\u043b\u0438\u0442\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430, \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u0430\u0432\u0442\u043e\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c. <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0da\/712\/5f3\/0da7125f38a4dcb4cef89aa5535e3e61.png\" width=\"580\" height=\"261\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0da\/712\/5f3\/0da7125f38a4dcb4cef89aa5535e3e61.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043e\u043d\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0434\u0432\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 (\u0438 \u043a\u043e\u0434 \u0434\u043b\u044f \u0438\u0445 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f, \u0438 \u0438\u0445 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435). <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/1ae\/ef1\/51e\/1aeef151e7f37c50578551bc81c6c732.png\" width=\"580\" height=\"284\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1ae\/ef1\/51e\/1aeef151e7f37c50578551bc81c6c732.png\"\/><figcaption><\/figcaption><\/figure>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440\u044b<\/h3>\n<p>\u0414\u043b\u044f Interop.Word \u0432\u043e \u0432\u0441\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u0438\u043c\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0447\u0442\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"cs\">using MicrosoftWord = Microsoft.Office.Interop.Word;<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u043c \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c Open XML SDK \u043f\u0440\u043e\u0441\u0442\u043e Open XML.<\/p>\n<h4>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430<\/h4>\n<p><strong><em>Interop.Word:<\/em><\/strong><\/p>\n<pre><code class=\"cs\">MicrosoftWord.Application wordApp = new MicrosoftWord.Application(); MicrosoftWord.Document wordDoc = wordApp.Documents.Add(); MicrosoftWord.Range docRange = wordDoc.Range(); .... \/\/ \u0442\u0443\u0442 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u043c wordDoc.SaveAs2(pathToDocFile); wordApp.Quit();<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0432\u0441\u0451 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e, \u043d\u043e \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438. \u041f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 Interop \u043c\u044b \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u043c \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u0430 \u0441 COM-\u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0442\u044c \u0432\u0441\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u043f\u043e\u0441\u043b\u0435 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u042d\u0442\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043d\u0435 \u0440\u0430\u0437 \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u043b\u0430\u0441\u044c \u043d\u0430 Stack Overflow (<a href=\"https:\/\/stackoverflow.com\/questions\/158706\/how-do-i-properly-clean-up-excel-interop-objects?page=1&amp;tab=active\">1<\/a>, <a href=\"https:\/\/stackoverflow.com\/questions\/25134024\/clean-up-excel-interop-objects-with-idisposable\/25135685\">2<\/a>), \u0438 \u0435\u0439 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439.<\/p>\n<p>\u0415\u0441\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0441 \u0443\u0447\u0430\u0441\u0442\u0438\u0435\u043c <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/system.runtime.interopservices.marshal?view=net-5.0\">Marshal Class<\/a>, \u044f\u0432\u043b\u044f\u044e\u0449\u0438\u043c\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e InteropServices.<\/p>\n<pre><code class=\"cs\">finally {   if (Marshal.IsComObject(wordDoc))     try     {       Marshal.FinalReleaseComObject(wordDoc);     }     catch { throw; }     if (Marshal.IsComObject(wordApp))     try     {       Marshal.FinalReleaseComObject(wordApp);     }     catch { throw; } }<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b.<\/p>\n<p>\u0415\u0441\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043d\u0430\u0434\u0451\u0436\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435\u043c \u043a <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/system.gc?view=net-5.0\">GC<\/a>:<\/p>\n<pre><code class=\"cs\">GC.Collect(); GC.WaitForPendingFinalizers();<\/code><\/pre>\n<p>\u042d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043d\u0430\u0434\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0432\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 COM-\u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b, \u0442\u043e \u043f\u0440\u0438 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u043c \u0434\u0435\u0431\u0430\u0433\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u0435\u0431\u0435 \u0442\u0430\u043a\u0443\u044e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/260\/c82\/6b4\/260c826b4fd899a08294490ce0055aad.png\" width=\"491\" height=\"347\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/260\/c82\/6b4\/260c826b4fd899a08294490ce0055aad.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u043e \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432 \u043a\u043e\u0434\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b, \u043f\u0440\u0438 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0438\u043b\u0438 \u0435\u0451 \u043f\u0430\u0434\u0435\u043d\u0438\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u043c. \u0422\u0430\u043a\u043e\u0433\u043e \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0430 \u043d\u0435\u0442 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0447\u0435\u0440\u0435\u0437 Open XML.<\/p>\n<p><strong><em>Open XML:<\/em><\/strong><\/p>\n<pre><code class=\"cs\">using (WordprocessingDocument doc =           WordprocessingDocument.Create(pathToDocFile,                                        WordprocessingDocumentType.Document,                                        true)) {   MainDocumentPart mainPart = doc.AddMainDocumentPart();   mainPart.Document = new Document();   Body body = mainPart.Document.AppendChild(new Body());   SectionProperties props = new SectionProperties();   body.AppendChild(props); }<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 <em>SectionProperties<\/em>, \u043e\u043d\u0438 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u043d\u0430\u043c \u043f\u043e\u0437\u0436\u0435.<\/p>\n<h4>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u0430<\/h4>\n<p><strong><em>Interop.Word<\/em><\/strong><\/p>\n<pre><code class=\"cs\">public static void InsertWordText(MicrosoftWord.Document doc,                                       string text) {   MicrosoftWord.Paragraph paragraph = doc.Paragraphs.Add(Missing.Value);   paragraph.Range.Text = text;   paragraph.Range.InsertParagraphAfter(); }<\/code><\/pre>\n<p>\u0422\u0435\u043a\u0441\u0442 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0436\u0438\u0440\u043d\u044b\u043c \u0438\u043b\u0438 \u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u043c \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <em>Font<\/em>:<\/p>\n<pre><code class=\"cs\">paragraph.Range.Font.Bold = 1; paragraph.Range.Font.Italic = 1;<\/code><\/pre>\n<p>\u0418\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u0448\u0440\u0438\u0444\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0447\u0435\u0440\u0435\u0437:<\/p>\n<pre><code class=\"cs\">paragraph.Range.Font.Size = 14;<\/code><\/pre>\n<p>\u0412\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 <em>ParagraphFormat.Alignment<\/em>:<\/p>\n<pre><code class=\"cs\">paragraph.Range.ParagraphFormat.Alignment = MicrosoftWord.WdParagraphAlignment                                                         .wdAlignParagraphCenter;<\/code><\/pre>\n<p><strong><em>Open XML:<\/em><\/strong><\/p>\n<pre><code class=\"cs\">public static void AddText(WordprocessingDocument doc, string text) {   MainDocumentPart mainPart = doc.MainDocumentPart;   Body body = mainPart.Document.Body;   Paragraph paragraph = body.AppendChild(new Paragraph());    Run run = paragraph.AppendChild(new Run());   run.AppendChild(new Text(text));   run.PrependChild(new RunProperties()); }<\/code><\/pre>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 Open XML \u0436\u0438\u0440\u043d\u044b\u043c \u0438\u043b\u0438 \u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u043c \u0442\u0435\u043a\u0441\u0442 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437:<\/p>\n<pre><code class=\"cs\">run.RunProperties.AddChild(new Bold()); run.RunProperties.AddChild(new Italic());<\/code><\/pre>\n<p>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0448\u0440\u0438\u0444\u0442\u0430 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043d\u0435\u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e, \u043d\u043e \u0441\u043e\u0433\u043b\u0430\u0441\u0443\u0435\u0442\u0441\u044f \u0441 \u043e\u0431\u0449\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Open XML:<\/p>\n<pre><code class=\"cs\">run.RunProperties.AddChild(new FontSize(){ Val = \"14\"});<\/code><\/pre>\n<p>\u0412\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430:<\/p>\n<pre><code class=\"cs\">paragraph.ParagraphProperties.AddChild(new Justification()                                        {                                          Val = JustificationValues.Center                                        });<\/code><\/pre>\n<p>\u0412\u0430\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u0443 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430:<\/p>\n<pre><code class=\"cs\">paragraph.AppendChild(new ParagraphProperties());<\/code><\/pre>\n<h4>\u0412\u0441\u0442\u0430\u0432\u043a\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430<\/h4>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 Interop.Word \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a \u0432\u0441\u0442\u0430\u0432\u043a\u0435 \u0442\u0435\u043a\u0441\u0442\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a:<\/p>\n<p><strong><em>Interop.Word:<\/em><\/strong><\/p>\n<pre><code class=\"cs\">public static void InsertWordHeading1(MicrosoftWord.Document doc,                                       string headingText) {   MicrosoftWord.Paragraph paragraph = doc.Paragraphs.Add(Missing.Value);   paragraph.Range.Text = headingText;   paragraph.Range.set_Style(\"Heading 1\");   paragraph.Range.InsertParagraphAfter(); }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u0434\u0430\u0451\u043c Range \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 \u0438 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u0435\u043c\u0443 \u0441\u0442\u0438\u043b\u044c <em>Heading 1<\/em>.<\/p>\n<p><strong><em>Open XML:<\/em><\/strong><\/p>\n<pre><code class=\"cs\">public static void InsertWordHeading1(WordprocessingDocument doc,                                       string headingText) {   MainDocumentPart mainPart = doc.MainDocumentPart;   Paragraph para = mainPart.Document.Body.AppendChild(new Paragraph());   Run run = para.AppendChild(new Run());   run.AppendChild(new Text(headingText));   para.ParagraphProperties = new ParagraphProperties(                                new ParagraphStyleId() { Val = \"Heading1\" }); }<\/code><\/pre>\n<p>\u0422\u0443\u0442, \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0432\u0441\u0451 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0435. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444 \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 Open XML \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0443\u0435\u043c \u043d\u0443\u0436\u043d\u0443\u044e \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 Open XML \u043a\u043e\u0432\u0430\u0440\u043d\u044b\u043c \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0438\u043b\u044f. Interop.Word \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u043c, \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u0431\u044b \u0432\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 Word \u0438 \u043d\u0430\u0436\u0430\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c. \u0410 \u0432\u043e\u0442 Open XML \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0431\u044b\u043b\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043e. \u0418 \u0435\u0441\u043b\u0438 \u0432\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0435 \u0442\u0435\u043a\u0441\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0443, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0447\u0435\u0440\u0435\u0437 Open XML, \u0430 \u043d\u0435 \u0447\u0435\u0440\u0435\u0437 Interop.Word, \u0442\u043e \u0432 \u043d\u0451\u043c \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0442\u0438\u043b\u0438. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0441\u0442\u0438\u043b\u044f <em>Heading1<\/em> \u0432 \u0442\u0430\u043a\u043e\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442. \u0415\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c. <\/p>\n<p>\u0423\u0434\u043e\u0431\u043d\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0439 \u0441\u0442\u0438\u043b\u044c \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430. \u0415\u0441\u0442\u044c \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430: \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u0441\u0442\u0438\u043b\u0438 \u0438\u0437 \u0433\u043e\u0442\u043e\u0432\u043e\u0433\u043e Word-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0438\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u0438 \u0441\u0442\u0438\u043b\u0438 \u0432\u0440\u0443\u0447\u043d\u0443\u044e. <\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441\u0442\u0438\u043b\u044c, \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0438\u0441\u043a\u043e\u043c\u044b\u0439 \u0441\u0442\u0438\u043b\u044c. \u0421\u0430\u043c \u043f\u0435\u0440\u0435\u043d\u043e\u0441 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u0431\u043b\u0430\u0433\u043e, \u0432 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0435\u0441\u0442\u044c <a href=\"https:\/\/docs.microsoft.com\/en-us\/office\/open-xml\/how-to-replace-the-styles-parts-in-a-word-processing-document\">\u043c\u0430\u043d\u0443\u0430\u043b \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443<\/a>.<\/p>\n<p>\u0414\u043b\u044f \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u043d\u0430\u043c \u043f\u043e\u043c\u043e\u0436\u0435\u0442 Productivity Tool \u0434\u043b\u044f Open XML, \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u0432\u0448\u0438\u0439\u0441\u044f \u0440\u0430\u043d\u0435\u0435. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u043e\u0434, \u043d\u0443\u0436\u043d\u044b\u0439 \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0436\u0435\u043b\u0430\u0435\u043c\u043e\u0433\u043e \u0441\u0442\u0438\u043b\u044f, \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0447\u0438\u0441\u0442\u044b\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 Word, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432 \u043d\u0451\u043c \u043d\u0443\u0436\u043d\u044b\u0439 \u0441\u0442\u0438\u043b\u044c \u0438 &#171;\u0441\u043a\u0430\u0440\u043c\u043b\u0438\u0432\u0430\u0435\u043c&#187; \u044d\u0442\u043e\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0443\u0442\u0438\u043b\u0438\u0442\u0435. \u0414\u0430\u043b\u0435\u0435 \u0447\u0435\u0440\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043d\u043e\u043f\u043a\u0438 Reflect Code \u043d\u0430 \/word\/styles.xml \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <em>GeneratePartContent<\/em>. \u0412 \u043d\u0451\u043c \u043c\u044b \u0438\u0449\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u0441\u0442\u0438\u043b\u044f \u0438 \u0432\u0441\u0451, \u0447\u0442\u043e \u0441 \u043d\u0438\u043c \u0441\u0432\u044f\u0437\u0430\u043d\u043e, \u0432\u043a\u043b\u044e\u0447\u0430\u044f <em>StyleParagraphProperties<\/em>, <em>StyleRunProperties<\/em> \u0438 \u0442.\u0434. <\/p>\n<p>\u0414\u043b\u044f \u0441\u0442\u0438\u043b\u044f <em>Heading 1<\/em> \u043d\u0443\u0436\u043d\u044b\u0439 \u043d\u0430\u043c \u0430\u0432\u0442\u043e\u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cs\">Style style2 = new Style() { Type = StyleValues.Paragraph,                              StyleId = \"Heading1\" }; StyleName styleName2 = new StyleName(){ Val = \"heading 1\" }; .... style2.Append(styleRunProperties1);<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0451\u043d\u043d\u044b\u0439 \u0441\u0442\u0438\u043b\u044c \u043a \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u043c\u0443 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0443, \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u0441\u0442\u0438\u043b\u0435\u0439 Styles \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0442\u0438\u043b\u044c \u043a \u043d\u0430\u0431\u043e\u0440\u0443. \u0414\u0430\u043b\u0435\u0435 \u043a \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0443 \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <em>StyleDefinitionsPart<\/em> \u0438 \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u0433\u0440\u0443\u043f\u043f\u0443 \u0441\u0442\u0438\u043b\u0435\u0439. \u0412\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cs\">var styles = new Styles(); styles.Append(style2); wordDocument.MainDocumentPart.AddNewPart&lt;StyleDefinitionsPart>(); wordDocument.MainDocumentPart.StyleDefinitionsPart.Styles = styles;<\/code><\/pre>\n<p>\u0423 \u0441\u0435\u0431\u044f \u043c\u044b \u0440\u0435\u0448\u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u043f\u0440\u0438 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 \u043a\u0430\u043a\u043e\u043c-\u043b\u0438\u0431\u043e \u0441\u0442\u0438\u043b\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043b\u0438\u0448\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0435 \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043d\u0438\u043c \u0432 \u043a\u043e\u0434\u0435 \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0440\u044b\u0442\u044c\u0441\u044f \u0432 ProductivityTool \u0438 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0431\u0435 \u043f\u043e\u043b\u043e\u0442\u043d\u0430 \u043a\u043e\u0434\u0430 \u0441 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u0441\u0442\u0438\u043b\u044f.<\/p>\n<h4>\u0421\u043c\u0435\u043d\u0430 \u043e\u0440\u0438\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b<\/h4>\n<p>\u0414\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043e\u0442\u0447\u0451\u0442\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u0431\u044b\u043b\u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043b\u0430\u043d\u0434\u0448\u0430\u0444\u0442\u043d\u0430\u044f \u043e\u0440\u0438\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/p>\n<p><strong><em>Interop.Word:<\/em><\/strong><\/p>\n<pre><code class=\"cs\">MicrosoftWord.Document wordDoc = wordApp.Documents.Add(); MicrosoftWord.Range docRange = wordDoc.Range(); docRange.PageSetup.Orientation = MicrosoftWord.WdOrientation                                               .wdOrientLandscape;<\/code><\/pre>\n<p>\u0423 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0439 Range (\u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0438\u043b\u0438 \u0432\u0441\u0435\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430) \u0438 \u0437\u0430\u0434\u0430\u0451\u043c \u043b\u0430\u043d\u0434\u0448\u0430\u0444\u0442\u043d\u0443\u044e \u043e\u0440\u0438\u0435\u043d\u0442\u0430\u0446\u0438\u044e.<\/p>\n<p><strong><em>Open XML:<\/em><\/strong><\/p>\n<pre><code class=\"cs\">var sectionProperties = mainPart.Document                                 .Body                                 .GetFirstChild&lt;SectionProperties>(); sectionProperties.AddChild(new PageSize() {   Width = (UInt32Value)15840U,   Height = (UInt32Value)12240U,   Orient = PageOrientationValues.Landscape });<\/code><\/pre>\n<p>C Open XML \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0441\u0451 \u043d\u0435 \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e, \u043a\u0430\u043a \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b. \u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0435 \u0432 <em>PageSize<\/em> \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0435 <em>Orient<\/em>, \u0442\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f. <em>Width<\/em> \u0438 <em>Height<\/em> \u0442\u043e\u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u043c\u0435\u043d\u044f\u0442\u044c.<\/p>\n<p>\u0412 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a \u044d\u0442\u043e\u043c\u0443, \u043b\u0430\u043d\u0434\u0448\u0430\u0444\u0442\u043d\u0430\u044f \u043e\u0440\u0438\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043e\u0431\u044b\u0447\u043d\u043e \u0438\u043c\u0435\u0435\u0442 \u0434\u0440\u0443\u0433\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u043f\u043e\u043b\u0435\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043a \u043d\u0438\u043c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0438\u0445 \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cs\">sectionProperties.AddChild(new PageMargin() {   Top = 720,   Right = Convert.ToUInt32(1440.0),   Bottom = 360,   Left = Convert.ToUInt32(1440.0),   Header = (UInt32Value)450U,   Footer = (UInt32Value)720U,   Gutter = (UInt32Value)0U });<\/code><\/pre>\n<h4>\u0413\u0438\u043f\u0435\u0440\u0441\u0441\u044b\u043b\u043a\u0438<\/h4>\n<p><strong><em>Interop.Word:<\/em><\/strong><\/p>\n<pre><code class=\"cs\">public static void AddHyperlinkedText(MicrosoftWord.Document doc,                                       string text,                                       string url) {   MicrosoftWord.Range wrdRng = doc.Bookmarks                                   .get_Item(\"\\\\endofdoc\")                                   .Range;   doc.Hyperlinks.Add(wrdRng, url, TextToDisplay: text); }<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e: \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0439 Range \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0433\u0438\u043f\u0435\u0440\u0441\u0441\u044b\u043b\u043a\u0443. \u0423 \u043c\u0435\u0442\u043e\u0434\u0430 <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/microsoft.office.interop.word.hyperlinks.add?view=word-pia\">Add<\/a> \u043c\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443.<\/p>\n<p><strong><em>Open XML:<\/em><\/strong><\/p>\n<pre><code class=\"cs\">public static void AddHyperlinkedText(WordprocessingDocument doc,                                       string text,                                       string url) {   MainDocumentPart mainPart = doc.MainDocumentPart;   Body body = mainPart.Document.Body;   Paragraph paragraph = body.AppendChild(new Paragraph());    var rel = mainPart.AddHyperlinkRelationship(new Uri(url), true);    Hyperlink hyperlink = new Hyperlink(new Run(                                     new RunProperties(                                       new RunStyle                                        {                                         Val = \"Hyperlink\",                                       },                                       new Underline                                       {                                         Val = UnderlineValues.Single                                       },                                       new Color                                       {                                         ThemeColor = ThemeColorValues.Hyperlink                                       }),                                       new Text                                       {                                         Text = text                                       }))                      {                       Id = rel.Id                      };    paragraph.AppendChild(hyperlink); }<\/code><\/pre>\n<p>\u0418\u0437 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043e\u0442\u043b\u0438\u0447\u0438\u0439 \u0442\u0443\u0442 \u0442\u043e, \u0447\u0442\u043e <em>url<\/em> \u043d\u0443\u0436\u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u0432 <em>Uri<\/em> \u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0432\u044f\u0437\u044c <em>url<\/em> \u0441 \u0433\u0438\u043f\u0435\u0440\u0441\u0441\u044b\u043b\u043a\u043e\u0439 \u0447\u0435\u0440\u0435\u0437 <em>AddHyperlinkRelationship<\/em>. \u041f\u043e\u0442\u043e\u043c \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0441\u0430\u043c\u043e\u0439 \u0433\u0438\u043f\u0435\u0440\u0441\u0441\u044b\u043b\u043a\u0438, \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u043f\u043e\u043b\u044e <em>Id<\/em> \u043d\u043e\u0432\u043e\u0439 \u0433\u0438\u043f\u0435\u0440\u0441\u0441\u044b\u043b\u043a\u0438 Id \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0439 \u0440\u0430\u043d\u0435\u0435 \u0441\u0432\u044f\u0437\u0438.<\/p>\n<h4>\u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0438<\/h4>\n<p><strong><em>Interop.Word:<\/em><\/strong><\/p>\n<pre><code class=\"cs\">public static void InsertWordPicture(MicrosoftWord.Document doc,                                      string picturePath) {   MicrosoftWord.Range wrdRng = doc.Bookmarks.get_Item(\"\\\\endofdoc\")                                             .Range;   wrdRng.InlineShapes.AddPicture(picturePath); }<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0432\u0441\u0451 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e, \u0430 \u0441 Open XML \u0432\u0441\u0451 \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043a\u0440\u0430\u0439\u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e. <\/p>\n<p><strong><em>Open XML:<\/em><\/strong><\/p>\n<p>\u0414\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0431\u043b\u044e\u0441\u0442\u0438 \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438. \u0425\u043e\u0440\u043e\u0448\u043e, \u0447\u0442\u043e \u0435\u0441\u0442\u044c <a href=\"https:\/\/docs.microsoft.com\/en-us\/office\/open-xml\/how-to-insert-a-picture-into-a-word-processing-document\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043d\u0430 \u044d\u0442\u043e\u0442 \u0441\u0447\u0451\u0442<\/a>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u043a\u043e\u0434, \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u044b\u0439 \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435. \u0420\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0447\u0435\u043c\u0443-\u0442\u043e \u043d\u0435 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438. \u041c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0432 \u0442\u043e\u043c \u043a\u043e\u0434\u0435 \u043d\u0438\u0433\u0434\u0435 \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438. \u0424\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0435\u0451 \u0440\u0430\u0437\u043c\u0435\u0440 \u0442\u0443\u0442:<\/p>\n<pre><code class=\"cs\">new DW.Extent() { Cx = 990000L, Cy = 792000L }<\/code><\/pre>\n<p>\u0438 \u0442\u0443\u0442<\/p>\n<pre><code class=\"cs\">new A.Extents() { Cx = 990000L, Cy = 792000L }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434, \u0442\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438, \u0431\u0443\u0434\u0435\u0442 \u0432\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u043c\u0430\u043b\u044e\u0441\u0435\u043d\u044c\u043a\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435. \u0415\u0433\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f, \u043d\u043e \u043f\u0440\u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u043e\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u0434\u043e \u0442\u0430\u043a\u0438\u0445 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/650\/775\/6e0\/6507756e082243823df6c449ff41146b.png\" width=\"176\" height=\"110\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/650\/775\/6e0\/6507756e082243823df6c449ff41146b.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u0437\u0434\u0435\u0441\u044c \u0437\u0430\u0432\u044f\u0437\u0430\u043d \u043d\u0430 \u0442\u0430\u043a\u0443\u044e \u0432\u0435\u0449\u044c, \u043a\u0430\u043a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Office_Open_XML_file_formats\">EMU<\/a> (English Metric Units).<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u0443 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u0432 \u043f\u0438\u043a\u0441\u0435\u043b\u044f\u0445, \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435:<\/p>\n<pre><code class=\"cs\">double englishMetricUnitsPerInch = 914400; double pixelsPerInch = 96; double englishMetricUnitsPerPixel = englishMetricUnitsPerInch \/ pixelsPerInch;  double emuWidth = width * englishMetricUnitsPerPixel; double emuHeight = height * englishMetricUnitsPerPixel;<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e EMU \u043d\u0430 \u043f\u0438\u043a\u0441\u0435\u043b\u044c, \u043f\u0440\u0438\u043d\u044f\u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 PPI \u0437\u0430 96, \u0438 \u0443\u043c\u043d\u043e\u0436\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u043d\u0443\u0436\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439 \u0434\u043b\u044f \u0448\u0438\u0440\u0438\u043d\u044b \u0438 \u0432\u044b\u0441\u043e\u0442\u044b. \u0412 \u0438\u0442\u043e\u0433\u0435 \u0443 \u043d\u0430c \u0435\u0441\u0442\u044c \u043d\u0443\u0436\u043d\u0430\u044f \u043d\u0430\u043c \u0448\u0438\u0440\u0438\u043d\u0430 \u0438 \u0432\u044b\u0441\u043e\u0442\u0430 \u0432 EMU. \u0418\u0445 \u043c\u044b \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u043a\u0430\u043a <em>Cx<\/em> \u0438 <em>Cy<\/em> \u0434\u043b\u044f Extent \u0438 Extents:<\/p>\n<pre><code class=\"cs\">Cx = (Int64Value)emuWidth, Cy = (Int64Value)emuHeight<\/code><\/pre>\n<h4>\u0422\u0430\u0431\u043b\u0438\u0446\u044b<\/h4>\n<p><strong><em>Interop.Word:<\/em><\/strong><\/p>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0447\u0435\u0440\u0435\u0437 Interop.Word \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0439\u043d\u0430. \u0420\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0438\u0437 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0441\u0442\u0440\u043e\u043a.<\/p>\n<pre><code class=\"cs\">public static void InsertWordTable(MicrosoftWord.Document doc,                                    string[,] table) {   MicrosoftWord.Table oTable;   MicrosoftWord.Range wrdRng = doc.Bookmarks                                   .get_Item(\"\\\\endofdoc\")                                   .Range;    int rowCount = table.GetLength(0);   int columnCount = table.GetLength(1);    oTable = doc.Tables.Add(wrdRng,                     rowCount,                     columnCount,                     DefaultTableBehavior: MicrosoftWord.WdDefaultTableBehavior                                                        .wdWord9TableBehavior,                     AutoFitBehavior: MicrosoftWord.WdAutoFitBehavior                                                   .wdAutoFitWindow);    for (int i = 0; i &lt; rowCount; i++)     for (int j = 0; j &lt; columnCount; j++)       oTable.Cell(i + 1, j + 1).Range.Text = table[i,j]; }<\/code><\/pre>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u0435\u0442\u043e\u0434\u0430 <em>Add<\/em> \u2014 <em>DefaultTableBehavior<\/em> \u0438 <em>AutoFitBehavior<\/em> \u2014 \u043a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u0438\u0445 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0442 \u0437\u0430 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043f\u043e\u0434 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u044f\u0447\u0435\u0435\u043a. \u0418\u043c \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/microsoft.office.interop.word.wddefaulttablebehavior?view=word-pia\">WdDefaultTableBehavior<\/a> \u0438 <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/microsoft.office.interop.word.wdautofitbehavior?view=word-pia\">WdAutoFitBehavior<\/a> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e. \u0421\u0430\u043c \u043c\u0435\u0442\u043e\u0434 Add \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441 \u043d\u0443\u0436\u043d\u044b\u043c\u0438 \u043d\u0430\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438.<\/p>\n<p>\u0421\u0442\u0438\u043b\u044c \u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cs\">oTable.set_Style(\"Grid Table 4 - Accent 1\");<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0433\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0438\u043a\u0430, \u0435\u0441\u043b\u0438 \u043e\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u043c, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c <em>true<\/em> \u043f\u043e\u043b\u044e <em>oTable.ApplyStyleFirstColumn<\/em>.<\/p>\n<p>\u0420\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u0430\u043c\u0438 \u0442\u0435\u043a\u0441\u0442\u0430 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 <em>oTable.Range.ParagraphFormat.SpaceAfter<\/em>. \u0414\u043b\u044f \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u043e\u0433\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c<\/p>\n<pre><code class=\"cs\">oTable.Range.ParagraphFormat.SpaceAfter = 0;<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0442\u0438\u043f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u0430 \u043a \u0441\u0442\u0440\u043e\u043a\u0430\u043c \u0438\u043b\u0438 \u043a\u043e\u043b\u043e\u043d\u043a\u0430\u043c:<\/p>\n<pre><code class=\"cs\">oTable.Rows[1].Range.Font.Bold = 1; oTable.Column[1].Range.Font.Italic = 1;<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u044d\u0442\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9df\/1b5\/4c6\/9df1b54c626dc0dac343700ed990aceb.png\" width=\"580\" height=\"44\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9df\/1b5\/4c6\/9df1b54c626dc0dac343700ed990aceb.png\"\/><figcaption><\/figcaption><\/figure>\n<p><strong><em>Open XML:<\/em><\/strong><\/p>\n<pre><code class=\"cs\">public static void InsertWordTable(WordprocessingDocument doc,                                    string[,] table) {   DocumentFormat.OpenXml.Wordprocessing.Table dTable =     new DocumentFormat.OpenXml.Wordprocessing.Table();    TableProperties props = new TableProperties();    dTable.AppendChild&lt;TableProperties>(props);    for (int i = 0; i &lt; table.GetLength(0); i++)   {     var tr = new TableRow();      for (int j = 0; j &lt; table.GetLength(1); j++)     {       var tc = new TableCell();       tc.Append(new Paragraph(new Run(new Text(table[i, j]))));        tc.Append(new TableCellProperties());        tr.Append(tc);     }     dTable.Append(tr);   }   doc.MainDocumentPart.Document.Body.Append(dTable); }<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441 \u043d\u0443\u043b\u044f \u0441 Open XML \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u043c\u043d\u0438\u0442\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u044f\u0447\u0435\u0435\u043a \u0438\u043b\u0438 \u0441\u0442\u0440\u043e\u043a \u043a \u043c\u043e\u043c\u0435\u043d\u0442\u0443 \u0432\u0432\u043e\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442. \u0418\u0445 \u043d\u0443\u0436\u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0442\u044c, \u0441\u043e\u0431\u043b\u044e\u0434\u0430\u044f \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044e\u044e \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438 \u043f\u0440\u043e\u0445\u043e\u0434\u0435 \u043f\u043e \u043c\u0430\u0442\u0440\u0438\u0446\u0435 \u043c\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u0451\u043c <em>TableRow<\/em>, \u0430 \u043f\u043e\u0442\u043e\u043c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 \u0441\u043e\u0437\u0434\u0430\u0451\u043c <em>TableCell<\/em>, \u043a\u0443\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u044b\u0435 <em>Paragraph<\/em>, <em>Run<\/em> \u0438 <em>Text<\/em> \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0438\u0437 \u043c\u0430\u0442\u0440\u0438\u0446\u044b. <em>TableCellProperties<\/em> \u043b\u0443\u0447\u0448\u0435 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0440\u0430\u0437\u0443, \u0447\u0435\u043c \u043f\u043e\u0442\u043e\u043c \u043f\u0440\u0438 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 \u043d\u0430\u0442\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u043d\u0430 <em>System.NullReferenceException<\/em> \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u044f\u0447\u0435\u0439\u043a\u0435.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043d\u0435 \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u0432 <em>TableProperties<\/em> \u043d\u0438 \u0441\u0442\u0438\u043b\u044f, \u043d\u0438 Borders, \u0442\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f44\/933\/ab3\/f44933ab3ac7faed826a9b2649d196b7.png\" width=\"169\" height=\"76\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f44\/933\/ab3\/f44933ab3ac7faed826a9b2649d196b7.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0413\u0440\u0430\u043d\u0438\u0446\u044b \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 <em>TableBorders<\/em>.<\/p>\n<pre><code class=\"cs\">var borderValues = new EnumValue&lt;BorderValues>(BorderValues.Single); var tableBorders = new TableBorders(                       new TopBorder { Val = borderValues, Size = 4 },                      new BottomBorder {  Val = borderValues,  Size = 4 },                      new LeftBorder { Val = borderValues, Size = 4 },                      new RightBorder { Val = borderValues, Size = 4 },                      new InsideHorizontalBorder { Val= borderValues, Size = 4 },                      new InsideVerticalBorder { Val= borderValues, Size = 4 }));<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/documentformat.openxml.vml.wordprocessing.bordervalues?view=openxml-2.8.1\">BorderValues<\/a> \u0437\u0434\u0435\u0441\u044c \u0437\u0430\u0434\u0430\u0451\u0442 \u0441\u0442\u0438\u043b\u044c \u0433\u0440\u0430\u043d\u0438\u0446. <\/p>\n<p><em>TableBorders<\/em> \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a <em>TableProperties<\/em> \u0447\u0435\u0440\u0435\u0437<\/p>\n<pre><code class=\"cs\">props.Append(tableBorders);<\/code><\/pre>\n<p>\u0413\u0440\u0430\u043d\u0438\u0446\u044b \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0435\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0441\u0442\u0438\u043b\u044c. \u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c, \u0447\u0442\u043e \u0441\u0442\u0438\u043b\u044c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0443.<\/p>\n<p>\u0417\u0430\u0434\u0430\u0451\u0442\u0441\u044f \u0441\u0442\u0438\u043b\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<pre><code class=\"cs\">TableStyle tableStyle = new TableStyle()                         {                           Val = \"GridTable4-Accent5\"                         };<\/code><\/pre>\n<p>\u0415\u0433\u043e \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438 \u0433\u0440\u0430\u043d\u0438\u0446\u044b, \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a <em>TableProperties<\/em>:<\/p>\n<pre><code class=\"cs\">props.Append(tableStyle);<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0437\u0430\u043d\u044f\u043b\u0430 \u0432\u0441\u044e \u0448\u0438\u0440\u0438\u043d\u0443 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <em>TableWidth<\/em> \u0437\u0430\u0434\u0430\u043d\u043d\u0443\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cs\">var tableWidth = new TableWidth()                  {                    Width = \"5000\",                    Type = TableWidthUnitValues.Pct                  };<\/code><\/pre>\n<p>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 5000 \u0442\u0443\u0442 \u0432\u0437\u044f\u0442\u043e &#171;\u043d\u0435 \u0438\u0437 \u0432\u043e\u0437\u0434\u0443\u0445\u0430&#187;. \u0422\u0438\u043f \u0435\u0434\u0438\u043d\u0438\u0446\u044b \u0448\u0438\u0440\u0438\u043d\u044b \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u0437\u0430\u0434\u0430\u0451\u043c <em>TableWidthUnitValues.Pct<\/em> \u2013 \u0435\u0434\u0438\u043d\u0438\u0446\u044b \u0448\u0438\u0440\u0438\u043d\u044b \u0432 \u043e\u0434\u043d\u0443 \u043f\u044f\u0442\u0438\u0434\u0435\u0441\u044f\u0442\u0443\u044e \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0438\u043b\u0438 0,02%. \u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u044f\u0442\u044c \u0442\u044b\u0441\u044f\u0447 Pct \u044d\u0442\u043e 100% \u0448\u0438\u0440\u0438\u043d\u044b \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/p>\n<p>\u042d\u0442\u043e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a <em>TableProperties<\/em> \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cs\">props.Append(tableWidth);<\/code><\/pre>\n<p>\u0412\u0430\u0436\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442: <em>TableProperties<\/em> \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0434\u043e \u0441\u0430\u043c\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e. \u0418\u0445 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0438 \u043f\u043e\u0441\u043b\u0435 \u0434\u0440\u0443\u0433\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043d\u043e \u0442\u043e\u0433\u0434\u0430 \u0443\u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c<\/p>\n<pre><code class=\"cs\">dTable.PrependChild&lt;TableProperties>(props);<\/code><\/pre>\n<h4>\u0420\u0430\u0441\u043a\u0440\u0430\u0441\u043a\u0430 \u0442\u0430\u0431\u043b\u0438\u0446<\/h4>\n<p>\u0414\u043b\u044f \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043e\u0442\u0447\u0451\u0442\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0440\u0430\u0441\u043a\u0440\u0430\u0441\u0438\u0442\u044c \u044f\u0447\u0435\u0439\u043a\u0438 \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430.<\/p>\n<p><strong><em>Interop.Word:<\/em><\/strong><\/p>\n<pre><code class=\"cs\">oTable.Cell(i, j).Range.Shading.BackgroundPatternColor = MicrosoftWord.WdColor                                                                     .wdColorRed;<\/code><\/pre>\n<p>\u0433\u0434\u0435 <em>oTable<\/em> \u2013 \u044d\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0430\u044f \u043d\u0430\u043c\u0438 \u0440\u0430\u043d\u0435\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u0430, <em>i<\/em> \u0438 <em>j<\/em> \u2014 \u044d\u0442\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043d\u0443\u0436\u043d\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0438. \u041f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u2013 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/microsoft.office.interop.word.wdcolor?view=word-pia\">WdColor<\/a>. <\/p>\n<p><strong><em>Open XML:<\/em><\/strong><\/p>\n<pre><code class=\"cs\">tc.Append(new TableCellProperties(             new Shading { Fill = \"FF0000\" }));<\/code><\/pre>\n<p>\u0433\u0434\u0435 <em>tc<\/em> \u2013 \u044d\u0442\u043e <em>TableCell<\/em>, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0438\u0434\u0451\u0442 \u0440\u0430\u0431\u043e\u0442\u0430. \u041f\u043e\u043b\u044e <em>Fill<\/em> \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0441 Hex-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0446\u0432\u0435\u0442\u0430.<\/p>\n<h4>\u0420\u0430\u0437\u0440\u044b\u0432 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b<\/h4>\n<p>\u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0442\u0447\u0451\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0430\u0437\u0440\u044b\u0432 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430.<\/p>\n<p><strong><em>Interop.Word:<\/em><\/strong><\/p>\n<pre><code class=\"cs\">public static void InsertWordBreak(MicrosoftWord.Document doc) {   MicrosoftWord.Range wrdRng = doc.Bookmarks.get_Item(\"\\\\endofdoc\")                                             .Range;   wrdRng.InsertBreak(); }<\/code><\/pre>\n<p><strong><em>Open XML:<\/em><\/strong><\/p>\n<pre><code class=\"cs\">public static void InsertWordBreak(WordprocessingDocument doc) {   MainDocumentPart mainPart = doc.MainDocumentPart;   mainPart.Document.Body.InsertAfter(new Paragraph(                                        new Run(                                          new Break()                                          {                                             Type = BreakValues.Page                                          })),                                      mainPart.Document.Body.LastChild); }<\/code><\/pre>\n<p>\u0422\u0438\u043f \u0440\u0430\u0437\u0440\u044b\u0432\u0430 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/documentformat.openxml.wordprocessing.breakvalues?view=openxml-2.8.1\">BreakValues<\/a>.<\/p>\n<h4>Footer\/Header<\/h4>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u044b \u0431\u044b\u043b\u0438 \u0444\u0443\u0442\u0435\u0440\u044b\/\u0445\u0435\u0434\u0435\u0440\u044b \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435.<\/p>\n<p><strong><em>Interop.Word:<\/em><\/strong><\/p>\n<pre><code class=\"cs\">public static void InsertWordFooter(   MicrosoftWord.Document doc,   string headerText) {   MicrosoftWord.Range headerRange = doc.Sections                                  .Last                                  .Headers[MicrosoftWord.WdHeaderFooterIndex                                                        .wdHeaderFooterPrimary]                                  .Range;    headerRange.Fields.Add(headerRange, MicrosoftWord.WdFieldType.wdFieldPage);   headerRange.Text = headerText; }<\/code><\/pre>\n<p>\u0427\u0435\u0440\u0435\u0437 <em>headerRange.Font<\/em> \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0442\u0435\u043a\u0441\u0442\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0437\u043c\u0435\u0440, \u0448\u0440\u0438\u0444\u0442, \u0446\u0432\u0435\u0442 \u0438 \u0442.\u0434. \u0410 <em>headerRange.ParagraphFormat.Alignment<\/em>, \u043a\u0430\u043a \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0437 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f, \u0437\u0430\u0434\u0430\u0451\u0442 \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430. \u042d\u0442\u043e \u043f\u043e\u043b\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/microsoft.office.interop.word.wdparagraphalignment?view=word-pia\">WdParagraphAlignment<\/a>.<\/p>\n<p><strong><em>Open XML:<\/em><\/strong><\/p>\n<p>\u0422\u0443\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0444\u0443\u0442\u0435\u0440\/\u0445\u044d\u0434\u0435\u0440 \u0441\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c .xml \u0444\u0430\u0439\u043b\u0438\u043a\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0445\u044d\u0434\u0435\u0440\/\u0444\u0443\u0442\u0435\u0440 \u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/documentformat.openxml.wordprocessing.sectionproperties?view=openxml-2.8.1\">SectionProperties<\/a>.<\/p>\n<pre><code class=\"cs\">static void InsertWordHeader(HeaderPart part,                              string headerText) {   MainDocumentPart mainPart = doc.MainDocumentPart;    if (mainPart.HeaderParts.Any())     return;    HeaderPart headerPart = mainPart.AddNewPart&lt;HeaderPart>();    string headerPartId = mainPart.GetIdOfPart(headerPart);    part.Header = new Header(                   new Paragraph(                     new ParagraphProperties(                       new ParagraphStyleId() { Val = \"Header\" }),                       new Run( new Text() { Text = headerText })));    var sectionProperties = mainPart.Document                                   .Body                                   .GetFirstChild&lt;SectionProperties>();   sectionProperties.PrependChild&lt;HeaderReference>(new HeaderReference()                                                   {                                                     Id = headerPartId                                                   }); }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0442\u0435\u043a\u0441\u0442 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u043b\u0441\u044f \u043d\u0430 \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0445\u0435\u0434\u0435\u0440\u0430, \u0442\u043e \u0432\u043c\u0435\u0441\u0442\u043e <\/p>\n<pre><code class=\"cs\">if (mainPart.HeaderParts.Any())   return;<\/code><\/pre>\n<p>\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c<\/p>\n<pre><code class=\"cs\">mainDocumentPart.DeleteParts(mainDocumentPart.HeaderParts);<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0444\u0443\u0442\u0435\u0440\u0430 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c <em>mainDocumentPart.FooterParts<\/em>.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Open XML SDK \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0434\u043b\u044f \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438, \u0447\u0442\u043e \u043c\u044b \u0438 \u0441\u0434\u0435\u043b\u0430\u043b\u0438. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 Word \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u0442\u0430\u043b\u043e \u0434\u0430\u0436\u0435 \u0443\u0434\u043e\u0431\u043d\u0435\u0435, \u0447\u0435\u043c \u0431\u044b\u043b\u043e \u0441 Word Interop API.<\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0437\u0430\u043a\u043e\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441, \u0435\u0441\u0442\u044c \u043b\u0438 \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 Open XML SDK \u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438? \u041e\u0442\u0432\u0435\u0442 \u2013 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e \u0434\u0430. \u041d\u043e, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0442\u0430\u043a\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u0440\u0435\u043a\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f. \u0418\u0441\u0442\u043e\u0440\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0430\u043a\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u0432\u0441\u0435 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435: \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 Word, \u043e\u0441\u043e\u0437\u043d\u0430\u044e\u0442 \u043d\u0435\u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u0434\u043e\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442 \u0435\u0451 \u2014 \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u044e\u0442\u0441\u044f \u043d\u0430 GitHub. \u0414\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0443\u0434\u0430\u0441\u0442\u0441\u044f \u043d\u0430\u0439\u0442\u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0432\u0435\u0436\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0442\u043e, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u043e\u043d\u0430 \u0431\u044b\u043b\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u043f\u043e\u0434 \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u0438 \u0432 \u0432\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438. \u041f\u043b\u044e\u0441 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0440\u0438\u0441\u043a \u043e\u0441\u0442\u0430\u0442\u044c\u0441\u044f \u0441 \u043d\u0435\u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435\u0439 \u0441 \u0430\u043d\u0433\u043b\u043e\u044f\u0437\u044b\u0447\u043d\u043e\u0439 \u0430\u0443\u0434\u0438\u0442\u043e\u0440\u0438\u0435\u0439, \u0442\u043e \u043f\u0440\u043e\u0448\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043f\u0435\u0440\u0435\u0432\u043e\u0434: Victoria Khanieva, Svyatoslav Razmyslov. <a href=\"https:\/\/habr.com\/en\/company\/pvs-studio\/blog\/573860\/\">Tutorial: how to port a project from Interop Word API to Open XML SDK<\/a>.<\/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\/573866\/\"> https:\/\/habr.com\/ru\/articles\/573866\/<\/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<p>\u0421 \u0432\u044b\u0445\u043e\u0434\u043e\u043c .NET5 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0435 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u0434 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c \u0438\u0437-\u0437\u0430 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u043e\u0442 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u0438\u043b\u0438 \u043d\u0430\u0439\u0442\u0438 \u0438\u043c \u0437\u0430\u043c\u0435\u043d\u0443, \u0442\u043e \u043e\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 Microsoft.Office.Interop.Word.dll \u043e\u0447\u0435\u043d\u044c \u0441\u043b\u043e\u0436\u043d\u043e \u043e\u0442\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f. Microsoft \u043d\u0435 \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0441 .NET Core\/5+, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b Word \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Open XML SDK.<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<h3>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h3>\n<p>Office Open XML, \u0442\u0430\u043a\u0436\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 \u043a\u0430\u043a OpenXML \u0438\u043b\u0438 OOXML, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 XML \u0434\u043b\u044f \u043e\u0444\u0438\u0441\u043d\u044b\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u044b, \u0444\u0438\u0433\u0443\u0440\u044b \u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b. \u0412 \u0438\u044e\u043d\u0435 2014 \u0433\u043e\u0434\u0430 Microsoft \u0432\u044b\u043f\u0443\u0441\u0442\u0438\u043b\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 Open XML SDK \u043d\u0430 <a href=\"https:\/\/github.com\/OfficeDev\/Open-XML-SDK\">GitHub<\/a> \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0442\u0430\u043a\u0438\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u043c.<\/p>\n<p>\u0423 \u044d\u0442\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0435\u0441\u0442\u044c \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u044b\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430:<\/p>\n<ul>\n<li>\n<p>\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u0430 \u0441 .NET 5+,<\/p>\n<\/li>\n<li>\n<p>\u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 Microsoft Office,<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0441\u043e\u043a\u0430\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b,<\/p>\n<\/li>\n<li>\n<p>\u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434.<\/p>\n<\/li>\n<\/ul>\n<p>\u0411\u0435\u0437 \u043c\u0438\u043d\u0443\u0441\u043e\u0432 \u0442\u043e\u0436\u0435 \u043d\u0435 \u043e\u0431\u043e\u0448\u043b\u043e\u0441\u044c:<\/p>\n<ul>\n<li>\n<p>\u0441\u043b\u043e\u0436\u043d\u044b\u0439 API,<\/p>\n<\/li>\n<li>\n<p>\u0441\u043a\u0443\u0434\u043d\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u042d\u0442\u0438 \u043c\u0438\u043d\u0443\u0441\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430. \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u044d\u0442\u043e \u0438 \u0441\u0442\u0430\u043b\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u043e\u0439 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430.<\/p>\n<p>\u0410 \u0432\u043e\u0442 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043f\u043b\u044e\u0441\u043e\u043c. \u0415\u0441\u043b\u0438 \u0431\u044b \u043a\u043e\u0434 COM-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0431\u044b\u043b \u043e\u0442\u043a\u0440\u044b\u0442, \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043f\u043e\u043c\u043e\u0433\u043b\u043e \u0431\u044b \u0441 \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043d\u0430 .NET Core\/5+. \u041a\u0440\u043e\u043c\u0435 \u043f\u0440\u0438\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u043e\u0434 \u0434\u0430\u0451\u0442 \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0438 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0438 \u0443\u044f\u0437\u0432\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 \u0445\u043e\u0442\u044f \u0431\u044b \u0441\u043e\u043e\u0431\u0449\u0430\u0442\u044c \u043e \u043d\u0438\u0445. \u041a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u043e\u0447\u0435\u043d\u044c <a href=\"https:\/\/pvs-studio.com\/ru\/blog\/posts\/cpp\/0762\/\">\u0432\u0430\u0436\u043d\u043e<\/a> \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043b\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 <a href=\"https:\/\/pvs-studio.com\/ru\/blog\/posts\/csharp\/0777\/\">\u0430\u0443\u0434\u0438\u0442 \u043a\u043e\u0434\u0430<\/a> Open XML SDK \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u0435 \u0441 \u044d\u0442\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439.<\/p>\n<h3>\u0411\u043e\u043b\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 Office<\/h3>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 Office \u0431\u044b\u043b\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043e \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u0441\u043e\u0444\u0442\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u043c\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c\u0438. \u042d\u0442\u043e \u043f\u043b\u0430\u0433\u0438\u043d\u044b \u0434\u043b\u044f Word, Excel, Outlook. \u041c\u043d\u043e\u0433\u0438\u0435 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u043d\u0430\u0434\u0435\u043b\u0430\u043b\u0438 \u0441\u0435\u0431\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u0445 \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u0432 \u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u043e\u0442\u0447\u0451\u0442\u043e\u0432 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 Word. \u0410 3 \u0438\u044e\u043b\u044f 2021 \u0433\u043e\u0434\u0430 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u0441\u0442\u0440\u0430\u0448\u043d\u043e\u0435 \u2013 \u0432\u0441\u0435 \u0442\u0438\u043a\u0435\u0442\u044b \u043f\u0440\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 .NET 5+ \u0432 VSTO \/ COM, \u0440\u0430\u0437\u0431\u0440\u043e\u0441\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0440\u0430\u0437\u043d\u044b\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c, \u0431\u044b\u043b\u0438 \u0432 \u043e\u0434\u043d\u043e\u0447\u0430\u0441\u044c\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u044b \u0441 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u0435\u043b\u0435\u0439 Microsoft \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u0440\u043e\u0434\u0430:<\/p>\n<blockquote>\n<p>&#8230;The VSTO\/COM Add-Ins platform is very important to Microsoft, and we plan to continue to support it in Office with .NET Framework 4.8 as the last major version&#8230;VSTO\/COM Add-Ins cannot be created with .NET Core and .NET 5+. This is because .NET Core\/.NET 5+ cannot work together with .NET Framework in the same process and may lead to add-in load failures. Microsoft will not be updating VSTO or the COM Add-in platform to use .NET Core or .NET 5+&#8230; <\/p>\n<\/blockquote>\n<p>\u041f\u043e \u0438\u0445 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 .NET 5+ \u043d\u0435 \u043f\u0440\u0435\u0434\u0432\u0438\u0434\u0438\u0442\u0441\u044f. \u0412\u043e\u0442 \u043e\u0434\u043d\u0430 \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u0434\u0438\u0441\u043a\u0443\u0441\u0441\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0435\u0449\u0451 \u0434\u043e\u043b\u0433\u043e \u043d\u0435 \u043f\u0440\u0435\u043a\u0440\u0430\u0449\u0430\u043b\u0430\u0441\u044c \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f: &#171;<a href=\"https:\/\/developercommunity.visualstudio.com\/t\/Please-port-Visual-Studio-Tools-For-Offi\/757925\">Please port Visual Studio Tools For Office (VSTO) to .NET 5\/7, to enable VSTO add-in development in C# in .Net 5\/7<\/a>&#171;.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u0432 \u0441\u043e\u0432\u0441\u0435\u043c \u0432\u0441\u0451 \u043f\u043b\u043e\u0445\u043e \u2013 \u0438\u043c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0430 Office JavaScript API (\u0441\u043e\u0432\u0441\u0435\u043c \u0434\u0440\u0443\u0433\u043e\u0439 \u044f\u0437\u044b\u043a, API \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u0438 \u043c\u0430\u043b\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0431\u044b\u043b\u043e), \u0442\u043e \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u0437 C# \u043a\u043e\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 Open XML SDK (<a href=\"https:\/\/www.nuget.org\/packages\/Open-XML-SDK\">nuget<\/a>).<\/p>\n<h3>\u041e\u0441\u043d\u043e\u0432\u044b<\/h3>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u0440\u0430\u0437\u0431\u043e\u0440\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u043d\u044f\u0442\u044c, \u0441 \u0447\u0435\u043c \u0432\u043e\u043e\u0431\u0449\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u044d\u0442\u0438 \u0434\u0432\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0438 \u0432 \u0447\u0451\u043c \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0438\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432.<\/p>\n<p>Word \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u2014 \u044d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u0437\u0430\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0445 xml-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u0412\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043f\u043e\u0434 \u0442\u0435\u0433\u0430\u043c\u0438.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444 \u0432\u043d\u0443\u0442\u0440\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"xml\">&lt;w:p w:rsidR=\"007D2247\" w:rsidRDefault=\"009A4B44\"          xmlns:w=\"http:\/\/schemas.openxmlformats.org\/wordprocessingml\/2006\/main\">   &lt;w:r>     &lt;w:t>\u0442\u0435\u0441\u0442&lt;\/w:t>   &lt;\/w:r>   &lt;w:bookmarkStart w:name=\"_GoBack\" w:id=\"0\" \/>   &lt;w:bookmarkEnd w:id=\"0\" \/> &lt;\/w:p><\/code><\/pre>\n<p>\u0421\u0431\u043e\u0440\u043a\u0430 Interop.Word \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0430\u0431\u0441\u0442\u0440\u0430\u0433\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043e\u0442 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438 \u0447\u0430\u0441\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0443\u0447\u0430\u0441\u0442\u043a\u043e\u043c \u2013 Range \u2013 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430. \u0410 Open XML SDK \u0438\u0434\u0451\u0442 \u043f\u043e \u043f\u0443\u0442\u0438 \u043e\u0442\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u043e\u0434\u0435. \u041f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u044b <em>&lt;w:p><\/em>, \u0443\u0447\u0430\u0441\u0442\u043a\u0438 \u0442\u0435\u043a\u0441\u0442\u0430 <em>&lt;w:t><\/em> \u0438 \u0432\u0441\u0451 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u043e\u0434\u0435. \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u0442\u0435 \u0442\u0435\u043b\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430, \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444 \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 &#171;\u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u0439&#187;, \u0442\u043e \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043a\u0443\u0434\u0430.<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430 \u0441\u043a\u0440\u0438\u043d\u0448\u043e\u0442\u0435 \u043a\u0430\u043a \u0440\u0430\u0437 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0430 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044f\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0434\u043b\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 Word \u2013 document.xml. \u042d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u0430\u043c\u043e \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430.<\/p>\n<p>\u0421\u043a\u0440\u0438\u043d\u0448\u043e\u0442 \u0441\u0434\u0435\u043b\u0430\u043d \u0432 \u043e\u0447\u0435\u043d\u044c \u043d\u0443\u0436\u043d\u043e\u0439 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Open XML \u0443\u0442\u0438\u043b\u0438\u0442\u0435 Open XML SDK 2.5 Productivity Tool. \u041a \u043c\u043e\u043c\u0435\u043d\u0442\u0443 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438 \u044d\u0442\u0430 \u0443\u0442\u0438\u043b\u0438\u0442\u0430 \u0431\u044b\u043b\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0430 \u0441 \u0441\u0430\u0439\u0442\u0430 Microsoft, \u0430 \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 <a href=\"https:\/\/github.com\/OfficeDev\/Open-XML-SDK\">Open-XML-SDK<\/a> \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043d\u0435\u043a\u0438\u0439 <a href=\"https:\/\/github.com\/rmboggs\/DocxToSource\">DocxToSource<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u0442\u0430\u0442\u044c \u0437\u0430\u043c\u0435\u043d\u043e\u0439 \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0435\u0433\u043e Productivity Tool. \u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u0430 \u0437\u0430\u043c\u0435\u043d\u0430 \u0432\u0441\u0451 \u0435\u0449\u0451 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u043e\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u043a\u0430 \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u0439\u0442\u0438 \u0441\u0442\u0430\u0440\u044b\u0439 \u0434\u043e\u0431\u0440\u044b\u0439 Productivity Tool. \u0421\u0442\u0430\u0440\u0430\u044f \u0443\u0442\u0438\u043b\u0438\u0442\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430, \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u0430\u0432\u0442\u043e\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c. <\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043e\u043d\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0434\u0432\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 (\u0438 \u043a\u043e\u0434 \u0434\u043b\u044f \u0438\u0445 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f, \u0438 \u0438\u0445 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435). <\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440\u044b<\/h3>\n<p>\u0414\u043b\u044f Interop.Word \u0432\u043e \u0432\u0441\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u0438\u043c\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0447\u0442\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"cs\">using MicrosoftWord = Microsoft.Office.Interop.Word;<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u043c \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c Open XML SDK \u043f\u0440\u043e\u0441\u0442\u043e Open XML.<\/p>\n<h4>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430<\/h4>\n<p><strong><em>Interop.Word:<\/em><\/strong><\/p>\n<pre><code class=\"cs\">MicrosoftWord.Application wordApp = new MicrosoftWord.Application(); MicrosoftWord.Document wordDoc = wordApp.Documents.Add(); MicrosoftWord.Range docRange = wordDoc.Range(); .... \/\/ \u0442\u0443\u0442 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u043c wordDoc.SaveAs2(pathToDocFile); wordApp.Quit();<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0432\u0441\u0451 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e, \u043d\u043e \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438. \u041f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 Interop \u043c\u044b \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u043c \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u0430 \u0441 COM-\u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0442\u044c \u0432\u0441\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u043f\u043e\u0441\u043b\u0435 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u042d\u0442\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043d\u0435 \u0440\u0430\u0437 \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u043b\u0430\u0441\u044c \u043d\u0430 Stack Overflow (<a href=\"https:\/\/stackoverflow.com\/questions\/158706\/how-do-i-properly-clean-up-excel-interop-objects?page=1&amp;tab=active\">1<\/a>, <a href=\"https:\/\/stackoverflow.com\/questions\/25134024\/clean-up-excel-interop-objects-with-idisposable\/25135685\">2<\/a>), \u0438 \u0435\u0439 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439.<\/p>\n<p>\u0415\u0441\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0441 \u0443\u0447\u0430\u0441\u0442\u0438\u0435\u043c <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/system.runtime.interopservices.marshal?view=net-5.0\">Marshal Class<\/a>, \u044f\u0432\u043b\u044f\u044e\u0449\u0438\u043c\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e InteropServices.<\/p>\n<pre><code class=\"cs\">finally {   if (Marshal.IsComObject(wordDoc))     try     {       Marshal.FinalReleaseComObject(wordDoc);     }     catch { throw; }     if (Marshal.IsComObject(wordApp))     try     {       Marshal.FinalReleaseComObject(wordApp);     }     catch { throw; } }<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b.<\/p>\n<p>\u0415\u0441\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043d\u0430\u0434\u0451\u0436\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435\u043c \u043a <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/system.gc?view=net-5.0\">GC<\/a>:<\/p>\n<pre><code class=\"cs\">GC.Collect(); GC.WaitForPendingFinalizers();<\/code><\/pre>\n<p>\u042d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043d\u0430\u0434\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0432\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 COM-\u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b, \u0442\u043e \u043f\u0440\u0438 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u043c \u0434\u0435\u0431\u0430\u0433\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u0435\u0431\u0435 \u0442\u0430\u043a\u0443\u044e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u043e \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432 \u043a\u043e\u0434\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b, \u043f\u0440\u0438 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0438\u043b\u0438 \u0435\u0451 \u043f\u0430\u0434\u0435\u043d\u0438\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u043c. \u0422\u0430\u043a\u043e\u0433\u043e \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0430 \u043d\u0435\u0442 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0447\u0435\u0440\u0435\u0437 Open XML.<\/p>\n<p><strong><em>Open XML:<\/em><\/strong><\/p>\n<pre><code class=\"cs\">using (WordprocessingDocument doc =           WordprocessingDocument.Create(pathToDocFile,                                        WordprocessingDocumentType.Document,                                        true)) {   MainDocumentPart mainPart = doc.AddMainDocumentPart();   mainPart.Document = new Document();   Body body = mainPart.Document.AppendChild(new Body());   SectionProperties props = new SectionProperties();   body.AppendChild(props); }<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 <em>SectionProperties<\/em>, \u043e\u043d\u0438 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u043d\u0430\u043c \u043f\u043e\u0437\u0436\u0435.<\/p>\n<h4>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u0430<\/h4>\n<p><strong><em>Interop.Word<\/em><\/strong><\/p>\n<pre><code class=\"cs\">public static void InsertWordText(MicrosoftWord.Document doc,                                       string text) {   MicrosoftWord.Paragraph paragraph = doc.Paragraphs.Add(Missing.Value);   paragraph.Range.Text = text;   paragraph.Range.InsertParagraphAfter(); }<\/code><\/pre>\n<p>\u0422\u0435\u043a\u0441\u0442 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0436\u0438\u0440\u043d\u044b\u043c \u0438\u043b\u0438 \u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u043c \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <em>Font<\/em>:<\/p>\n<pre><code class=\"cs\">paragraph.Range.Font.Bold = 1; paragraph.Range.Font.Italic = 1;<\/code><\/pre>\n<p>\u0418\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u0448\u0440\u0438\u0444\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0447\u0435\u0440\u0435\u0437:<\/p>\n<pre><code class=\"cs\">paragraph.Range.Font.Size = 14;<\/code><\/pre>\n<p>\u0412\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 <em>ParagraphFormat.Alignment<\/em>:<\/p>\n<pre><code class=\"cs\">paragraph.Range.ParagraphFormat.Alignment = MicrosoftWord.WdParagraphAlignment                                                         .wdAlignParagraphCenter;<\/code><\/pre>\n<p><strong><em>Open XML:<\/em><\/strong><\/p>\n<pre><code class=\"cs\">public static void AddText(WordprocessingDocument doc, string text) {   MainDocumentPart mainPart = doc.MainDocumentPart;   Body body = mainPart.Document.Body;   Paragraph paragraph = body.AppendChild(new Paragraph());    Run run = paragraph.AppendChild(new Run());   run.AppendChild(new Text(text));   run.PrependChild(new RunProperties()); }<\/code><\/pre>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 Open XML \u0436\u0438\u0440\u043d\u044b\u043c \u0438\u043b\u0438 \u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u043c \u0442\u0435\u043a\u0441\u0442 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437:<\/p>\n<pre><code class=\"cs\">run.RunProperties.AddChild(new Bold()); run.RunProperties.AddChild(new Italic());<\/code><\/pre>\n<p>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0448\u0440\u0438\u0444\u0442\u0430 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043d\u0435\u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e, \u043d\u043e \u0441\u043e\u0433\u043b\u0430\u0441\u0443\u0435\u0442\u0441\u044f \u0441 \u043e\u0431\u0449\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Open XML:<\/p>\n<pre><code class=\"cs\">run.RunProperties.AddChild(new FontSize(){ Val = \"14\"});<\/code><\/pre>\n<p>\u0412\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430:<\/p>\n<pre><code class=\"cs\">paragraph.ParagraphProperties.AddChild(new Justification()                                        {                                          Val = JustificationValues.Center                                        });<\/code><\/pre>\n<p>\u0412\u0430\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u0443 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430:<\/p>\n<pre><code class=\"cs\">paragraph.AppendChild(new ParagraphProperties());<\/code><\/pre>\n<h4>\u0412\u0441\u0442\u0430\u0432\u043a\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430<\/h4>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 Interop.Word \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a \u0432\u0441\u0442\u0430\u0432\u043a\u0435 \u0442\u0435\u043a\u0441\u0442\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a:<\/p>\n<p><strong><em>Interop.Word:<\/em><\/strong><\/p>\n<pre><code class=\"cs\">public static void InsertWordHeading1(MicrosoftWord.Document doc,                                       string headingText) {   MicrosoftWord.Paragraph paragraph = doc.Paragraphs.Add(Missing.Value);   paragraph.Range.Text = headingText;   paragraph.Range.set_Style(\"Heading 1\");   paragraph.Range.InsertParagraphAfter(); }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u0434\u0430\u0451\u043c Range \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 \u0438 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u0435\u043c\u0443 \u0441\u0442\u0438\u043b\u044c <em>Heading 1<\/em>.<\/p>\n<p><strong><em>Open XML:<\/em><\/strong><\/p>\n<pre><code class=\"cs\">public static void InsertWordHeading1(WordprocessingDocument doc,                                       string headingText) {   MainDocumentPart mainPart = doc.MainDocumentPart;   Paragraph para = mainPart.Document.Body.AppendChild(new Paragraph());   Run run = para.AppendChild(new Run());   run.AppendChild(new Text(headingText));   para.ParagraphProperties = new ParagraphProperties(                                new ParagraphStyleId() { Val = \"Heading1\" }); }<\/code><\/pre>\n<p>\u0422\u0443\u0442, \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0432\u0441\u0451 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0435. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444 \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 Open XML \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0443\u0435\u043c \u043d\u0443\u0436\u043d\u0443\u044e \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 Open XML<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-405574","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/405574","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=405574"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/405574\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=405574"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=405574"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=405574"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}