-
Hello, I'm trying to empty a column cells while keeping the header and then write new data into the column. What is the strategy? Normally I would check the length of something and iterate over each occurrence to delete data. But after I grab the column I don't see the length method: $worksheet.Column(4) Shall I delete the entire column and recreate it when I enter the fresh data? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
please add a short repro of what you are attempting, including an xlsx |
Beta Was this translation helpful? Give feedback.
-
apologies.. definitely wrote in a rush.. basically the script should:
Here what I got so far but the data is not being written. The header yes.
and the error is:
|
Beta Was this translation helpful? Give feedback.
-
apologies again, I've just realized I missed the method Value $worksheet.Cells["D$count"].Value = $item |
Beta Was this translation helpful? Give feedback.
-
actually, as column C contains formulas in each cell the $worksheet.DeleteColumn(4) is not an option, as that breaks the formula application to column D. So, I'm back to the need of emptying each cell .. |
Beta Was this translation helpful? Give feedback.
-
found that too, sorry for the waste of time.. hopefully it might help other importExcel newbies: $excelPack = Open-ExcelPackage -Path 'pathToFile' |
Beta Was this translation helpful? Give feedback.
found that too, sorry for the waste of time.. hopefully it might help other importExcel newbies:
$excelPack = Open-ExcelPackage -Path 'pathToFile'
$worksheet = $excelPack.Workbook.Worksheets['sapsid']
foreach ($cell in ($worksheet.SelectedRange["D2:D"])){
$cell.Clear()
}
$count = 1
foreach($item in $servers){
$count +=1
$worksheet.Cells["D$count"].Value = $item
}
Close-ExcelPackage $excelPack