Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

How to Autosize Columns when using PowerShell using excel objects

$
0
0

So I'm trying to Autosize the columns, so that when I open up the excel file, I dont have to expand the columns manually to see all the contents inside the cell. But for some reason , I'm failing, even the .xls file shows everything in one column instead of multiple columns. This is wht I did for the script, if anyone can help that would be great!

$excel = New-Object -ComObject excel.application;
$excel.visible=$false;
$serverInfoSheet= $excel.Workbooks.Open("C:\Temp\report.csv");
$serverInfoSheet.Activesheet.Cells.EntireColumn.Autofit();
$serverInfoSheet.SaveAs("C:\Temp\report.xls");
$ServerInfoSheet.Close(0);
$excel.Quit();


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>