你在這裏:
# Launch Excel:
$app = New-Object -comobject Excel.Application
# Open a Workbook:
$app.Workbooks.Open("C:\Users\admin\Desktop\Workbook.xlsx")
# Activate the chart you need (note: you don't need full path with filename now):
$app.Workbooks("Workbook.xlsx").Sheets("Sheet1").ChartObjects("Chart 1").Activate()
# Change the category type of axis. Axes(1) means category axis. Possible values:
# xlCategoryScale = 2
# xlTimeScale = 3
# xlAutomaticScale = -4105
$app.ActiveChart.Axes(1).CategoryType = 2
# Save & close the workbook
$app.Workbooks("Workbook.xlsx").Close($True)
您現在可以返回到第2步,打開另一個工作簿,並重復這些動作。 完成後,關閉Excel應用程序並清理:
$app.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($app)
Remove-Variable app
什麼格式,XLS或XLSX? – Taosique
@Taosique請參閱問題更新。謝謝。 – Federer