Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PowerShell save as xlsx without excel

Status
Not open for further replies.
Feb 26, 2015
5
US
Hello All
I have a PowerShell script that takes a txt file that is output from our monitoring software sorts it by headers and converts it to a CSV file. my issue is that I need this file in xlsx format and I do not have Excel installed on the server. does anyone know of anyway to do this?
 
come on another separate post in the vbscript forum?
for example a family tree related csv
Import-csv yourfile.csv|select person, surname, given, gender|sort gender, surname,given|export-csv newfile.csv
open the csv in xl or rename it to xls..etc
 
You cannot merely rename a TEXT file to .xls* it's still a text file!
 
dpierce4776,

I am not aware of any way to do the conversion you are looking for without having Excel installed. Microsoft provides a free Excel viewer that would allow you to read an Excel file without having Excel installed, but nothing to let you go the other way.

What you could however do is use a remote PowerShell session to a system that does have Excel installed, have that system open the CSV file and then perform the SaveAs to convert it.

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at
Work SMARTER not HARDER.
 
Thank you markdmac
I have been researching it and seen others try to make cmdlets for PowerShell to make it work but when I try it it errors out
 
dpierce4776, start with getting code to work locally on a machine that does have Excel. Then you just need to put the wrapper of the remote session around it.

Here is some quick code I put together and tested to verify it works locally for you.

Code:
$xl = New-Object -ComObject Excel.Application
$xl.Visible = $True
$WorkBook = $xl.Workbooks.Open("C:\Temp\Printers.csv")
$xl.ActiveWorkBook.SaveAs("C:\Temp\Printers.xlsx")

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at
Work SMARTER not HARDER.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top