Inventor Customization

Inventor Customization

Reply
Contributor
MtigaM
Posts: 17
Registered: ‎06-26-2012
Message 1 of 7 (1,085 Views)
Accepted Solution

How to create a excel file using ilogic? Thanks

1085 Views, 6 Replies
06-27-2012 09:56 AM
 
*Expert Elite*
Curtis_Waguespack
Posts: 2,874
Registered: ‎03-08-2006
Message 2 of 7 (1,080 Views)

Re: How to create a excel file using ilogic? Thanks

06-27-2012 10:34 AM in reply to: MtigaM

Hi MtigaM, 

 

Here is an iLogic example.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

'define the file to create/open
myXLS_File = "C:\Temp\Best_Excel_File_Ever.xls"

‘get the Inventor user name from the Inventor Options
myName= ThisApplication.GeneralOptions.UserName

'define Excel Application object
excelApp = CreateObject("Excel.Application")
'set Excel to run visibly, change to false if you want to run it invisibly
excelApp.Visible = True
'suppress prompts (such as the compatibility checker)
excelApp.DisplayAlerts = false

'check for existing file
If Dir(myXLS_File) <> "" Then
'workbook exists, open it
excelWorkbook = excelApp.Workbooks.Open(myXLS_File)
ExcelSheet = ExcelWorkbook.Worksheets(1)
Else
'workbook does NOT exist, so create a new one
excelWorkbook = excelApp.Workbooks.Add
End if

'Insert data into Excel.
With excelApp
    .Range("A1").Select
    .ActiveCell.FormulaR1C1 = "Hello, " & myName
End With   

'set all of the columns to autofit
excelApp.Columns.AutoFit   
'save the file
excelWorkbook.SaveAs (myXLS_File)

''close the workbook and the Excel Application
''uncomment if you want to close the xls file at the end
'excelWorkbook.Close
'excelApp.Quit
'excelApp = Nothing    


  solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.





Contributor
MtigaM
Posts: 17
Registered: ‎06-26-2012
Message 3 of 7 (1,071 Views)

Re: How to create a excel file using ilogic? Thanks

06-27-2012 10:45 AM in reply to: Curtis_Waguespack

Thanks alot, this is what i am looking for!

Contributor
MtigaM
Posts: 17
Registered: ‎06-26-2012
Message 4 of 7 (1,064 Views)

Re: How to create a excel file using ilogic? Thanks

06-27-2012 10:55 AM in reply to: MtigaM

Is it possible to open a template excel file somewhere and then save it as a new excel in another place?

*Expert Elite*
Curtis_Waguespack
Posts: 2,874
Registered: ‎03-08-2006
Message 5 of 7 (1,058 Views)

Re: How to create a excel file using ilogic? Thanks

06-27-2012 11:54 AM in reply to: MtigaM

Hi MtigaM,

 

To specify the template to use you can use this example.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

'define the file to create/open
myXLS_File = "C:\Temp\Best_Excel_File_Ever.xls"

‘get the Inventor user name from the Inventor Options
myName= ThisApplication.GeneralOptions.UserName

'define Excel Application object
excelApp = CreateObject("Excel.Application")
'set Excel to run visibly, change to false if you want to run it invisibly
excelApp.Visible = True
'suppress prompts (such as the compatibility checker)
excelApp.DisplayAlerts = false

'check for existing file 
If Dir(myXLS_File) <> "" Then
'workbook exists, open it
excelWorkbook = excelApp.Workbooks.Open(myXLS_File)
ExcelSheet = ExcelWorkbook.Worksheets(1)
Else
'create a new spreadsheet from template
excelWorkbook = excelApp.Workbooks.Add (Template: = "C:\Temp\Best_Excel_Template_Ever.xlt")
End if

'Insert data into Excel.
With excelApp
	.Range("A1").Select
	.ActiveCell.FormulaR1C1 = "Hello, " & myName
End With   

'set all of the columns to autofit
excelApp.Columns.AutoFit   
'save the file
excelWorkbook.SaveAs (myXLS_File)

''close the workbook and the Excel Application
''uncomment if you want to close the xls file at the end
'excelWorkbook.Close
'excelApp.Quit
'excelApp = Nothing       

 



  solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.





Contributor
MtigaM
Posts: 17
Registered: ‎06-26-2012
Message 6 of 7 (1,048 Views)

Re: How to create a excel file using ilogic? Thanks

06-27-2012 12:11 PM in reply to: Curtis_Waguespack

Thank you very much!

New Member
shahbaz-alavi
Posts: 1
Registered: ‎07-02-2013
Message 7 of 7 (666 Views)

Re: How to create a excel file using ilogic? Thanks

07-02-2013 11:41 PM in reply to: Curtis_Waguespack

can we specify the directory of the saved file?

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.