9

Is there any way to create a new Excel file from command line?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Diego Pacheco
  • 193
  • 2
  • 2
  • 10

2 Answers2

6

You can do this using PowerShell:

PS> $excel = New-Object -ComObject "Excel.Application"
PS> $wb = $excel.Workbooks.Add()
PS> $ws = $wb.ActiveSheet
PS> $excel.Visible = $True

       < do some work >

PS> $wb.SaveAs("xltest.xlsx")
PS> $wb.Close()
PS> $excel.Quit()
David
  • 6,462
  • 2
  • 25
  • 22
6

If the Excel files you need to create are always the same, you can create a template manually, then create new files at will with something like...

copy template.xlsx myNewSpreadsheet.xlsx

If you need to create files with content that varies, I suggest starting with the powershell solution proposed by David.

Tim
  • 1,755
  • 2
  • 22
  • 34