Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Excel file from command line

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

like image 999
Diego Pacheco Avatar asked Nov 29 '12 21:11

Diego Pacheco


2 Answers

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.

like image 166
Tim Avatar answered Oct 23 '22 15:10

Tim


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()
like image 33
David Avatar answered Oct 23 '22 16:10

David