我已经有了这个文件Workspacesize.csv。我正在向单元格(1,2)添加一个TEST值,并试图保存。它要求我提示文件已经存在,是否要覆盖。我不想要这个提示。我使用了$Excelobject。DisplayAlerts= 'False',但仍然不工作
$Excelobject=New-object -ComObject Excel.Application
$Excelobject.visible = $False
$workbook=$Excelobject.Workbooks.Open("C:UsersSiddhartha.S.Das2OneDrive - ShellDesktopWorkspacesize.csv")
$worksheet=$workbook.worksheets.Item(1)
$worksheet.Activate()
$worksheet.cells.item(1,2)="TEST"
$workbook.SaveAs("C:UsersSiddhartha.S.Das2OneDrive - ShellDesktopWorkspacesize.csv")
$workbook.close
$Excelobject.DisplayAlerts= 'False'
$Excelobject.Quit()
你最好不要用excel来处理csv文件,这会使事情不必要地复杂化。
$Path = "C:UsersSiddhartha.S.Das2OneDrive - ShellDesktopWorkspacesize.csv"
$Content = Import-Csv -Path $Path
$Content[0].Col1 = 'TEST' #Put your actual column name rather than Col1
$Content | Export-Csv -Path $Path