PSWriteOffice

repository·main·Indexed 41 days ago

https://github.com/evotecit/pswriteoffice

A PowerShell-first document automation library providing cmdlets and a DSL for creating, converting, and searching documents in Office, PDF, iWork, OpenDocument, Email, Markdown, and CSV formats. Built on the OfficeIMO.* libraries, it allows for sophisticated document manipulation without requiring Microsoft Office to be installed.

Tokens
301.6K
Snippets
902
Records
1.3K
Agent score
50%

What's inside PSWriteOffice

  1. Overview of PSWriteOffice

    main

    PSWriteOffice is a PowerShell module designed to create, convert, read, inspect, and export content for various formats including Office (Excel, Word, etc.), PDF, iWork, OneNote, OpenDocument, email, Markdown, AsciiDoc, LaTeX, CSV, Visio, and Confluence.

    A key feature is that it can perform these operations without Microsoft Office installed, as it is powered by the OfficeIMO.* engine.

  2. Word workflow capabilities

    main

    The Word module provides several advanced workflow capabilities:

    • Templates and Data: Supports mail merge, table conditions, calculated columns, document properties, fields, and reusable content blocks.
    • Reviewing: Inspect comments and revisions using Get-OfficeWordReview, and resolve them using Resolve-OfficeWordRevision.
    • Forms: Create interactive documents with check boxes, combo boxes, date pickers, drop-down lists, picture controls, repeating sections, and general content controls.
    • Delivery: Merge documents, protect output, update fields/TOCs, and convert documents to HTML or Markdown.
  3. Explore PSWriteOffice automation capabilities by format

    main

    PSWriteOffice provides specialized automation for the following areas:

    Microsoft Office

    • Word: Read/inspect documents, update existing files, and perform mail merges.
    • Excel: Read/import data, update workbooks, merge, and compare workbooks.
    • PowerPoint: Inspect/update presentations and reuse/combine slides.
    • Visio: Diagram automation.

    PDF and Document Processing

    • PDF: Read/preflight, merge/split pages, position text/graphics, and redact/sanitize/optimize.
    • Reader & OCR: Search mixed document corpora and extract chunks, tables, and assets.

    Publishing and Open Formats

    • Confluence Cloud: Publishing workflows.
    • Open Text Formats: Support for Markdown (read, parse, convert, publish), RTF, CSV, OpenDocument, email, AsciiDoc, and LaTeX.
  4. Find text matches in a Word document with Find-OfficeWord

    main

    The Find-OfficeWord cmdlet allows you to search for specific text or regular expression patterns within a Word document. You can search by providing a file path or by passing an existing WordDocument object.

    Depending on the parameters used, the cmdlet returns either matching paragraphs (OfficeIMO.Word.WordParagraph) or a comprehensive OfficeIMO.Word.WordSearchResult object when using regex with the -AsResult switch.

    # Example: Find paragraphs containing 'Quarter' and export to CSV
    $matches = Find-OfficeWord -Path .\Report.docx -Text 'Quarter'
    $matches |
        Select-Object -Property Text |
        Export-Csv -Path .\ReviewMatches.csv -NoTypeInformation
  5. Generate request batches with -AsBatch

    main

    Use the -AsBatch switch to generate a GoogleSheetsBatch object. This returns a provider-neutral request batch without contacting Google services. This is useful for inspecting the structured requests that will be sent to the Google API.

    $batch = Export-OfficeExcelGoogleSpreadsheet -Path 'C:\Workbook.xlsx' -AsBatch
    # Inspect $batch for the provider-neutral requests
  6. Get-OfficePowerPointShape Parameter Sets

    main

    The Get-OfficePowerPointShape cmdlet operates in two distinct modes depending on the input provided:

    Slide Mode (Default)

    Used when piping a slide object into the cmdlet.

    • Input: PowerPointSlide via pipeline.
    • Parameters: -Slide, -ShapeIndex, -Name, -Kind.

    Presentation Mode

    Used when targeting a presentation directly.

    • Input: PowerPointPresentation via -Presentation parameter or pipeline.
    • Parameters: -Presentation, -Index (zero-based slide index), -ShapeIndex, -Name, -Kind.
  7. Use Add-OfficeExcelValidationTime with an existing Document

    main

    When not using the DSL context, you must pass an ExcelDocument object to the -Document parameter. You can also specify which sheet to target using -Sheet (name) or -SheetIndex (0-based index).

    # Example of the Document parameter set syntax
    Add-OfficeExcelValidationTime -Document $myDoc -Sheet 'Sheet1' -Range 'A1:A10' -Operator LessThan -Formula1 ([TimeSpan]::FromHours(12))
  8. Choose the right workflow for your job

    main

    Use the following decision matrix to select the appropriate PSWriteOffice surface:

    Job TypeRecommended Workflow
    Export rows or query resultsPipeline (Export-Office*)
    Add content from loops or conditionsDocument object (New-Office* with -NoSave)
    Author the complete artifact in one placeDSL (PdfNew, etc.)
    Change a supplied documentOpen, target, save, close (Get-Office*)
    Read many formats into one downstream modelReader

    All workflows utilize the same underlying OfficeIMO engines and are complementary.

  9. Convert between document formats with PSWriteOffice

    main

    PSWriteOffice features a robust suite of conversion cmdlets to move data between Microsoft Office, PDF, Markdown, HTML, and other formats:

    • Office to Other: Convert Word/Excel/PowerPoint to OpenDocument, or convert OneNote to Markdown/HTML/PDF.
    • PDF Conversions: Convert PDF to Word, Excel (extracting tables), HTML, or Markdown. You can also optimize PDFs, redact content, sanitize files, or make them searchable via OCR.
    • Markdown/HTML/LaTeX: Convert between Markdown, HTML, AsciiDoc, and LaTeX with fidelity diagnostics.
    • Visio/PowerPoint: Export Visio to PNG/SVG, or reconstruct PowerPoint presentations from PDFs.
  10. Understand the PSWriteOffice DSL structure

    main

    The PSWriteOffice Domain Specific Language (DSL) uses a scoped command pattern for document composition.

    1. Outer Constructor: A command like New-Office* (e.g., WordNew, ExcelNew, PdfNew) creates the file and establishes the top-level scope.
    2. Nested Blocks: Commands inside the script block (e.g., WordSection, PdfHeading) establish active sections, sheets, slides, or pages. This allows you to use content commands without repeatedly passing the document object.

    If you need to pass explicit document objects through loops or conditions, refer to the pipeline, object, and DSL workflow guide.

  11. Configure image placement and behavior in Excel

    main

    When using the -Range parameter, you can control how the image behaves when cells are moved or resized using the -Placement parameter.

    Valid values for -Placement (ExcelImagePlacement):

    • MoveAndSize: The image moves and resizes with the cells in the specified range.
    • MoveOnly: The image moves with the cells but maintains its original size.
    • FreeFloating: The image does not move or resize with the cells.
    # Example of MoveAndSize placement
    Add-OfficeExcelImage -Range 'A1:C15' -Path .\logo.png -Placement MoveAndSize