Opening Excel from Julia via DotNET

  • 1 year ago
Comment

ChatGPTChatGPT
1 / 1

To open Excel from Julia via DotNET, you can use the following code:

julia
using NET

# Create an instance of the Excel application
excel = NET.createInstance("Microsoft.Office.Interop.Excel.Application")

# Make Excel visible
excel.Visible = true

# Open a new workbook
workbook = excel.Workbooks.Add()

# Do some work in the workbook...

# Save and close the workbook
workbook.SaveAs("C:\\path\\to\\my\\workbook.xlsx")
workbook.Close()

# Quit Excel
excel.Quit()

In this code, we use the NET package to create an instance of the Excel application using the createInstance function. We then set the Visible property of the Excel application to true so that the Excel window is displayed.

Next, we create a new workbook using the Add method of the Workbooks collection property of the Excel application. We can then manipulate the workbook as needed, adding data, formulas, and formatting.

Finally, we save the workbook using the SaveAs method, close it using the Close method, and quit Excel using the Quit method.

Note that you may need to adjust the code to suit your specific needs, such as specifying the path to your Excel file, adding data to the workbook, or using a different version of Excel. Also, make sure that you have the necessary permissions and licenses to use Excel on your system.