Created
June 13, 2023 09:14
-
-
Save Fabaderheld/6282c8c73b656cad55ec9fa3caba8b9e to your computer and use it in GitHub Desktop.
CS to PS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Click-Button1 { | |
| # Specify the path to your logo image file | |
| $logoPath = "C:\temp\stv\stv-04.png" | |
| # Get the current Word document | |
| $doc = $app.ActiveDocument | |
| # Add the logo to the document | |
| $logoShape = $doc.Shapes.AddPicture($logoPath, @{LinkToFile = $false; SaveWithDocument = $true }).ConvertToInlineShape() | |
| $logoShape.LockAspectRatio = [Microsoft.Office.Core.MsoTriState]::msoTrue | |
| $logoShape.Width = 50 # Adjust the logo width as needed | |
| $logoShape.Height = 50 # Adjust the logo height as needed | |
| $isLogoAdded = $true # | |
| } | |
| function Click-Button2 { | |
| # Specify the path to your logo image file | |
| $logoPath = "C:\temp\stv\stv-04.png" | |
| # Get the current Word document | |
| $doc = $application.ActiveDocument | |
| # Get the first section of the document | |
| $section = $doc.Sections.Item(1) | |
| # Get the header for the first section | |
| $header = $section.Headers.Item(1) | |
| # Add a shape to the header | |
| $shape = $header.Shapes.AddPicture($logoPath) | |
| # Get the width of the header in points | |
| $headerWidth = $section.PageSetup.PageWidth - $section.PageSetup.LeftMargin - $section.PageSetup.RightMargin | |
| # Print the header width | |
| Write-Host "Header Width: " + $headerWidth.ToString() + " points" | |
| Write-Host "Margin: " + $section.PageSetup.LeftMargin.ToString() + " points" | |
| Write-Host "Logo Width: " + $shape.Width.ToString() + " points" | |
| # Convert point to cm | |
| $headerWidthCm = $headerWidth / 28.35f | |
| # Set the absolute position of the shape | |
| $shape.LeftRelative = 0 | |
| $shape.TopRelative = 0 | |
| # Set the position in points (adjust as needed) | |
| $shape.Left = $headerWidth - $shape.Width | |
| $shape.Top = 0 | |
| $isLogoAdded = $true # | |
| } | |
| function Click-Button3 { | |
| #Get the selected item label from the dropdown | |
| $selectedItemLabel = dropDown1.SelectedItem.Label; | |
| if ($selectedItemLabel -eq "Deutsch") { | |
| $headlineText = "Ueberschrift"; | |
| } | |
| else { | |
| $headlineText = "Your Heading Text"; | |
| } | |
| #Get the current Word document | |
| $doc = $Globals:ThisAddIn.Application.ActiveDocument; | |
| #Get the first paragraph in the document | |
| $paragraph = $doc.Paragraphs[1]; | |
| #Set the paragraph's style to a heading style (e.g., Heading 1) | |
| $paragraph.set_Style(WdBuiltinStyle.wdStyleHeading1); | |
| #Set the text for the heading | |
| $paragraph.Range.Text = $headlineText; | |
| $isHeadLineAdded = $true; | |
| } | |
| function Click-Button4 { | |
| # Get the running Word application instance | |
| $wordApp = [Runtime.InteropServices.Marshal]::GetActiveObject("Word.Application"); | |
| # Get the current Word document | |
| $doc = $wordApp.ActiveDocument; | |
| # Get the current selection range | |
| $selectionRange = $wordApp.Selection.Range; | |
| # Insert a new paragraph at the selection range | |
| $newParagraph = $doc.Content.Paragraphs.Add($selectionRange); | |
| # Define the table dimensions | |
| $rows = 3; | |
| $columns = 4; | |
| # Add the table | |
| $table = $doc.Tables.Add($selectionRange, $rows, $columns); | |
| # Populate the table cells | |
| for ($row = 1; $row -le $rows; $row++) { | |
| for ($column = 1; $column -le $columns; $column++) { | |
| # Access the cell using the row and column indexes | |
| $cell = $table.Cell($row, $column); | |
| # Set the cell content | |
| $cell.Range.Text = "Cell $row-$column"; | |
| } | |
| } | |
| # Format the table | |
| $table.Range.Font.Size = 12; | |
| $table.Range.Font.Name = "Arial"; | |
| $table.Borders.Enable = 0; | |
| $table.AutoFitBehavior([WdAutoFitBehavior]::wdAutoFitContent); | |
| $isAddressblockAdded = $true; # | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment