├── .gitattributes ├── .github └── FUNDING.yml ├── .gitignore ├── PSWord.Tests ├── Class1Test.cs ├── PSWord.Tests.csproj ├── Properties │ ├── AssemblyInfo.cs │ └── PexAssemblyInfo.cs └── packages.config ├── PSWord ├── .vs │ └── config │ │ └── applicationhost.config ├── AddWordList.cs ├── AddWordPicture.cs ├── AddWordTable.cs ├── AddWordTableofContents.cs ├── AddWordText.cs ├── Enumerators.cs ├── GetWordDocument.cs ├── GetWordParagraph.cs ├── GetWordTable.cs ├── NewWordFormatting.cs ├── NewWordList.cs ├── PSWORD.png ├── PSWord.csproj ├── PSWord.psd1 ├── PSWord.sln ├── Properties │ └── AssemblyInfo.cs ├── ProtectWordDocument.cs ├── README.md ├── SetWordListItem.cs ├── UpdateWordText.cs ├── appveyor.yaml ├── en-US │ └── PSWord.dll-Help.xml └── packages.config ├── README.md ├── Release ├── DocX.dll ├── PSWord.dll ├── PSWord.psd1 └── en-US │ └── PSWord.dll-Help.xml └── install.ps1 /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.config 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: guidooliveira 4 | ko_fi: guidooliveira 5 | custom: ["https://paypal.me/guidoboliveira"] 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # Build results 11 | [Dd]ebug/ 12 | [Dd]ebugPublic/ 13 | x64/ 14 | x86/ 15 | build/ 16 | bld/ 17 | [Bb]in/ 18 | [Oo]bj/ 19 | 20 | # Roslyn cache directories 21 | *.ide/ 22 | 23 | # MSTest test Results 24 | [Tt]est[Rr]esult*/ 25 | [Bb]uild[Ll]og.* 26 | 27 | #NUNIT 28 | *.VisualState.xml 29 | TestResult.xml 30 | 31 | # Build Results of an ATL Project 32 | [Dd]ebugPS/ 33 | dlldata.c 34 | 35 | *_i.c 36 | *_p.c 37 | *_i.h 38 | *.ilk 39 | *.meta 40 | *.obj 41 | *.pch 42 | *.pdb 43 | *.pgc 44 | *.pgd 45 | *.rsp 46 | *.sbr 47 | *.tlb 48 | *.tli 49 | *.tlh 50 | *.tmp 51 | *.tmp_proj 52 | *.log 53 | *.vspscc 54 | *.vssscc 55 | .builds 56 | *.pidb 57 | *.svclog 58 | *.scc 59 | 60 | # Chutzpah Test files 61 | _Chutzpah* 62 | 63 | # Visual C++ cache files 64 | ipch/ 65 | *.aps 66 | *.ncb 67 | *.opensdf 68 | *.sdf 69 | *.cachefile 70 | 71 | # Visual Studio profiler 72 | *.psess 73 | *.vsp 74 | *.vspx 75 | 76 | # TFS 2012 Local Workspace 77 | $tf/ 78 | 79 | # Guidance Automation Toolkit 80 | *.gpState 81 | 82 | # ReSharper is a .NET coding add-in 83 | _ReSharper*/ 84 | *.[Rr]e[Ss]harper 85 | *.DotSettings.user 86 | 87 | # JustCode is a .NET coding addin-in 88 | .JustCode 89 | 90 | # TeamCity is a build add-in 91 | _TeamCity* 92 | 93 | # DotCover is a Code Coverage Tool 94 | *.dotCover 95 | 96 | # NCrunch 97 | _NCrunch_* 98 | .*crunch*.local.xml 99 | 100 | # MightyMoose 101 | *.mm.* 102 | AutoTest.Net/ 103 | 104 | # Web workbench (sass) 105 | .sass-cache/ 106 | 107 | # Installshield output folder 108 | [Ee]xpress/ 109 | 110 | # DocProject is a documentation generator add-in 111 | DocProject/buildhelp/ 112 | DocProject/Help/*.HxT 113 | DocProject/Help/*.HxC 114 | DocProject/Help/*.hhc 115 | DocProject/Help/*.hhk 116 | DocProject/Help/*.hhp 117 | DocProject/Help/Html2 118 | DocProject/Help/html 119 | 120 | # Click-Once directory 121 | publish/ 122 | 123 | # Publish Web Output 124 | *.[Pp]ublish.xml 125 | *.azurePubxml 126 | # TODO: Comment the next line if you want to checkin your web deploy settings 127 | # but database connection strings (with potential passwords) will be unencrypted 128 | *.pubxml 129 | *.publishproj 130 | 131 | # NuGet Packages 132 | *.nupkg 133 | # The packages folder can be ignored because of Package Restore 134 | **/packages/* 135 | # except build/, which is used as an MSBuild target. 136 | !**/packages/build/ 137 | # If using the old MSBuild-Integrated Package Restore, uncomment this: 138 | #!**/packages/repositories.config 139 | 140 | # Windows Azure Build Output 141 | csx/ 142 | *.build.csdef 143 | 144 | # Windows Store app package directory 145 | AppPackages/ 146 | 147 | # Others 148 | sql/ 149 | *.Cache 150 | ClientBin/ 151 | [Ss]tyle[Cc]op.* 152 | ~$* 153 | *~ 154 | *.dbmdl 155 | *.dbproj.schemaview 156 | *.pfx 157 | *.publishsettings 158 | node_modules/ 159 | 160 | # RIA/Silverlight projects 161 | Generated_Code/ 162 | 163 | # Backup & report files from converting an old project file 164 | # to a newer Visual Studio version. Backup files are not needed, 165 | # because we have git ;-) 166 | _UpgradeReport_Files/ 167 | Backup*/ 168 | UpgradeLog*.XML 169 | UpgradeLog*.htm 170 | 171 | # SQL Server files 172 | *.mdf 173 | *.ldf 174 | 175 | # Business Intelligence projects 176 | *.rdl.data 177 | *.bim.layout 178 | *.bim_*.settings 179 | 180 | # Microsoft Fakes 181 | FakesAssemblies/ 182 | 183 | # ========================= 184 | # Operating System Files 185 | # ========================= 186 | 187 | # OSX 188 | # ========================= 189 | 190 | .DS_Store 191 | .AppleDouble 192 | .LSOverride 193 | 194 | # Thumbnails 195 | ._* 196 | 197 | # Files that might appear on external disk 198 | .Spotlight-V100 199 | .Trashes 200 | 201 | # Directories potentially created on remote AFP share 202 | .AppleDB 203 | .AppleDesktop 204 | Network Trash Folder 205 | Temporary Items 206 | .apdisk 207 | 208 | # Windows 209 | # ========================= 210 | 211 | # Windows image file caches 212 | Thumbs.db 213 | ehthumbs.db 214 | 215 | # Folder config file 216 | Desktop.ini 217 | 218 | # Recycle Bin used on file shares 219 | $RECYCLE.BIN/ 220 | 221 | # Windows Installer files 222 | *.cab 223 | *.msi 224 | *.msm 225 | *.msp 226 | 227 | # Windows shortcuts 228 | *.lnk 229 | -------------------------------------------------------------------------------- /PSWord.Tests/Class1Test.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guidooliveira/PSWord/a11c89f6c713c272e04bd8700d9c2598560f7bd2/PSWord.Tests/Class1Test.cs -------------------------------------------------------------------------------- /PSWord.Tests/PSWord.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | {FA254AF9-1F83-403A-862D-55A39C23BE56} 7 | Library 8 | Properties 9 | PSWord.Tests 10 | PSWord.Tests 11 | v4.5.2 12 | 512 13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 10.0 15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 17 | False 18 | UnitTest 19 | True 20 | Full 21 | 22 | 23 | true 24 | full 25 | false 26 | bin\Debug\ 27 | DEBUG;TRACE 28 | prompt 29 | 4 30 | 31 | 32 | pdbonly 33 | true 34 | bin\Release\ 35 | TRACE 36 | prompt 37 | 4 38 | 39 | 40 | 41 | False 42 | E:\Downloads\DocX.dll 43 | 44 | 45 | ..\..\..\..\..\..\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Pex\Microsoft.Pex.Framework.dll 46 | 47 | 48 | ..\PSWord\packages\NUnit.3.0.0-beta-3\lib\net45\nunit.framework.dll 49 | True 50 | 51 | 52 | 53 | ..\PSWord\packages\System.Management.Automation.6.1.7601.17515\lib\net45\System.Management.Automation.dll 54 | True 55 | 56 | 57 | 58 | 59 | {D2640933-09D8-4CE2-AC2B-03DEF1B82B1A} 60 | PSWord 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | False 88 | 89 | 90 | False 91 | 92 | 93 | False 94 | 95 | 96 | False 97 | 98 | 99 | 100 | 101 | 102 | 103 | 110 | -------------------------------------------------------------------------------- /PSWord.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guidooliveira/PSWord/a11c89f6c713c272e04bd8700d9c2598560f7bd2/PSWord.Tests/Properties/AssemblyInfo.cs -------------------------------------------------------------------------------- /PSWord.Tests/Properties/PexAssemblyInfo.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guidooliveira/PSWord/a11c89f6c713c272e04bd8700d9c2598560f7bd2/PSWord.Tests/Properties/PexAssemblyInfo.cs -------------------------------------------------------------------------------- /PSWord.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /PSWord/.vs/config/applicationhost.config: -------------------------------------------------------------------------------- 1 |  2 | 20 | 21 | 22 | 23 | 50 | 51 | 52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | 61 | 62 | 63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | 81 |
82 |
83 | 84 |
85 |
86 |
87 |
88 |
89 |
90 | 91 |
92 |
93 |
94 |
95 |
96 | 97 |
98 |
99 |
100 | 101 |
102 |
103 | 104 |
105 |
106 | 107 |
108 |
109 |
110 | 111 | 112 |
113 |
114 |
115 |
116 |
117 |
118 | 119 |
120 |
121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | 869 | 870 | 871 | 872 | 873 | 874 | 875 | 876 | 877 | 878 | 879 | 880 | 881 | 882 | 883 | 884 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 894 | 895 | 896 | 897 | 898 | 899 | 902 | 903 | 904 | 905 | 906 | 907 | 908 | 909 | 910 | 911 | 912 | 913 | 914 | 915 | 916 | 917 | 918 | 919 | 920 | 921 | 922 | 923 | 924 | 925 | 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | 935 | 936 | 937 | 938 | 939 | 940 | 941 | 942 | 943 | 944 | 945 | 946 | 947 | 948 | 949 | 950 | 951 | 952 | 953 | 954 | 955 | 956 | 957 | 958 | 959 | 960 | 961 | 962 | 963 | 964 | 965 | 966 | 967 | 968 | 969 | 970 | 971 | 972 | 973 | 974 | 975 | 976 | 977 | 978 | 979 | 980 | 981 | 982 | 983 | 984 | 985 | 986 | 987 | 988 | 989 | 990 | 991 | 992 | 993 | 994 | 995 | 996 | 997 | 998 | 999 | 1000 | 1001 | 1002 | 1003 | 1004 | 1005 | 1006 | 1007 | 1008 | 1009 | 1010 | 1011 | 1012 | 1013 | 1014 | 1015 | 1016 | 1017 | 1018 | 1019 | 1020 | -------------------------------------------------------------------------------- /PSWord/AddWordList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Management.Automation; 7 | using System.IO; 8 | using Novacode; 9 | using System.Diagnostics; 10 | 11 | namespace PSWord 12 | { 13 | [Cmdlet(VerbsCommon.Add, "WordList")] 14 | public class AddWordList : PSCmdlet 15 | { 16 | [Parameter] 17 | public string FilePath { get; set; } 18 | 19 | [Parameter] 20 | public Novacode.List List { get; set; } 21 | 22 | [Parameter] 23 | public SwitchParameter Show { get; set; } 24 | private string resolvedPath { get; set; } 25 | private DocX wordDocument { get; set; } 26 | protected override void BeginProcessing() 27 | { 28 | this.resolvedPath = this.GetUnresolvedProviderPathFromPSPath(this.FilePath); 29 | if (File.Exists(this.resolvedPath)) 30 | { 31 | this.wordDocument = DocX.Load(this.resolvedPath); 32 | } 33 | } 34 | protected override void ProcessRecord() 35 | { 36 | this.wordDocument.InsertList(this.List); 37 | } 38 | 39 | protected override void EndProcessing() 40 | { 41 | try 42 | { 43 | using (this.wordDocument) 44 | { 45 | this.wordDocument.SaveAs(this.resolvedPath); 46 | } 47 | } 48 | catch (Exception exception) 49 | { 50 | this.WriteError(new ErrorRecord(exception, exception.HResult.ToString(), ErrorCategory.WriteError, exception)); 51 | } 52 | if (this.Show.IsPresent) 53 | { 54 | Process.Start(this.resolvedPath); 55 | } 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /PSWord/AddWordPicture.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Management.Automation; 7 | using Novacode; 8 | using System.IO; 9 | using System.Diagnostics; 10 | using System.Reflection; 11 | using System.Drawing; 12 | 13 | namespace PSWord 14 | { 15 | using System.Collections; 16 | using System.Collections.ObjectModel; 17 | using System.Data.Odbc; 18 | using System.Runtime.CompilerServices; 19 | 20 | using Image = System.Drawing.Image; 21 | 22 | [Cmdlet(VerbsCommon.Add, "WordPicture")] 23 | public class AddWordPicture : PSCmdlet 24 | { 25 | [Parameter(Position = 0, Mandatory = true)] 26 | [ValidateNotNullOrEmpty] 27 | public string FilePath { get; set; } 28 | 29 | [Parameter] 30 | [ValidateNotNullOrEmpty] 31 | public BasicShapes PictureShape { get; set; } 32 | 33 | [Parameter] 34 | [ValidateNotNullOrEmpty] 35 | public string PicturePath { get; set; } 36 | 37 | [Parameter] 38 | public string PostContent { get; set; } 39 | 40 | [Parameter] 41 | public string PreContent { get; set; } 42 | 43 | [Parameter] 44 | public int PictureHeight { get; set; } 45 | 46 | [Parameter] 47 | public int PictureWidth { get; set; } 48 | [Parameter] 49 | [ValidateRange(-360,360)] 50 | public uint Rotation { get; set; } 51 | 52 | [Parameter] 53 | public SwitchParameter Show { get; set; } 54 | 55 | //private Image documentPicture { get; set; } 56 | private DocX wordDocument { get; set; } 57 | private Paragraph paragraph { get; set; } 58 | private Paragraph PreContentparagraph { get; set; } 59 | private Paragraph PostContentparagraph { get; set; } 60 | private string resolvedPath { get; set; } 61 | protected override void BeginProcessing() 62 | { 63 | this.resolvedPath = this.GetUnresolvedProviderPathFromPSPath(this.FilePath); 64 | 65 | if (!File.Exists(this.resolvedPath)) 66 | { 67 | this.wordDocument = DocX.Create(this.resolvedPath); 68 | } 69 | else 70 | { 71 | this.wordDocument = DocX.Load(this.resolvedPath); 72 | } 73 | } 74 | 75 | protected override void ProcessRecord() 76 | { 77 | 78 | try 79 | { 80 | ProviderInfo propertyInfo = null; 81 | var pictureFilePath = this.GetResolvedProviderPathFromPSPath(this.PicturePath, out propertyInfo); 82 | 83 | this.WriteVerbose(String.Format(@"Appending {0} to the Word Document...", pictureFilePath[0])); 84 | if (!String.IsNullOrEmpty(this.PreContent)) 85 | { 86 | this.PreContentparagraph = this.wordDocument.InsertParagraph(this.PreContent, false); 87 | } 88 | using (MemoryStream ms = new MemoryStream()) 89 | { 90 | System.Drawing.Image myImg = System.Drawing.Image.FromFile(pictureFilePath[0]); 91 | 92 | myImg.Save(ms, myImg.RawFormat); // Save your picture in a memory stream. 93 | ms.Seek(0, SeekOrigin.Begin); 94 | 95 | Novacode.Image image = this.wordDocument.AddImage(ms); // Create image. 96 | 97 | this.paragraph = this.wordDocument.InsertParagraph("", false); 98 | 99 | Picture picture = image.CreatePicture(); // Create picture. 100 | if (this.PictureHeight > 0) 101 | { 102 | picture.Height = this.PictureHeight; 103 | } 104 | else 105 | { 106 | picture.Height = myImg.Height; 107 | } 108 | if(this.PictureWidth > 0) 109 | { 110 | picture.Width = this.PictureWidth; 111 | } 112 | else 113 | { 114 | picture.Width = myImg.Width; 115 | } 116 | //if (!String.IsNullOrEmpty(this.PictureShape.ToString())) 117 | //{ 118 | // picture.SetPictureShape(this.PictureShape); // Set picture shape (if needed) 119 | //} 120 | 121 | if (this.Rotation > 0) 122 | { 123 | picture.Rotation = this.Rotation; 124 | } 125 | 126 | this.paragraph.InsertPicture(picture, 0); // Insert picture into paragraph. 127 | } 128 | if (!String.IsNullOrEmpty(this.PostContent)) 129 | { 130 | this.PostContentparagraph = this.wordDocument.InsertParagraph(this.PostContent, false); 131 | } 132 | 133 | } 134 | catch (Exception exception) 135 | { 136 | this.WriteError(new ErrorRecord(exception, exception.HResult.ToString(), ErrorCategory.WriteError, exception)); 137 | } 138 | } 139 | 140 | protected override void EndProcessing() 141 | { 142 | try 143 | { 144 | using (this.wordDocument) 145 | { 146 | this.wordDocument.Save(); 147 | } 148 | } 149 | catch (Exception exception) 150 | { 151 | this.WriteError(new ErrorRecord(exception, exception.HResult.ToString(), ErrorCategory.WriteError, exception)); 152 | } 153 | if (this.Show.IsPresent) 154 | { 155 | Process.Start(this.resolvedPath); 156 | } 157 | } 158 | } 159 | } -------------------------------------------------------------------------------- /PSWord/AddWordTable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Management.Automation; 4 | using Novacode; 5 | using System.IO; 6 | using System.Diagnostics; 7 | 8 | 9 | namespace PSWord 10 | { 11 | 12 | [Cmdlet(VerbsCommon.Add, "WordTable")] 13 | public class AddWordTable : PSCmdlet 14 | { 15 | [Parameter(Position = 0, Mandatory = true)] 16 | public string FilePath { get; set; } 17 | 18 | [Parameter(Position = 1, Mandatory = true, ValueFromPipeline = true)] 19 | public PSObject[] InputObject { get; set; } 20 | 21 | [Parameter] 22 | public TableDesign Design { get; set; } = TableDesign.TableNormal; 23 | 24 | [Parameter] 25 | public AutoFit AutoFitStyle { get; set; } = AutoFit.Contents; 26 | 27 | [Parameter] 28 | public string PostContent { get; set; } 29 | 30 | [Parameter] 31 | public string PreContent { get; set; } 32 | 33 | [Parameter] 34 | public SwitchParameter Show { get; set; } 35 | 36 | private int Count { get; set; } 37 | private Table DocumentTable { get; set; } 38 | private DocX WordDocument { get; set; } 39 | private Paragraph PreContentparagraph { get; set; } 40 | private Paragraph PostContentparagraph { get; set; } 41 | private string ResolvedPath { get; set; } 42 | protected override void BeginProcessing() 43 | { 44 | this.ResolvedPath = this.GetUnresolvedProviderPathFromPSPath(this.FilePath); 45 | 46 | if (!File.Exists(this.ResolvedPath)) 47 | { 48 | this.WordDocument = DocX.Create(this.ResolvedPath); 49 | } 50 | else 51 | { 52 | this.WordDocument = DocX.Load(this.ResolvedPath); 53 | } 54 | this.Count = 0; 55 | 56 | if (!string.IsNullOrEmpty(this.PreContent)) 57 | { 58 | this.PreContentparagraph = this.WordDocument.InsertParagraph(this.PreContent, false); 59 | } 60 | } 61 | 62 | protected override void ProcessRecord() 63 | { 64 | 65 | var header = this.InputObject[0].Properties; 66 | 67 | try 68 | { 69 | if (this.Count == 0) 70 | { 71 | this.DocumentTable = this.WordDocument.InsertTable(1, header.Count()); 72 | this.DocumentTable.Design = this.Design; 73 | this.DocumentTable.AutoFit = this.AutoFitStyle; 74 | 75 | 76 | var column = 0; 77 | var row = 0; 78 | foreach (var name in header) 79 | { 80 | this.DocumentTable.Rows[row].Cells[column].Paragraphs[0].Append(name.Name); 81 | column++; 82 | } 83 | this.Count++; 84 | } 85 | 86 | var columnIndex = 0; 87 | Row newRow = this.DocumentTable.InsertRow(); 88 | 89 | 90 | foreach (var name in header) 91 | { 92 | try 93 | { 94 | int i = 0; 95 | string appendData; 96 | if (this.InputObject.Length < 0) 97 | { 98 | appendData = this.InputObject[i++].Properties[name.Name].Value.ToString(); 99 | } 100 | else 101 | { 102 | appendData = this.InputObject[0].Properties[name.Name].Value.ToString(); 103 | } 104 | newRow.Cells[columnIndex++].Paragraphs[0].Append(appendData); 105 | this.DocumentTable.Rows.Add(newRow); 106 | } 107 | catch (Exception exception) 108 | { 109 | this.WriteError(new ErrorRecord(exception, exception.HResult.ToString(), ErrorCategory.WriteError, exception)); 110 | } 111 | } 112 | } 113 | catch (Exception exception) 114 | { 115 | this.WriteError(new ErrorRecord(exception, exception.HResult.ToString(), ErrorCategory.WriteError, exception)); 116 | } 117 | } 118 | 119 | protected override void EndProcessing() 120 | { 121 | try 122 | { 123 | if (!string.IsNullOrEmpty(this.PostContent)) 124 | { 125 | this.PostContentparagraph = this.WordDocument.InsertParagraph(this.PostContent, false); 126 | } 127 | using (this.WordDocument) 128 | { 129 | this.WordDocument.Save(); 130 | } 131 | } 132 | catch (Exception exception) 133 | { 134 | this.WriteError(new ErrorRecord(exception, exception.HResult.ToString(), ErrorCategory.WriteError, exception)); 135 | } 136 | if (this.Show.IsPresent) 137 | { 138 | 139 | Process.Start(this.ResolvedPath); 140 | } 141 | } 142 | } 143 | } -------------------------------------------------------------------------------- /PSWord/AddWordTableofContents.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Management.Automation; 7 | using Novacode; 8 | using System.IO; 9 | using System.Diagnostics; 10 | using System.Drawing; 11 | 12 | 13 | namespace PSWord 14 | { 15 | using System.Runtime.CompilerServices; 16 | 17 | [Cmdlet(VerbsCommon.Add, "WordTableofContents", DefaultParameterSetName = "Default")] 18 | public class AddWordTableofContents : PSCmdlet 19 | { 20 | [Parameter(Position = 0, Mandatory = true)] 21 | public string FilePath { get; set; } 22 | 23 | [Parameter] 24 | public string Title { get; set; } 25 | 26 | [Parameter] 27 | public TableOfContentsSwitches TableSwitch { get; set; } = TableOfContentsSwitches.None; 28 | 29 | [Parameter] 30 | public SwitchParameter Show { get; set; } 31 | private DocX wordDocument { get; set; } 32 | private string resolvedPath { get; set; } 33 | 34 | protected override void BeginProcessing() 35 | { 36 | this.resolvedPath = this.GetUnresolvedProviderPathFromPSPath(this.FilePath); 37 | 38 | if (!File.Exists(this.resolvedPath)) 39 | { 40 | this.wordDocument = DocX.Create(this.resolvedPath); 41 | } 42 | else 43 | { 44 | this.wordDocument = DocX.Load(this.resolvedPath); 45 | } 46 | } 47 | 48 | protected override void ProcessRecord() 49 | { 50 | this.wordDocument.InsertTableOfContents(this.Title, this.TableSwitch, "Title"); 51 | } 52 | protected override void EndProcessing() 53 | { 54 | try 55 | { 56 | using (this.wordDocument) 57 | { 58 | this.wordDocument.Save(); 59 | } 60 | } 61 | catch (Exception exception) 62 | { 63 | this.WriteError(new ErrorRecord(exception, exception.HResult.ToString(), ErrorCategory.WriteError, exception)); 64 | } 65 | if (this.Show.IsPresent) 66 | { 67 | Process.Start(this.resolvedPath); 68 | } 69 | } 70 | } 71 | } 72 | 73 | -------------------------------------------------------------------------------- /PSWord/AddWordText.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Management.Automation; 7 | using Novacode; 8 | using System.IO; 9 | using System.Diagnostics; 10 | using System.Drawing; 11 | 12 | 13 | namespace PSWord 14 | { 15 | using System.Runtime.CompilerServices; 16 | 17 | [Cmdlet(VerbsCommon.Add, "WordText", DefaultParameterSetName = "Default")] 18 | public class AddWordText : PSCmdlet 19 | { 20 | [Parameter(Position = 0, Mandatory =true, ParameterSetName = "Default")] 21 | [Parameter(Position = 0, Mandatory = true, ParameterSetName = "Heading")] 22 | public string FilePath { get; set; } 23 | 24 | [Parameter(Position = 1, ValueFromPipeline =true, ParameterSetName = "Heading")] 25 | [Parameter(Position = 1, ValueFromPipeline = true, ParameterSetName = "Default")] 26 | public String[] Text { get; set; } 27 | 28 | [Parameter(HelpMessage = "Please choose a font size between 4 and 72", ParameterSetName = "Default")] 29 | [ValidateRange(4, 72)] 30 | public Int32 Size { get; set; } 31 | 32 | [Parameter(ParameterSetName = "Default")] 33 | public SwitchParameter Bold { get; set; } 34 | 35 | [Parameter(ParameterSetName = "Default")] 36 | public SwitchParameter Italic { get; set; } 37 | 38 | [Parameter] 39 | public SwitchParameter Show { get; set; } 40 | 41 | [Parameter(ParameterSetName = "Default")] 42 | public FontFamily FontFamily { get; set; } 43 | 44 | [Parameter(ParameterSetName = "Default")] 45 | public KnownColor FontColor { get; set; } 46 | 47 | [Parameter(ParameterSetName = "Heading")] 48 | public PSWord.HeadingType Heading { get; set; } 49 | 50 | [Parameter] 51 | public SwitchParameter NoNewLine { get; set;} 52 | private DocX wordDocument { get; set; } 53 | private string resolvedPath { get; set; } 54 | private Formatting formatting { get; set; } 55 | protected override void BeginProcessing() 56 | { 57 | this.resolvedPath = this.GetUnresolvedProviderPathFromPSPath(this.FilePath); 58 | 59 | if (!File.Exists(this.resolvedPath)) 60 | { 61 | this.wordDocument = DocX.Create(this.resolvedPath); 62 | } 63 | else 64 | { 65 | this.wordDocument = DocX.Load(this.resolvedPath); 66 | } 67 | } 68 | 69 | protected override void ProcessRecord() 70 | { 71 | if (!(ParameterSetName == "Heading")) 72 | { 73 | formatting = new Formatting 74 | { 75 | FontFamily = this.FontFamily, 76 | Size = this.Size 77 | }; 78 | 79 | if (this.Bold.IsPresent) 80 | { 81 | formatting.Bold = true; 82 | } 83 | if (this.Italic.IsPresent) 84 | { 85 | formatting.Italic = true; 86 | } 87 | 88 | formatting.FontColor = Color.FromKnownColor(this.FontColor); 89 | } 90 | if (this.Text.Length > 0) 91 | { 92 | for (int i = 0; i < this.Text.Length; i++) 93 | { 94 | if (this.NoNewLine.IsPresent) 95 | { 96 | if (this.Bold.IsPresent) 97 | { 98 | if (this.Italic.IsPresent) 99 | { 100 | var p = this.wordDocument.Paragraphs[this.wordDocument.Paragraphs.Count - 1].Append(this.Text[i]).Bold().Italic(); 101 | } 102 | else 103 | { 104 | var p = this.wordDocument.Paragraphs[this.wordDocument.Paragraphs.Count - 1].Append(this.Text[i]).Bold(); 105 | } 106 | } 107 | else 108 | { 109 | var p = this.wordDocument.Paragraphs[this.wordDocument.Paragraphs.Count - 1].Append(this.Text[i]); 110 | } 111 | if (this.Italic.IsPresent) 112 | { 113 | if (this.Bold.IsPresent) 114 | { 115 | var p = this.wordDocument.Paragraphs[this.wordDocument.Paragraphs.Count - 1].Append(this.Text[i]).Bold().Italic(); 116 | } 117 | else 118 | { 119 | var p = this.wordDocument.Paragraphs[this.wordDocument.Paragraphs.Count - 1].Append(this.Text[i]).Italic(); 120 | } 121 | } 122 | else 123 | { 124 | var p = this.wordDocument.Paragraphs[this.wordDocument.Paragraphs.Count - 1].Append(this.Text[i]); 125 | } 126 | 127 | } 128 | 129 | else 130 | { 131 | if (ParameterSetName == "Heading") 132 | { 133 | var p = this.wordDocument.InsertParagraph(this.Text[i]); 134 | p.StyleName = this.Heading.ToString(); 135 | } 136 | else 137 | { 138 | var p = this.wordDocument.InsertParagraph(this.Text[i], false, formatting); 139 | } 140 | 141 | } 142 | } 143 | } 144 | else 145 | { 146 | try 147 | { 148 | var p = this.wordDocument.InsertParagraph(this.Text[0], false, formatting); 149 | } 150 | catch (Exception exception) 151 | { 152 | this.WriteError(new ErrorRecord(exception, exception.HResult.ToString(), ErrorCategory.WriteError, exception)); 153 | } 154 | } 155 | } 156 | protected override void EndProcessing() 157 | { 158 | try 159 | { 160 | using (this.wordDocument) 161 | { 162 | this.wordDocument.Save(); 163 | } 164 | } 165 | catch (Exception exception) 166 | { 167 | this.WriteError(new ErrorRecord(exception, exception.HResult.ToString(), ErrorCategory.WriteError, exception)); 168 | } 169 | if (this.Show.IsPresent) 170 | { 171 | Process.Start(this.resolvedPath); 172 | } 173 | } 174 | } 175 | } 176 | 177 | -------------------------------------------------------------------------------- /PSWord/Enumerators.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace PSWord 8 | { 9 | using System.ComponentModel; 10 | 11 | public enum HeadingType 12 | { 13 | [Description("Heading1")] 14 | Heading1, 15 | 16 | [Description("Heading2")] 17 | Heading2, 18 | 19 | [Description("Heading3")] 20 | Heading3, 21 | 22 | [Description("Heading4")] 23 | Heading4, 24 | 25 | [Description("Heading5")] 26 | Heading5, 27 | 28 | [Description("Heading6")] 29 | Heading6, 30 | 31 | [Description("Heading7")] 32 | Heading7, 33 | 34 | [Description("Heading8")] 35 | Heading8, 36 | 37 | [Description("Heading9")] 38 | Heading9, 39 | 40 | [Description("NoSpacing")] 41 | NoSpacing, 42 | 43 | [Description("Title")] 44 | Title, 45 | 46 | [Description("Subtitle")] 47 | Subtitle, 48 | 49 | [Description("Quote")] 50 | Quote, 51 | 52 | [Description("IntenseQuote")] 53 | IntenseQuote, 54 | 55 | [Description("Emphasis")] 56 | Emphasis, 57 | 58 | [Description("IntenseEmphasis")] 59 | IntenseEmphasis, 60 | 61 | [Description("Strong")] 62 | Strong, 63 | 64 | [Description("ListParagraph")] 65 | ListParagraph, 66 | 67 | [Description("SubtleReference")] 68 | SubtleReference, 69 | 70 | [Description("IntenseReference")] 71 | IntenseReference, 72 | 73 | [Description("BookTitle")] 74 | BookTitle 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /PSWord/GetWordDocument.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Management.Automation; 7 | using System.IO; 8 | using Novacode; 9 | 10 | namespace PSWord 11 | { 12 | [Cmdlet(VerbsCommon.Get, "WordDocument")] 13 | public class GetWordDocument : PSCmdlet 14 | { 15 | [Parameter] 16 | public string FilePath { get; set; } 17 | 18 | private string resolvedPath { get; set; } 19 | 20 | private DocX wordDocument { get; set; } 21 | 22 | protected override void BeginProcessing() 23 | { 24 | this.resolvedPath = this.GetUnresolvedProviderPathFromPSPath(this.FilePath); 25 | if (File.Exists(this.resolvedPath)) 26 | { 27 | this.wordDocument = DocX.Load(this.resolvedPath); 28 | 29 | } 30 | } 31 | 32 | protected override void ProcessRecord() 33 | { 34 | this.WriteObject( 35 | new 36 | { 37 | DocumentName = Path.GetFileName(this.resolvedPath), 38 | Paragraphs = this.wordDocument.Paragraphs.Count, 39 | Tables = this.wordDocument.Tables.Count, 40 | Images = this.wordDocument.Images.Count, 41 | IsProtected = this.wordDocument.isProtected 42 | }); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /PSWord/GetWordParagraph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Management.Automation; 7 | using System.IO; 8 | using Novacode; 9 | 10 | namespace PSWord 11 | { 12 | 13 | 14 | [Cmdlet(VerbsCommon.Get, "WordParagraph")] 15 | public class GetWordParagraph : PSCmdlet 16 | { 17 | [Parameter] 18 | public string FilePath { get; set; } 19 | 20 | private string resolvedPath { get; set; } 21 | private DocX wordDocument { get; set; } 22 | protected override void BeginProcessing() 23 | { 24 | this.resolvedPath = this.GetUnresolvedProviderPathFromPSPath(this.FilePath); 25 | if (File.Exists(this.resolvedPath)) 26 | { 27 | this.wordDocument = DocX.Load(this.resolvedPath); 28 | } 29 | } 30 | protected override void ProcessRecord() 31 | { 32 | for (var i = 0; i < this.wordDocument.Paragraphs.Count; i++) 33 | { 34 | this.WriteObject(new 35 | { 36 | Index = i, 37 | Text = this.wordDocument.Paragraphs[i].Text, 38 | StyleName = this.wordDocument.Paragraphs[i].StyleName 39 | }); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /PSWord/GetWordTable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Management.Automation; 7 | using System.IO; 8 | using Novacode; 9 | using System.Diagnostics; 10 | 11 | namespace PSWord 12 | { 13 | 14 | 15 | [Cmdlet(VerbsCommon.Get, "WordTable")] 16 | public class GetWordTable : PSCmdlet 17 | { 18 | [Parameter] 19 | public string FilePath { get; set; } 20 | 21 | [Parameter] 22 | public EditRestrictions EditRestrictions { get; set; } 23 | 24 | [Parameter] 25 | public string DocumentPassword { get; set; } 26 | 27 | [Parameter] 28 | public SwitchParameter Show { get; set; } 29 | private string resolvedPath { get; set; } 30 | private DocX wordDocument { get; set; } 31 | protected override void BeginProcessing() 32 | { 33 | this.resolvedPath = this.GetUnresolvedProviderPathFromPSPath(this.FilePath); 34 | if (File.Exists(this.resolvedPath)) 35 | { 36 | this.wordDocument = DocX.Load(this.resolvedPath); 37 | } 38 | } 39 | protected override void ProcessRecord() 40 | { 41 | 42 | } 43 | protected override void EndProcessing() 44 | { 45 | try 46 | { 47 | using (this.wordDocument) 48 | { 49 | this.wordDocument.SaveAs(this.resolvedPath); 50 | } 51 | } 52 | catch (Exception exception) 53 | { 54 | this.WriteError(new ErrorRecord(exception, exception.HResult.ToString(), ErrorCategory.WriteError, exception)); 55 | } 56 | if (this.Show.IsPresent) 57 | { 58 | 59 | Process.Start(this.resolvedPath); 60 | } 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /PSWord/NewWordFormatting.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Novacode; 7 | 8 | namespace PSWord 9 | { 10 | using System.Drawing; 11 | using System.Management.Automation; 12 | 13 | [Cmdlet(VerbsCommon.New, "WordFormatting")] 14 | class NewWordFormatting : PSCmdlet 15 | { 16 | [Parameter] 17 | public CapsStyle CapsStyle { get; set; } 18 | 19 | [Parameter] 20 | public SwitchParameter Bold { get; set; } 21 | 22 | [Parameter] 23 | public SwitchParameter Italic { get; set; } 24 | 25 | [Parameter] 26 | public FontFamily FontFamily { get; set; } 27 | 28 | [Parameter] 29 | public KnownColor FontColor { get; set; } 30 | 31 | [Parameter] 32 | public SwitchParameter Hidden { get; set; } 33 | 34 | [Parameter] 35 | public Highlight Highlight { get; set; } 36 | 37 | [Parameter] 38 | public Misc Misc { get; set; } 39 | 40 | [Parameter(Mandatory = true)] 41 | public int? Size { get; set; } 42 | 43 | [Parameter] 44 | public double Spacing { get; set; } 45 | 46 | [Parameter] 47 | public StrikeThrough StrikeThrough { get; set; } 48 | 49 | [Parameter] 50 | public UnderlineStyle UnderlineStyle { get; set; } 51 | 52 | [Parameter] 53 | public KnownColor UnderlineColor { get; set; } 54 | private Formatting formatting { get; set; } 55 | 56 | protected override void BeginProcessing() 57 | { 58 | this.formatting = new Formatting 59 | { 60 | Size = this.Size 61 | }; 62 | 63 | } 64 | 65 | protected override void ProcessRecord() 66 | { 67 | this.formatting.CapsStyle = this.CapsStyle; 68 | if (this.Bold.IsPresent) 69 | { 70 | this.formatting.Bold = true; 71 | } 72 | if (this.Italic.IsPresent) 73 | { 74 | this.formatting.Italic = true; 75 | } 76 | this.formatting.FontFamily = this.FontFamily; 77 | this.formatting.FontColor = Color.FromKnownColor(this.FontColor); 78 | if (this.Hidden.IsPresent) 79 | { 80 | this.formatting.Hidden = true; 81 | } 82 | if (!string.IsNullOrEmpty(this.Highlight.ToString())) 83 | { 84 | this.formatting.Highlight = this.Highlight; 85 | } 86 | if (!String.IsNullOrEmpty(this.Misc.ToString())) 87 | { 88 | this.formatting.Misc = this.Misc; 89 | } 90 | if (!String.IsNullOrEmpty(this.Spacing.ToString())) 91 | { 92 | this.formatting.Spacing = this.Spacing; 93 | } 94 | 95 | if (!String.IsNullOrEmpty(this.StrikeThrough.ToString())) 96 | { 97 | this.formatting.StrikeThrough = this.StrikeThrough; 98 | } 99 | 100 | if (!String.IsNullOrEmpty(this.UnderlineStyle.ToString())) 101 | { 102 | this.formatting.UnderlineStyle = this.UnderlineStyle; 103 | } 104 | 105 | if (!String.IsNullOrEmpty(this.UnderlineColor.ToString())) 106 | { 107 | this.formatting.UnderlineColor = Color.FromKnownColor(this.UnderlineColor); 108 | } 109 | 110 | this.WriteObject(this.formatting); 111 | } 112 | } 113 | } -------------------------------------------------------------------------------- /PSWord/NewWordList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Management.Automation; 7 | using System.IO; 8 | using Novacode; 9 | using System.Diagnostics; 10 | 11 | namespace PSWord 12 | { 13 | 14 | 15 | [Cmdlet(VerbsCommon.New, "WordList")] 16 | public class NewWordList : PSCmdlet 17 | { 18 | [Parameter] 19 | public string FilePath { get; set; } 20 | 21 | [Parameter] 22 | public string[] Items { get; set; } 23 | 24 | [Parameter] 25 | public ListItemType ListItemType { get; set; } 26 | 27 | 28 | private string resolvedPath { get; set; } 29 | private DocX wordDocument { get; set; } 30 | protected override void BeginProcessing() 31 | { 32 | this.resolvedPath = this.GetUnresolvedProviderPathFromPSPath(this.FilePath); 33 | if (File.Exists(this.resolvedPath)) 34 | { 35 | this.wordDocument = DocX.Load(this.resolvedPath); 36 | } 37 | } 38 | protected override void ProcessRecord() 39 | { 40 | var numberedList = this.wordDocument.AddList(this.Items[0], 0, this.ListItemType); 41 | 42 | for (var i = 1; i < this.Items.Length; i++) 43 | { 44 | this.wordDocument.AddListItem(numberedList, this.Items[i]); 45 | } 46 | 47 | this.WriteObject(numberedList); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /PSWord/PSWORD.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guidooliveira/PSWord/a11c89f6c713c272e04bd8700d9c2598560f7bd2/PSWord/PSWORD.png -------------------------------------------------------------------------------- /PSWord/PSWord.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {D2640933-09D8-4CE2-AC2B-03DEF1B82B1A} 8 | Library 9 | Properties 10 | PSWord 11 | PSWord 12 | v4.5 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | false 28 | ..\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | False 36 | E:\Downloads\DocX.dll 37 | 38 | 39 | 40 | 41 | 42 | packages\System.Management.Automation.6.1.7601.17515\lib\net45\System.Management.Automation.dll 43 | False 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | Always 73 | 74 | 75 | 76 | 77 | Always 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 98 | -------------------------------------------------------------------------------- /PSWord/PSWord.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guidooliveira/PSWord/a11c89f6c713c272e04bd8700d9c2598560f7bd2/PSWord/PSWord.psd1 -------------------------------------------------------------------------------- /PSWord/PSWord.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PSWord", "PSWord.csproj", "{D2640933-09D8-4CE2-AC2B-03DEF1B82B1A}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PSWord.Tests", "..\PSWord.Tests\PSWord.Tests.csproj", "{FA254AF9-1F83-403A-862D-55A39C23BE56}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {D2640933-09D8-4CE2-AC2B-03DEF1B82B1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {D2640933-09D8-4CE2-AC2B-03DEF1B82B1A}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {D2640933-09D8-4CE2-AC2B-03DEF1B82B1A}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {D2640933-09D8-4CE2-AC2B-03DEF1B82B1A}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {FA254AF9-1F83-403A-862D-55A39C23BE56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {FA254AF9-1F83-403A-862D-55A39C23BE56}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {FA254AF9-1F83-403A-862D-55A39C23BE56}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {FA254AF9-1F83-403A-862D-55A39C23BE56}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /PSWord/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("PSWord")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("PSWord")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("d2640933-09d8-4ce2-ac2b-03def1b82b1a")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | [assembly: InternalsVisibleTo("PSWord.Tests")] 38 | [assembly: InternalsVisibleTo("PSWord.Explorables")] 39 | 40 | -------------------------------------------------------------------------------- /PSWord/ProtectWordDocument.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Management.Automation; 7 | using System.IO; 8 | using Novacode; 9 | using System.Diagnostics; 10 | 11 | namespace PSWord 12 | { 13 | [Cmdlet(VerbsSecurity.Protect, "WordDocument")] 14 | public class ProtectWordDocument : PSCmdlet 15 | { 16 | [Parameter] 17 | public string FilePath { get; set; } 18 | 19 | [Parameter] 20 | public EditRestrictions EditRestrictions { get; set; } 21 | 22 | [Parameter] 23 | public string DocumentPassword { get; set; } 24 | 25 | [Parameter] 26 | public SwitchParameter Show { get; set; } 27 | private string resolvedPath { get; set; } 28 | private DocX wordDocument { get; set; } 29 | protected override void BeginProcessing() 30 | { 31 | this.resolvedPath = this.GetUnresolvedProviderPathFromPSPath(this.FilePath); 32 | if (File.Exists(this.resolvedPath)) 33 | { 34 | this.wordDocument = DocX.Load(this.resolvedPath); 35 | } 36 | } 37 | protected override void ProcessRecord() 38 | { 39 | this.wordDocument.AddProtection(this.EditRestrictions, this.DocumentPassword); 40 | } 41 | protected override void EndProcessing() 42 | { 43 | try 44 | { 45 | using (this.wordDocument) 46 | { 47 | this.wordDocument.SaveAs(this.resolvedPath); 48 | } 49 | } 50 | catch (Exception exception) 51 | { 52 | this.WriteError(new ErrorRecord(exception, exception.HResult.ToString(), ErrorCategory.WriteError, exception)); 53 | } 54 | if (this.Show.IsPresent) 55 | { 56 | Process.Start(this.resolvedPath); 57 | } 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /PSWord/README.md: -------------------------------------------------------------------------------- 1 | PSWord 2 | ==================== 3 | 4 | Powershell module for creation and manipulation of Docx files without needing Microsoft Office Installed. This module will enable you to automate project documentations into word Directly. 5 | 6 | 7 | 8 | Usage 9 | ----- 10 | Assuming you've installed the module somewhere in your module path, just import the module in your profile, e.g.: 11 | 12 | ```powershell 13 | Import-Module PSWord 14 | ``` 15 | 16 | Installing 17 | ---------- 18 | If you have PowerShell V5, or have installed [PowerShellGet](https://www.microsoft.com/en-us/download/details.aspx?id=49186) for V3, you can install right away with: 19 | 20 | ```powershell 21 | Install-Module -Name PSWord 22 | ``` 23 | 24 | Alternatively, you can install in your personal modules folder (e.g. ~\Documents\WindowsPowerShell\Modules), iwith: 25 | 26 | ```powershell 27 | iex (new-object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/guidooliveira/PSWord/master/install.ps1') 28 | ``` 29 | 30 | If you want to install elsewhere, you can download Install.ps1 (using the URL above) and run it, passing in the directory you want to install. 31 | 32 | # Issues / Feedback 33 | 34 | For any issues or feedback related to this module, please register for GitHub, and post your inquiry to this project's issue tracker. -------------------------------------------------------------------------------- /PSWord/SetWordListItem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Management.Automation; 7 | using System.IO; 8 | using Novacode; 9 | using System.Diagnostics; 10 | 11 | namespace PSWord 12 | { 13 | [Cmdlet(VerbsCommon.Set, "WordListItem")] 14 | public class SetWordListItem : PSCmdlet 15 | { 16 | [Parameter] 17 | public string FilePath { get; set; } 18 | 19 | [Parameter] 20 | public Novacode.List List { get; set; } 21 | 22 | [Parameter] 23 | public string Text { get; set; } 24 | 25 | [Parameter] 26 | public int? ParentIndex { get; set; } 27 | 28 | private string resolvedPath { get; set; } 29 | private DocX wordDocument { get; set; } 30 | protected override void BeginProcessing() 31 | { 32 | this.resolvedPath = this.GetUnresolvedProviderPathFromPSPath(this.FilePath); 33 | if (File.Exists(this.resolvedPath)) 34 | { 35 | this.wordDocument = DocX.Load(this.resolvedPath); 36 | } 37 | } 38 | protected override void ProcessRecord() 39 | { 40 | if (this.ParentIndex == null) 41 | { 42 | this.wordDocument.AddListItem(this.List,this.Text); 43 | } 44 | else 45 | { 46 | this.wordDocument.AddListItem(this.List, this.Text, (int)this.ParentIndex); 47 | } 48 | 49 | this.WriteObject(this.List); 50 | } 51 | 52 | } 53 | } -------------------------------------------------------------------------------- /PSWord/UpdateWordText.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Management.Automation; 7 | using Novacode; 8 | using System.IO; 9 | using System.Diagnostics; 10 | using System.Drawing; 11 | using System.Text.RegularExpressions; 12 | 13 | namespace PSWord 14 | { 15 | 16 | 17 | [Cmdlet(VerbsData.Update, "WordText")] 18 | public class UpdateWordText : PSCmdlet 19 | { 20 | [Parameter(Position = 0, Mandatory = true)] 21 | public string FilePath { get; set; } 22 | 23 | [Parameter(Position = 1)] 24 | public String ReplacingText { get; set; } 25 | 26 | [Parameter(Position = 2, ValueFromPipeline = true)] 27 | public String NewText { get; set; } 28 | 29 | [Parameter] 30 | public SwitchParameter TrackChanges { get; set; } 31 | 32 | [Parameter] 33 | public SwitchParameter Show { get; set; } 34 | 35 | private DocX wordDocument { get; set; } 36 | private string resolvedPath { get; set; } 37 | 38 | protected override void BeginProcessing() 39 | { 40 | this.resolvedPath = this.GetUnresolvedProviderPathFromPSPath(this.FilePath); 41 | 42 | if (!File.Exists(this.resolvedPath)) 43 | { 44 | this.wordDocument = DocX.Create(this.resolvedPath); 45 | } 46 | else 47 | { 48 | this.wordDocument = DocX.Load(this.resolvedPath); 49 | } 50 | } 51 | 52 | protected override void ProcessRecord() 53 | { 54 | try 55 | { 56 | if (this.TrackChanges.IsPresent) 57 | { 58 | this.wordDocument.ReplaceText(this.ReplacingText, this.NewText, true, RegexOptions.IgnoreCase); 59 | } 60 | else 61 | { 62 | this.wordDocument.ReplaceText(this.ReplacingText, this.NewText, false, RegexOptions.IgnoreCase); 63 | } 64 | 65 | this.wordDocument.Save(); 66 | } 67 | catch (Exception exception) 68 | { 69 | this.WriteError(new ErrorRecord(exception, exception.HResult.ToString(), ErrorCategory.WriteError, exception)); 70 | } 71 | } 72 | protected override void EndProcessing() 73 | { 74 | try 75 | { 76 | using (this.wordDocument) 77 | { 78 | this.wordDocument.Save(); 79 | } 80 | } 81 | catch (Exception exception) 82 | { 83 | this.WriteError(new ErrorRecord(exception, exception.HResult.ToString(), ErrorCategory.WriteError, exception)); 84 | } 85 | if (this.Show.IsPresent) 86 | { 87 | Process.Start(this.resolvedPath); 88 | } 89 | } 90 | } 91 | } 92 | 93 | -------------------------------------------------------------------------------- /PSWord/appveyor.yaml: -------------------------------------------------------------------------------- 1 | version: 0.2.{build} 2 | platform: Any CPU 3 | before_build: 4 | - cmd: nuget restore 5 | build: 6 | verbosity: detailed 7 | -------------------------------------------------------------------------------- /PSWord/en-US/PSWord.dll-Help.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 11 | 12 | 13 | Add-WordPicture 14 | 15 | Inserts a Picture file into the document. 16 | 17 | 18 | 19 | 20 | Add 21 | WordPicture 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | FilePath 34 | 35 | Path for the Word Document File. 36 | 37 | String 38 | 39 | String 40 | 41 | 42 | 43 | 44 | 45 | 46 | PicturePath 47 | 48 | Path of the picture to be added into the document. 49 | 50 | String 51 | 52 | String 53 | 54 | 55 | 56 | 57 | 58 | 59 | Show 60 | 61 | Opens the Word Document after the command has run. 62 | 63 | SwitchParameter 64 | 65 | SwitchParameter 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | System.String 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | System.Object 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | -------------------------- EXAMPLE 1 -------------------------- 102 | 103 | PS C:\> 104 | 105 | Add-WordPicture -FilePath .\example.docx -PicturePath .\image.png -Show 106 | 107 | Simple adition of a image into the example.docx file 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | Add-WordTable 116 | 117 | 118 | 119 | 120 | 121 | 122 | Add 123 | WordTable 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | Add-WordTable 133 | 134 | FilePath 135 | 136 | Path for the Word Document File. 137 | 138 | String 139 | 140 | 141 | 142 | 143 | InputObject 144 | 145 | PSObject to be parsed into a Table in the document. 146 | 147 | PSObject[] 148 | 149 | 150 | 151 | 152 | Design 153 | 154 | Built-in Table designs for the converted table 155 | 156 | TableDesign 157 | 158 | 159 | 160 | 161 | Show 162 | 163 | Opens the Word Document after the command has run. 164 | 165 | SwitchParameter 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | FilePath 175 | 176 | Path for the Word Document File. 177 | 178 | String 179 | 180 | String 181 | 182 | 183 | 184 | 185 | 186 | 187 | InputObject 188 | 189 | PSObject to be parsed into a Table in the document. 190 | 191 | PSObject[] 192 | 193 | PSObject[] 194 | 195 | 196 | 197 | 198 | 199 | 200 | Design 201 | 202 | Built-in Table designs for the converted table 203 | 204 | TableDesign 205 | 206 | TableDesign 207 | 208 | 209 | 210 | 211 | 212 | 213 | Show 214 | 215 | Opens the Word Document after the command has run. 216 | 217 | SwitchParameter 218 | 219 | SwitchParameter 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | System.Management.Automation.PSObject[] 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | System.Object 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | -------------------------- EXAMPLE 1 -------------------------- 256 | 257 | PS C:\> 258 | 259 | Get-Process | Select-Object -Property Name, Id, WorkingSet | Add-WordTable -FilePath .\example.docx -Design ColorfulGrid -Show 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | Add-WordText 271 | 272 | 273 | 274 | 275 | 276 | 277 | Add 278 | WordText 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | Add-WordText 288 | 289 | FilePath 290 | 291 | Path for the Word Document File. 292 | 293 | String 294 | 295 | 296 | 297 | 298 | Text 299 | 300 | Text to be added to the document 301 | 302 | String[] 303 | 304 | 305 | 306 | 307 | Size 308 | 309 | 310 | 311 | Int32 312 | 313 | 314 | Bold 315 | 316 | 317 | 318 | SwitchParameter 319 | 320 | 321 | Italic 322 | 323 | 324 | 325 | SwitchParameter 326 | 327 | 328 | Show 329 | 330 | Opens the Word Document after the command has run. 331 | 332 | SwitchParameter 333 | 334 | 335 | 336 | 337 | FontFamily 338 | 339 | 340 | 341 | FontFamily 342 | 343 | 344 | FontColor 345 | 346 | 347 | 348 | KnownColor 349 | 350 | 351 | 352 | 353 | 354 | 355 | FilePath 356 | 357 | Path for the Word Document File. 358 | 359 | String 360 | 361 | String 362 | 363 | 364 | 365 | 366 | 367 | 368 | Text 369 | 370 | Text to be added to the document 371 | 372 | String[] 373 | 374 | String[] 375 | 376 | 377 | 378 | 379 | 380 | 381 | Size 382 | 383 | 384 | 385 | Int32 386 | 387 | Int32 388 | 389 | 390 | 391 | 392 | 393 | Bold 394 | 395 | 396 | 397 | SwitchParameter 398 | 399 | SwitchParameter 400 | 401 | 402 | 403 | 404 | 405 | Italic 406 | 407 | 408 | 409 | SwitchParameter 410 | 411 | SwitchParameter 412 | 413 | 414 | 415 | 416 | 417 | Show 418 | 419 | Opens the Word Document after the command has run. 420 | 421 | SwitchParameter 422 | 423 | SwitchParameter 424 | 425 | 426 | 427 | 428 | 429 | 430 | FontFamily 431 | 432 | 433 | 434 | FontFamily 435 | 436 | FontFamily 437 | 438 | 439 | 440 | 441 | 442 | FontColor 443 | 444 | 445 | 446 | KnownColor 447 | 448 | KnownColor 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | System.String[] 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | System.Object 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | -------------------------- EXAMPLE 1 -------------------------- 484 | 485 | PS C:\> 486 | 487 | Add-WordText -FilePath .\example.docx -Text 'This is an example' -Size 12 -FontFamily 'Arial' -FontColor 'Cyan' -Bold -Show 488 | 489 | 490 | 491 | 492 | 493 | 494 | -------------------------- EXAMPLE 2 -------------------------- 495 | 496 | PS C:\> 497 | 498 | Add-WordText -FilePath .\example.docx -Text 'This is an example' -Size 18 -FontFamily 'Arial' -FontColor 'Blue' -Italic -Show 499 | 500 | 501 | 502 | 503 | 504 | 505 | -------------------------- EXAMPLE 3 -------------------------- 506 | 507 | PS C:\> 508 | 509 | Add-WordText -FilePath .\example.docx -Text 'This is an example' -Size 12 -FontFamily 'Verdana' -FontColor 'Red' -Bold -Italic -Show 510 | 511 | 512 | 513 | 514 | 515 | 516 | -------------------------- EXAMPLE 4 -------------------------- 517 | 518 | PS C:\> 519 | 520 | Add-WordText -FilePath .\example.docx -Text 'This is an example' -Size 14 -FontFamily 'Times New Roman' -FontColor 'Black' -Show 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | Update-WordText 532 | 533 | Replaces a given string within the Word Document 534 | 535 | 536 | 537 | 538 | Update 539 | WordText 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | Update-WordText 549 | 550 | FilePath 551 | 552 | Path for the Word Document File. 553 | 554 | String 555 | 556 | 557 | 558 | 559 | ReplacingText 560 | 561 | Text you wish to replace 562 | 563 | String 564 | 565 | 566 | 567 | 568 | NewText 569 | 570 | New Text to be placed 571 | 572 | String 573 | 574 | 575 | 576 | 577 | TrackChanges 578 | 579 | Track changes for further revision 580 | 581 | SwitchParameter 582 | 583 | 584 | 585 | 586 | Show 587 | 588 | Opens the Word Document after the command has run. 589 | 590 | SwitchParameter 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | FilePath 600 | 601 | Path for the Word Document File. 602 | 603 | String 604 | 605 | String 606 | 607 | 608 | 609 | 610 | 611 | 612 | ReplacingText 613 | 614 | Text you wish to replace 615 | 616 | String 617 | 618 | String 619 | 620 | 621 | 622 | 623 | 624 | 625 | NewText 626 | 627 | New Text to be placed 628 | 629 | String 630 | 631 | String 632 | 633 | 634 | 635 | 636 | 637 | 638 | TrackChanges 639 | 640 | Track changes for further revision 641 | 642 | SwitchParameter 643 | 644 | SwitchParameter 645 | 646 | 647 | 648 | 649 | 650 | 651 | Show 652 | 653 | Opens the Word Document after the command has run. 654 | 655 | SwitchParameter 656 | 657 | SwitchParameter 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | System.String 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | System.Object 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | -------------------------- EXAMPLE 1 -------------------------- 694 | 695 | PS C:\> 696 | 697 | Update-WordText -FilePath .\example.docx -ReplacingText 'Guido' -NewText 'GuidoOliveira.com' -Show 698 | 699 | 700 | 701 | 702 | 703 | 704 | -------------------------- EXAMPLE 2 -------------------------- 705 | 706 | PS C:\> 707 | 708 | Update-WordText -FilePath .\example.docx -ReplacingText 'Guido' -NewText 'GuidoOliveira.com' -TrackChanges -Show 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | -------------------------------------------------------------------------------- /PSWord/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PSWord 2 | ==================== 3 | 4 | Powershell module for creation and manipulation of Docx files without needing Microsoft Office Installed. This module will enable you to automate project documentations into word Directly. 5 | 6 | [![Build status](https://ci.appveyor.com/api/projects/status/vuacqoejrkw534v8?svg=true)](https://ci.appveyor.com/project/guidooliveira/psword) 7 | 8 | Usage 9 | ----- 10 | Assuming you've installed the module somewhere in your module path, just import the module in your profile, e.g.: 11 | 12 | ```powershell 13 | Import-Module PSWord 14 | ``` 15 | 16 | Installing 17 | ---------- 18 | If you have PowerShell V5, or have installed [PowerShellGet](https://www.microsoft.com/en-us/download/details.aspx?id=49186) for V3, you can install right away with: 19 | 20 | ```powershell 21 | Install-Module -Name PSWord 22 | ``` 23 | 24 | Alternatively, you can install in your personal modules folder (e.g. ~\Documents\WindowsPowerShell\Modules), iwith: 25 | 26 | ```powershell 27 | iex (new-object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/guidooliveira/PSWord/master/install.ps1') 28 | ``` 29 | 30 | If you want to install elsewhere, you can download Install.ps1 (using the URL above) and run it, passing in the directory you want to install. 31 | 32 | # Issues / Feedback 33 | 34 | For any issues or feedback related to this module, please register for GitHub, and post your inquiry to this project's issue tracker. 35 | -------------------------------------------------------------------------------- /Release/DocX.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guidooliveira/PSWord/a11c89f6c713c272e04bd8700d9c2598560f7bd2/Release/DocX.dll -------------------------------------------------------------------------------- /Release/PSWord.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guidooliveira/PSWord/a11c89f6c713c272e04bd8700d9c2598560f7bd2/Release/PSWord.dll -------------------------------------------------------------------------------- /Release/PSWord.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guidooliveira/PSWord/a11c89f6c713c272e04bd8700d9c2598560f7bd2/Release/PSWord.psd1 -------------------------------------------------------------------------------- /Release/en-US/PSWord.dll-Help.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 11 | 12 | 13 | Add-WordPicture 14 | 15 | Inserts a Picture file into the document. 16 | 17 | 18 | 19 | 20 | Add 21 | WordPicture 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | FilePath 34 | 35 | Path for the Word Document File. 36 | 37 | String 38 | 39 | String 40 | 41 | 42 | 43 | 44 | 45 | 46 | PicturePath 47 | 48 | Path of the picture to be added into the document. 49 | 50 | String 51 | 52 | String 53 | 54 | 55 | 56 | 57 | 58 | 59 | Show 60 | 61 | Opens the Word Document after the command has run. 62 | 63 | SwitchParameter 64 | 65 | SwitchParameter 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | System.String 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | System.Object 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | -------------------------- EXAMPLE 1 -------------------------- 102 | 103 | PS C:\> 104 | 105 | Add-WordPicture -FilePath .\example.docx -PicturePath .\image.png -Show 106 | 107 | Simple adition of a image into the example.docx file 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | Add-WordTable 116 | 117 | 118 | 119 | 120 | 121 | 122 | Add 123 | WordTable 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | Add-WordTable 133 | 134 | FilePath 135 | 136 | Path for the Word Document File. 137 | 138 | String 139 | 140 | 141 | 142 | 143 | InputObject 144 | 145 | PSObject to be parsed into a Table in the document. 146 | 147 | PSObject[] 148 | 149 | 150 | 151 | 152 | Design 153 | 154 | Built-in Table designs for the converted table 155 | 156 | TableDesign 157 | 158 | 159 | 160 | 161 | Show 162 | 163 | Opens the Word Document after the command has run. 164 | 165 | SwitchParameter 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | FilePath 175 | 176 | Path for the Word Document File. 177 | 178 | String 179 | 180 | String 181 | 182 | 183 | 184 | 185 | 186 | 187 | InputObject 188 | 189 | PSObject to be parsed into a Table in the document. 190 | 191 | PSObject[] 192 | 193 | PSObject[] 194 | 195 | 196 | 197 | 198 | 199 | 200 | Design 201 | 202 | Built-in Table designs for the converted table 203 | 204 | TableDesign 205 | 206 | TableDesign 207 | 208 | 209 | 210 | 211 | 212 | 213 | Show 214 | 215 | Opens the Word Document after the command has run. 216 | 217 | SwitchParameter 218 | 219 | SwitchParameter 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | System.Management.Automation.PSObject[] 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | System.Object 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | -------------------------- EXAMPLE 1 -------------------------- 256 | 257 | PS C:\> 258 | 259 | Get-Process | Select-Object -Property Name, Id, WorkingSet | Add-WordTable -FilePath .\example.docx -Design ColorfulGrid -Show 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | Add-WordText 271 | 272 | 273 | 274 | 275 | 276 | 277 | Add 278 | WordText 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | Add-WordText 288 | 289 | FilePath 290 | 291 | Path for the Word Document File. 292 | 293 | String 294 | 295 | 296 | 297 | 298 | Text 299 | 300 | Text to be added to the document 301 | 302 | String[] 303 | 304 | 305 | 306 | 307 | Size 308 | 309 | 310 | 311 | Int32 312 | 313 | 314 | Bold 315 | 316 | 317 | 318 | SwitchParameter 319 | 320 | 321 | Italic 322 | 323 | 324 | 325 | SwitchParameter 326 | 327 | 328 | Show 329 | 330 | Opens the Word Document after the command has run. 331 | 332 | SwitchParameter 333 | 334 | 335 | 336 | 337 | FontFamily 338 | 339 | 340 | 341 | FontFamily 342 | 343 | 344 | FontColor 345 | 346 | 347 | 348 | KnownColor 349 | 350 | 351 | 352 | 353 | 354 | 355 | FilePath 356 | 357 | Path for the Word Document File. 358 | 359 | String 360 | 361 | String 362 | 363 | 364 | 365 | 366 | 367 | 368 | Text 369 | 370 | Text to be added to the document 371 | 372 | String[] 373 | 374 | String[] 375 | 376 | 377 | 378 | 379 | 380 | 381 | Size 382 | 383 | 384 | 385 | Int32 386 | 387 | Int32 388 | 389 | 390 | 391 | 392 | 393 | Bold 394 | 395 | 396 | 397 | SwitchParameter 398 | 399 | SwitchParameter 400 | 401 | 402 | 403 | 404 | 405 | Italic 406 | 407 | 408 | 409 | SwitchParameter 410 | 411 | SwitchParameter 412 | 413 | 414 | 415 | 416 | 417 | Show 418 | 419 | Opens the Word Document after the command has run. 420 | 421 | SwitchParameter 422 | 423 | SwitchParameter 424 | 425 | 426 | 427 | 428 | 429 | 430 | FontFamily 431 | 432 | 433 | 434 | FontFamily 435 | 436 | FontFamily 437 | 438 | 439 | 440 | 441 | 442 | FontColor 443 | 444 | 445 | 446 | KnownColor 447 | 448 | KnownColor 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | System.String[] 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | System.Object 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | -------------------------- EXAMPLE 1 -------------------------- 484 | 485 | PS C:\> 486 | 487 | Add-WordText -FilePath .\example.docx -Text 'This is an example' -Size 12 -FontFamily 'Arial' -FontColor 'Cyan' -Bold -Show 488 | 489 | 490 | 491 | 492 | 493 | 494 | -------------------------- EXAMPLE 2 -------------------------- 495 | 496 | PS C:\> 497 | 498 | Add-WordText -FilePath .\example.docx -Text 'This is an example' -Size 18 -FontFamily 'Arial' -FontColor 'Blue' -Italic -Show 499 | 500 | 501 | 502 | 503 | 504 | 505 | -------------------------- EXAMPLE 3 -------------------------- 506 | 507 | PS C:\> 508 | 509 | Add-WordText -FilePath .\example.docx -Text 'This is an example' -Size 12 -FontFamily 'Verdana' -FontColor 'Red' -Bold -Italic -Show 510 | 511 | 512 | 513 | 514 | 515 | 516 | -------------------------- EXAMPLE 4 -------------------------- 517 | 518 | PS C:\> 519 | 520 | Add-WordText -FilePath .\example.docx -Text 'This is an example' -Size 14 -FontFamily 'Times New Roman' -FontColor 'Black' -Show 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | Update-WordText 532 | 533 | Replaces a given string within the Word Document 534 | 535 | 536 | 537 | 538 | Update 539 | WordText 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | Update-WordText 549 | 550 | FilePath 551 | 552 | Path for the Word Document File. 553 | 554 | String 555 | 556 | 557 | 558 | 559 | ReplacingText 560 | 561 | Text you wish to replace 562 | 563 | String 564 | 565 | 566 | 567 | 568 | NewText 569 | 570 | New Text to be placed 571 | 572 | String 573 | 574 | 575 | 576 | 577 | TrackChanges 578 | 579 | Track changes for further revision 580 | 581 | SwitchParameter 582 | 583 | 584 | 585 | 586 | Show 587 | 588 | Opens the Word Document after the command has run. 589 | 590 | SwitchParameter 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | FilePath 600 | 601 | Path for the Word Document File. 602 | 603 | String 604 | 605 | String 606 | 607 | 608 | 609 | 610 | 611 | 612 | ReplacingText 613 | 614 | Text you wish to replace 615 | 616 | String 617 | 618 | String 619 | 620 | 621 | 622 | 623 | 624 | 625 | NewText 626 | 627 | New Text to be placed 628 | 629 | String 630 | 631 | String 632 | 633 | 634 | 635 | 636 | 637 | 638 | TrackChanges 639 | 640 | Track changes for further revision 641 | 642 | SwitchParameter 643 | 644 | SwitchParameter 645 | 646 | 647 | 648 | 649 | 650 | 651 | Show 652 | 653 | Opens the Word Document after the command has run. 654 | 655 | SwitchParameter 656 | 657 | SwitchParameter 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | System.String 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | System.Object 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | -------------------------- EXAMPLE 1 -------------------------- 694 | 695 | PS C:\> 696 | 697 | Update-WordText -FilePath .\example.docx -ReplacingText 'Guido' -NewText 'GuidoOliveira.com' -Show 698 | 699 | 700 | 701 | 702 | 703 | 704 | -------------------------- EXAMPLE 2 -------------------------- 705 | 706 | PS C:\> 707 | 708 | Update-WordText -FilePath .\example.docx -ReplacingText 'Guido' -NewText 'GuidoOliveira.com' -TrackChanges -Show 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | -------------------------------------------------------------------------------- /install.ps1: -------------------------------------------------------------------------------- 1 | $fileList = @( 2 | 'DocX.dll', 3 | 'MadMilkman.Docx.dll', 4 | 'MadMilkman.Docx.xml', 5 | 'PSWord.dll', 6 | 'PSWord.psd1', 7 | 'en-US/PSWord.dll-Help.xml' 8 | ) 9 | 10 | 11 | $InstallDirectory = Join-Path -Path "$([Environment]::GetFolderPath('MyDocuments'))\WindowsPowershell\Modules" -ChildPath PSWord 12 | 13 | if (!(Test-Path $InstallDirectory)) 14 | { 15 | $null = mkdir $InstallDirectory 16 | $null = mkdir $InstallDirectory\en-US 17 | } 18 | 19 | $wc = new-object System.Net.WebClient 20 | $fileList | ForEach-Object { 21 | Try 22 | { 23 | $wc.DownloadFile("https://github.com/guidooliveira/PSWord/raw/master/Release/$_", "$installDirectory\$_") 24 | } 25 | catch 26 | { 27 | Write-Error -Message "Error Downloading $_" 28 | } 29 | } --------------------------------------------------------------------------------