Powershell: Create multiple files from a Word template and rename using a list in Excel/CSV
Powershell: Create multiple files from a Word template and rename using a list in Excel/CSV
I'm a beginner to Powershell and CLI in general, but this task does not need to use either so I'm open to using other tools.
I'm trying to do the following:
- Create multiple files from a Word template.
- Rename each file based on a list of names found in an Excel/CSV sheet.
Thanks in advance!
You're viewing a single thread.
For csv import, use import-csv and loop on the results:
Import-csv myfile.csv | foreach-object {
Templates should be easy, just copy the template to a new file with the docx extension. Use one of the columns (in this case "name" as the column header,) from the csv for the name:
$newname = $_.name + '.docx' Copy-item 'template.dotx' $newname }
2 0 ReplyHey this worked for me yesterday but now I'm having trouble getting it to work again. It just outputs a Word doc titled '.docx' now.
1 0 ReplyMake sure the columns in your csv are named properly, my code assumes it's named just "name"
2 0 ReplyBy the way, what would be the equivalent code when using a text file for the list of names rather than a csv file?
1 0 ReplyAh, I think that was it. Forgot about the column heading. Thanks for your help!
1 0 Reply
So I'm new to all this. When I enter the first command with my csv file and doc file included, it just opens the word doc. Wasn't sure what I should do next.
1 0 ReplyActually nevermind that question. Just realized the command was split.
I'm assuming I need to replace the name portion of the 2nd line. What do I input if the data is a list that starts in A1?
1 0 ReplyI got it now!
1 0 Reply