- This topic has 3 replies, 4 voices, and was last updated 1 week, 3 days ago by
February 5, 2020 at 8:25 pm #202049ParticipantTopics: 5Replies: 4Points: 42Rank: Member
I am having a hard time finding example scripts to convert an excel file into a word doc using Powershell, and then using Powershell to format the word doc. Does anyone have any examples i can work off of? Every online example errors out with me.
February 5, 2020 at 10:50 pm #202070Senior ModeratorTopics: 3Replies: 117Points: 605Rank: Major Contributor
First make sure you have a module like ImportExcel installed (or a module for Excel, anyway – there are other options). PowerShell doesn’t have commands for handling Excel data natively. You can check like this:
Get-Command | Where-Object -Property Name -Match 'Excel'
If you don’t get any results, do this:
Install-Module -Name ImportExcel
You won’t be able to convert an Excel spreadsheet directly into a Word document, but you can embed an Excel sheet in a Word document. This is the equivalent of doing Insert -> Object -> Microsoft Excel Worksheet in Word. You should probably read through these tutorials as well:
Beginning with PowerShell and Word
COM Automation of Office Applications via PowerShell
If you don’t want the Excel data to be in a worksheet object in Word, but instead want it as normal text on the page, you’ll have to get more creative. You’ll need to import the data from the Excel sheet into PowerShell, and then create some script manually to write that data into the Word document in the way that you want. Alternatively, you could convert the Excel sheet to a CSV and then write that data into a Word document.
February 6, 2020 at 12:59 am #202079ParticipantTopics: 10Replies: 119Points: 541Rank: Major Contributor
If you’re really adventurous, you could consider using a template .docx with formatting and text placeholders completed, then use a script to make a working copy of the .docx, unzip it to access word/document.xml. In document.xml, replace the placeholders with the Excel data, save it, and zip it back up.
February 17, 2020 at 12:31 pm #203793ParticipantTopics: 0Replies: 1Points: 6Rank: Member
It’s not that tough to convert Excel file to Word doc file. If you are looking for some easy tricks to import data from word to Excel. Then try any of the following method:
Method 1. Single Cell Import
Method 2. Import Data Cell by Cell
Method 3. Convert Word To Excel Using “From Text” Option
To catch complete detail about these methods check out the following link:
- This reply was modified 1 week, 3 days ago by edwards14256. Reason: correction
- You must be logged in to reply to this topic.