Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export to excel journal

Status
Not open for further replies.

ciach

Mechanical
Sep 23, 2011
19
Hi guys,
I'm searching for journal solution to export columns from Assembly Navigator to Excel. I want to have this in one button.

I was trying this, but this don't want to work
Public excelApp As Excel.Application
Public excelBook As Excel.Workbook
Public excelSheet As Excel.Worksheet

Any help? Direction? Solution?

NX 6 and Excel 2007
 
Replies continue below

Recommended for you

Right click on the up/down arrow in the ANT, flyout:send to spreadsheet?
 
I know I can do like that, but I want to do this by journal.
 
To use commands like

Public excelApp As Excel.Application
Public excelBook As Excel.Workbook
Public excelSheet As Excel.Worksheet

you need

Imports Microsoft.Office.Interop

now Microsoft.Office.Interop is not a library supported by journalling. Therefore to use the above commands you need to build it as a dll.

Regards

Frank Swinkels
 
Hi guys,
my code get err in line 3 with spreadsheet_name

Code:
Dim ufs As UFSession = UFSession.GetUFSession()
Dim spreadsheet_name As String
ufs.XS.ExtractSpreadsheet(spreadsheet_name, "C:\test.xlsx")

from NXOPEN .Net Api

int UF_XS_extract_spreadsheet
(

char * spreadsheet_name,
char * file_name

)

char * spreadsheet_name Input Spreadsheet object name:
"MODELING_SHEET" - modeling spreadsheet data
"DEFAULT_SHEET" - Gateway spreadsheet data
"PART_FAMILY_SHEET" - Part Family spreadsheet data

How to define "char * spreadsheet_name"? Or how to get object MODELING_SHEET?
Any help?
 
You can access Excel as per the following code, but you lose the 'autocomplete' feature of visual studio. If you go this route, you may want to keep an instance of Excel running so you can reference the object model.

The following code was tested on NX 7.5 and Excel 2010.
Code:
[COLOR=blue]Option[/color] [COLOR=blue]Strict[/color] [COLOR=blue]Off[/color]  
[COLOR=blue]Imports[/color] System  
[COLOR=blue]Imports[/color] NXOpen  

[COLOR=blue]Module[/color] Module1  

    [COLOR=blue]Sub[/color] Main()  

        [COLOR=blue]Dim[/color] theSession [COLOR=blue]As[/color] Session [COLOR=blue]=[/color] Session.GetSession()  

        [COLOR=blue]Dim[/color] objExcel [COLOR=blue]=[/color] CreateObject("Excel.Application")  
        [COLOR=blue]If[/color] objExcel [COLOR=blue]Is[/color] [COLOR=blue]Nothing[/color] [COLOR=blue]Then[/color]  
            MsgBox("Could [COLOR=blue]not[/color] start Excel, this journal will now exit.", MsgBoxStyle.Critical, "Error")  
            [COLOR=blue]Exit[/color] [COLOR=blue]Sub[/color]  
        End [COLOR=blue]If[/color]  

        [COLOR=blue]Dim[/color] excelFile [COLOR=blue]As[/color] [COLOR=blue]String[/color] [COLOR=blue]=[/color] "C:\temp\test.xlsx"  
        [COLOR=blue]If[/color] [COLOR=blue]Not[/color] IO.File.Exists(excelFile) [COLOR=blue]Then[/color]  
            MsgBox("Specified file [COLOR=blue]not[/color] found, journal will now exit.", MsgBoxStyle.Critical, "File not found.")  
            [COLOR=blue]Exit[/color] [COLOR=blue]Sub[/color]  
        End [COLOR=blue]If[/color]  

        [COLOR=blue]Dim[/color] objWorkbook [COLOR=blue]=[/color] objExcel.Workbooks.Open(excelFile)  
        [COLOR=blue]If[/color] objWorkbook [COLOR=blue]Is[/color] [COLOR=blue]Nothing[/color] [COLOR=blue]Then[/color]  
            MsgBox("Could [COLOR=blue]not[/color] open Excel file, journal will now exit.", MsgBoxStyle.Critical, "Error")  
            [COLOR=blue]Exit[/color] [COLOR=blue]Sub[/color]  
        End [COLOR=blue]If[/color]  

        objExcel.visible [COLOR=blue]=[/color] [COLOR=blue]True[/color]  
        objExcel.cells(1, 1).value [COLOR=blue]=[/color] "your text here"  
        objWorkbook.save()  

 [COLOR=green]'to close the workbook and excel, uncomment the following lines[/color]

 [COLOR=green]'objWorkbook.close()[/color]
 [COLOR=green]'objExcel.quit()[/color]
 [COLOR=green]'objWorkbook = Nothing[/color]
 [COLOR=green]'objExcel = Nothing[/color]

        MsgBox("Journal execution successful", MsgBoxStyle.Information, "Success")  

    End [COLOR=blue]Sub[/color]  


    [COLOR=blue]Public[/color] [COLOR=blue]Function[/color] GetUnloadOption(ByVal dummy [COLOR=blue]As[/color] [COLOR=blue]String[/color]) [COLOR=blue]As[/color] [COLOR=blue]Integer[/color]  

 [COLOR=green]'Unloads the image when the NX session terminates[/color]
        GetUnloadOption [COLOR=blue]=[/color] NXOpen.Session.LibraryUnloadOption.AtTermination  

    End [COLOR=blue]Function[/color]  

End [COLOR=blue]Module[/color]


www.nxjournaling.com
 
I'm trying to make journal to export spreadsheet to Excel (Right mouse button in Assembly Navigator and then export to spreadsheet). With journal I want to make some corrections in spreadsheet and then save the spreadsheet file, close excel and come back to NX.
I made something similar, I could export txt file with Plist.ListToFile function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor