Greeting,
How can I use powershell to open an Excel file and find a empty cell?
Thanks
Usera
Technology Tips and News
Greeting,
How can I use powershell to open an Excel file and find a empty cell?
Thanks
Usera
A quick search of TechNet for 'powershell read excel file' returns a number of examples of how to read an Excel spreadsheet. Many also have different examples of reading the data in different ways.
Pick some examples and give it a try. The best way to learn is attempt things yourself and learn from your mistakes.
I can just type it in from memory which is what you get when you spend time testing and trying things.
$xl=New-Object -Com Excel.Aplication
$xl.Workbooks.Add()
$xl.ActiveSheet.Cells.Item(1,1) = 'Hello World
$xl.ActiveWorkbook.SaveAs('myboook.xlsx')
$xl.Quit()
Find first empty cell in sheet.
foreach($cell in $xl.ActiveSheet.Cells){if($cell.Formula -eq ''){$_;break}}
$cell is now the first empty cell.
Find first empty cell in sheet.
foreach($cell in $xl.ActiveSheet.Cells){if($cell.Formula -eq ''){$cell;break}}
$cell is now the first empty cell.
Usera, what do you mean by "find empty cell"? Please elaborate.
Did you mean {$cell;break}?
It ends the loop on the first empty cell.
The first empty cell is the first cell with no formula or text.
Break ends the loop. $_ serves no purpose.
It stops the loop at the first empty cell. Now "$cell" is the first empty cell which is what was requested.
Have you even tried to run it,
Note the filter:
if($cell.Formula -eq ''){$_;break}}
It breaks on first empty cell leaving "$cell" set to that value.
This is a classic programing construct to seek over a collection for a specific item. It is a fundamental programming pattern.
<over [collection]>{break on match}
Usera, what do you mean by "find empty cell"? Please elaborate.
Usera, what do you mean by "find empty cell"? Please elaborate.
Hah! Mobile! No such thing here.
MSDN forums work much better.
MSDN forums work mu
No. How do we get to that?
Change the URL to point at MSDN instead of TechNet:
MSDN version:
https://social.msdn.microsoft.com/profile/jrv/?ws=usercard-mini
TechNet version:
https://social.technet.microsoft.com/profile/jrv/?ws=usercard-mini
Nice. Much cleaner. Is it only on the profile?
With HTML5 they should be be to do amazing things.
Yeah, it's only profile changes AFAIK.
I only recently found out about it. My avatar image doesn't fit very well.