r/PowerShell • u/adbertram • Dec 23 '19
Blog Post: PowerShell and Excel: Yes, They Work Together
Hey guys, I just wrote a shiny new blog post you may enjoy.
Summary: Marry PowerShell and Excel together by exporting and importing Excel workbooks, inspecting cells and more in this tutorial!
4
u/Swarfega Dec 24 '19
Converting CSV Files to Excel with PowerShell
The title says this but all examples are converting Excel to CSV. The title just needs correcting.
1
u/shallanlol Dec 24 '19
It's a pity word integration sucks
1
1
u/rantingdemon Dec 24 '19
What would be the use cases for integration with Word?
3
u/beerchugger709 Dec 24 '19
https://github.com/paulwetter/DocumentConfigMgrCB/
Here's a script that documents (in incredible detail) an entire SCCM environment. Among the outputs, is a docx without any need for word to be installed. Lol, the dude even added switches to customize the cover page with logos and stuff
2
u/MrWinks Dec 24 '19
Search and replace text in a template file, then save the file. Easy to make sheets with names and such on them this way.
2
u/ipreferanothername Dec 24 '19
https://github.com/EvotecIT/PSWriteWord
this guy posts around here regularly, i havent had a need to use the module myself but maybe give it a whirl. he has lots of other modules. https://github.com/EvotecIT
1
u/MrWinks Dec 24 '19
I use the com objects directly and got comfortable with the process, but thank you!
2
u/shallanlol Dec 27 '19
Problem is resources and runtime of the word objects vs Excel for similar operations
1
u/shallanlol Dec 27 '19
I work in education. Generally reports in docx are used by teachers in common and other behavioural templates.
There are much better methods of doing it so it's not a solid use case.
However the way the interaction works with word against powershell makes it much more annoying and resource consuming.
3
u/BigR0n75 Dec 23 '19
This and DbaTools are my favorite, most commonly used modules. I've barely scratched the surface with either and I can already see how cool things they can do together.
2
u/darty1713 Dec 23 '19
Fantastic, thanks, it's great. I'm just starting to learn powershell and this type of post is perfect.
1
u/dittbub Dec 24 '19
I've replaced SQL csv with powershell excel files at work. users love it cause they can actually open it as an attachment, and commas won't fuck the whole thing up!
-5
u/jsiii2010 Dec 23 '19
Or export to csv then import in excel. Excel likes ascii better than unicode.
1
u/volvo64 Dec 24 '19
Not to mention the csv support in Powershell is 10x faster. If I’m working with any large amount of data I start with a CSV then push it to Excel and manipulate from there. Much faster.
13
u/northendtrooper Dec 23 '19
Good stuff. Unfortunately some of the networks we work on prevent installing 3rd party modules. Would be nice to see how to work with excel within powershell as native with the com object.