saving Excel file in ABAQUS Python script?
saving Excel file in ABAQUS Python script?
(OP)
Hello,
I recorded a macro in ABAQUS, the last step is importing xy data from ABAQUS to Excel. If I run this python script in MATLAB, I can get an unsaved Excel file named 'Book1'.
The last few lines look like this:
import abq_ExcelUtilities.excelUtilities
abq_ExcelUtilities.excelUtilities.XYtoExcel(xyDataNames='From Current XY Plot',
trueName='From Current XY Plot')
My question is, is there any ABAQUS Python command which allows me to write in my macro Python file and save this Excel file? If I do not save it, I cannot do anything to these data apart from seeing it.
Thank you!
I recorded a macro in ABAQUS, the last step is importing xy data from ABAQUS to Excel. If I run this python script in MATLAB, I can get an unsaved Excel file named 'Book1'.
The last few lines look like this:
import abq_ExcelUtilities.excelUtilities
abq_ExcelUtilities.excelUtilities.XYtoExcel(xyDataNames='From Current XY Plot',
trueName='From Current XY Plot')
My question is, is there any ABAQUS Python command which allows me to write in my macro Python file and save this Excel file? If I do not save it, I cannot do anything to these data apart from seeing it.
Thank you!





RE: saving Excel file in ABAQUS Python script?
xl = win32com.client.Dispatch("Excel.Application") #Fetch the application and assign it to a variable. You can now interact with excel using python/VBA.
xl.DisplayAlerts=False #Get rid of popup alerts that will prevent some scripts from running.
xl.Visible = 1 #Shows the excel app window, useful if you want to mess around issuing commands from the Abaqus GUI and observing what happens in the workbook.
xlBook = xl.Workbooks.Add() #Similar to what Abaqus does, creates a 'Book1'.
xlSheet = xlBook.Sheets(1) #Access a worksheet
xlSheet.Cells(1,1).Value = #Modify cell contents.
xlBook.SaveAs(Filename='Name', FileFormat='Format') #Here is the save command you were looking for.
xl.Application.Quit()
You can also use that to open an existing workbook, modify and save it.
xlBook = xl.Workbooks.Open('path\filename.xls')
xlBook.Save()
RE: saving Excel file in ABAQUS Python script?
RE: saving Excel file in ABAQUS Python script?
Shall I use this code in ABAQUS or MATLAB? I tried in ABAQUS but it seems that it cannot recognise this syntax (which means I have to follow some Python syntax rules in order to make it work in ABAQUS)
RE: saving Excel file in ABAQUS Python script?
import win32com.client
from win32com.client import constants
RE: saving Excel file in ABAQUS Python script?
I tried and it gave me this error in MATLAB:
com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft Excel', u'SaveAs method of Workbook class failed', u'xlmain11.chm', 0, -2146827284), None)
Abaqus Error: cae exited with an error.
ans =
1
But an empty new book did created, so my question is instead of creating a new book, how to save the existing unsaved book?
Thank you!
RE: saving Excel file in ABAQUS Python script?