spreadsheet excel

Hello there,
How do you write ROW or column data when you are exporting data with journal? I do not want to print the headers in the sub-subheadings to meet the information.

sample ;
datum A
zone B5
page_number 1

I want you to be on the excel page as above. but the data I get is as follows.

datum zone page_number
  A B5 1

This is what happens with the following code, but I do not want it.

can you help me?

'Sheet No.'. | Zone | Description \ Measurement Direction |

Option Strict Off
Imports System
Imports System.IO
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Annotations

Module ExportDimensionsAndAnnotations
'Declare global variables
Dim theSession as Session = Session.GetSession ()
Dim theUfSession As UFSession = UFSession.GetUFSession

Sub Main ()

If IsNothing (theSession.Parts.Work) Then 'Error handling
MsgBox ("This code requires an active part.
Exit Sub
End If
Dim workPart as Part
workPart = theSession.Parts.Work

Dim theUISession as UI = UI.getUI
Dim saveFileName as String
Dim saveDialog as New System.Windows.Forms.SaveFileDialog
Dim objExcel as Object
Dim objWorkbook as Object
Dim excelFileExists as Boolean = False
Dim objWorksheet as Object
Dim colSheetNumber as Integer = 3
Dim colZone as Integer = 1
Dim colDescrMatlDir as Integer = 2

Dim valueSheetNumber as String
Dim valueZone as String
Dim valueDescrMatlDir as String
Dim rowNumber as Integer = 1

With saveDialog
.DefaultExt = "xlsx"
.FileName = & quot; Datum_GD & T data & quot;
.Filter = "MS Excel Spreadsheets (* .xlsx) | * .xlsx | All Files (*. *) | *. *"
.FilterIndex = 1
.OverwritePrompt = True
.Title = "Select a file where you'd like to save the exported data."
End With
savedialog.showdialog ()
saveFileName = saveDialog.FileName
If saveFileName = "Exported Data" Then
MsgBox ("You failed to select a save file. Exiting the macro.")
Exit Sub
End If
objExcel = CreateObject ("Excel.Application")
if objExcel is Nothing Then
theUISession.NXMessageBox.Show ("Error", theUISession.NXMessageBox.DialogType.Error, "Could not start Excel, journal exiting")
Exit Sub
End If
If File.Exists (saveFileName) Then
excelFileExists = True
objWorkbook = objExcel.Workbooks.Open (saveFileName)
objWorksheet = objWorkbook.Sheets.Add
else
objWorkbook = objExcel.Workbooks.Add
objworkbook.saveas (SaveFilename)
objWorksheet = objWorkbook.Sheets (1)
End If

objWorksheet.cells (rowNumber, colSheetNumber) .Value = "Sheet Number"
objWorksheet.cells (rowNumber, colZone) .Value = "Drawing Zone"
objWorksheet.cells (rowNumber, colDescrMatlDir) .Value = "Description Text \ Measurement Direction"

objworksheet.columns ( "A: M").entirecolumn.autofit
objworkbook.sav A ()
objworkbook.clos A ()
objexcel.quit ()
objWorksheet = Nothing
objWorkbook = Nothing
objExcel = Nothing
MsgBox ("Completed the extraction successfully! Check" & saveFileName & "for the data.")

End Sub

End Module

It sounds like you are writing information to multiple columns in the same row, but want it in multiple rows of the same column. The information shows up the way it does because of the following code:

objWorksheet.cells (rowNumber, colSheetNumber) .Value = "Sheet Number"
objWorksheet.cells (rowNumber, colZone) .Value = "Drawing Zone"
objWorksheet.cells (rowNumber, colDescrMatlDir) .Value = "Description Text \ Measurement Direction"

In the code above, the same row number is specified 3 times with a different column value each time. If you want to write to multiple rows, update the row number in each line and use the same column.

I solved this problem. thank you. I have now compared with another problem. I would like to export the datum letters (such as A, B, C) on the drafting page to excel but I failed. can you help if you have knowledge in this matter?

If you are talking about the datum feature symbols, I've already given you code to extract the datum letters and zones.
http://nxjournaling.com/content/datum-feature-symbol
You have code to get the letters and zones and you have code to write information to Excel. If I understand your requirement, all you have to do is combine the 2 journals.

Do you have a specific question?

Hello there,
With the code we sent earlier, the information opens in the List window. I want to export this information to excel.

Yes, you have all the pieces, now you need to put them together. So instead of writing to the information window:

listingwindow.WriteLine(zoneInfo)

Add in your Excel code and write it to the cell of your choosing:

objWorksheet.cells(rowNumber, colNumber).Value = zoneInfo

I do not know how to add the lines you send the code because I do not know very well. I tried, but I could not. I do not even know how to get the datum tag label. If you do not mind, can you help me more clearly?

Try the following code. It combines your Excel code and the code I previously gave you to report the drafting datum information.

Option Strict Off
Imports System
Imports System.IO
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Annotations

Module ExportDimensionsAndAnnotations
'Declare global variables
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession

Sub Main()

If IsNothing(theSession.Parts.Work) Then 'Error handling
MsgBox("This code requires an active part.")
Exit Sub
End If
Dim workPart As Part
workPart = theSession.Parts.Work

Dim theUISession As UI = UI.GetUI
Dim saveFileName As String
Dim saveDialog As New System.Windows.Forms.SaveFileDialog
Dim objExcel As Object
Dim objWorkbook As Object
Dim excelFileExists As Boolean = False
Dim objWorksheet As Object
Dim colZone As Integer = 1
Dim colDescrMatlDir As Integer = 2
Dim colSheetNumber As Integer = 3

Dim rowNumber As Integer = 1

Dim datumFeatures As New List(Of Annotations.DraftingDatum)

For Each temp As NXObject In theSession.Parts.Work.Gdts
'lw.WriteLine(" type: " & temp.GetType.ToString)
If TypeOf (temp) Is Annotations.DraftingDatum Then
datumFeatures.Add(temp)
End If
Next

If datumFeatures.Count = 0 Then
Return
End If

With saveDialog
.DefaultExt = "xlsx"
.FileName = "Datum_GDnT data"
.Filter = "MS Excel Spreadsheets (*.xlsx) | *.xlsx | All Files (*.*) | *.*"
.FilterIndex = 1
.OverwritePrompt = True
.Title = "Select a file where you'd like to save the exported data."
End With
savedialog.showdialog()
saveFileName = saveDialog.FileName
If saveFileName = "Exported Data" Then
MsgBox("You failed to select a save file. Exiting the macro.")
Exit Sub
End If
objExcel = CreateObject("Excel.Application")
If objExcel Is Nothing Then
theUISession.NXMessageBox.Show("Error", theUISession.NXMessageBox.DialogType.Error, "Could not start Excel, journal exiting")
Exit Sub
End If
If File.Exists(saveFileName) Then
excelFileExists = True
objWorkbook = objExcel.Workbooks.Open(saveFileName)
objWorksheet = objWorkbook.Sheets.Add
Else
objWorkbook = objExcel.Workbooks.Add
objworkbook.saveas(SaveFilename)
objWorksheet = objWorkbook.Sheets(1)
End If

objWorksheet.cells(rowNumber, colSheetNumber).Value = "Sheet Number"
objWorksheet.cells(rowNumber, colZone).Value = "Drawing Zone"
objWorksheet.cells(rowNumber, colDescrMatlDir).Value = "Datum"

For Each temp As Annotations.DraftingDatum In datumFeatures
rowNumber += 1

Dim myDraftingDatumZone As New NXJSheetZoneInfo
myDraftingDatumZone = ReportAnnotationSheetZone(AskDrawingSheet(temp), temp)

objWorksheet.cells(rowNumber, colSheetNumber).Value = myDraftingDatumZone.Sheet
objWorksheet.cells(rowNumber, colZone).Value = myDraftingDatumZone.VerticalZone & myDraftingDatumZone.HorizontalZone
objWorksheet.cells(rowNumber, colDescrMatlDir).Value = temp.Label

Next

objWorksheet.columns("A:M").entirecolumn.autofit
objWorkbook.save
objWorkbook.close
objExcel.quit()
Cleanup(objWorksheet, objWorkbook, objExcel)
MsgBox("Completed the extraction successfully! Check " & saveFileName & " for the data.")

End Sub

Sub Cleanup(ParamArray objs As Object())
GC.Collect()
GC.WaitForPendingFinalizers()
For Each obj As Object In objs
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Next
End Sub

Function AskDrawingSheet(ByVal theObject As TaggedObject) As Drawings.DrawingSheet
'Code written by Amy Webster of GTAC
' see nx_api4936 or nx_api4937
' This function will work for:
' an object which "Resides on drawing" or is "View Dependent In" a DraftingView
' a DraftingView
' a DrawingSheet.View
' Returns Nothing for all other (ie. model mode) objects

Dim theView As View = TryCast(theObject, View)
If Not theView Is Nothing Then
Dim sheetTag As Tag = Nothing
Try
theUfSession.Draw.AskDrawingOfView(theView.Tag, sheetTag)
Return Utilities.NXObjectManager.Get(sheetTag) ' the drawing it is on
Catch ex As NXException
Return Nothing ' it is a model view
End Try
End If

Dim viewName As String = Nothing
Dim status As Integer = Nothing
Try
theUfSession.View.AskViewDependentStatus(theObject.Tag, status, viewName)
Catch ex As NXException
Return Nothing
End Try
If status = 0 Then Return Nothing ' it is a model mode object

Dim viewTag As Tag = Nothing
theUfSession.View.AskTagOfViewName(viewName, viewTag)
Dim viewType As Integer = Nothing
Dim viewSubtype As Integer = Nothing
theUfSession.View.AskType(viewTag, viewType, viewSubtype)
If viewType = 0 Then Return Nothing ' it is view dependent in a modeling view

Dim drawingTag As Tag = Nothing
theUfSession.Draw.AskDrawingOfView(viewTag, drawingTag)
Return Utilities.NXObjectManager.Get(drawingTag) ' the drawing it is on!

End Function

Function ReportAnnotationSheetZone(ByVal theSheet As Drawings.DrawingSheet, ByVal theAnnotation As Annotations.Annotation) As NXJSheetZoneInfo

Dim info As New NXJSheetZoneInfo

Dim borderBuilder As Drawings.BordersAndZonesBuilder

If IsNothing(theSheet.BordersAndZones) Then
Return Nothing
End If

borderBuilder = theSession.Parts.Work.Drafting.BordersAndZonesObjects.CreateBordersAndZonesBuilder(theSheet.BordersAndZones)

Dim numHorizontalZones As Integer = (theSheet.Length - borderBuilder.LeftMargin - borderBuilder.RightMargin) / borderBuilder.HorizontalSize
Dim numVerticalZones As Integer = (theSheet.Height - borderBuilder.BottomMargin - borderBuilder.TopMargin) / borderBuilder.VerticalSize

'calculate zone wrt bottom left of drawing (ZoneOrigin.BottomLeft)
Dim Hcell As Double = (theAnnotation.AnnotationOrigin.X - borderBuilder.LeftMargin) / borderBuilder.HorizontalSize
Dim Vcell As Double = (theAnnotation.AnnotationOrigin.Y - borderBuilder.BottomMargin) / borderBuilder.VerticalSize

Hcell = Math.Ceiling(Hcell)
Vcell = Math.Ceiling(Vcell)

Dim theZoneOrigin As Drawings.BordersAndZonesBuilder.ZoneOrigin = borderBuilder.Origin
borderBuilder.Destroy()

Dim verticalLetterNum As Integer
Dim verticalLetter As Char

Dim horizontalNum As Integer

If theZoneOrigin = Drawings.BordersAndZonesBuilder.ZoneOrigin.BottomLeft Or theZoneOrigin = Drawings.BordersAndZonesBuilder.ZoneOrigin.TopLeft Then
'origin on left side
horizontalNum = Hcell
Else
'origin on right side
horizontalNum = numHorizontalZones - Hcell + 1
End If

If theZoneOrigin = Drawings.BordersAndZonesBuilder.ZoneOrigin.BottomLeft Or theZoneOrigin = Drawings.BordersAndZonesBuilder.ZoneOrigin.BottomRight Then
'origin on bottom
verticalLetterNum = Asc("A") + Vcell - 1
verticalLetter = Chr(verticalLetterNum)

Else
'origin on the top
verticalLetterNum = Asc("A") + numVerticalZones - Vcell
verticalLetter = Chr(verticalLetterNum)

End If

Dim theSheetNum As String = SheetNumber(theSheet)

info.Sheet = theSheetNum
info.VerticalZone = verticalLetter
info.HorizontalZone = horizontalNum

Return info

End Function

Function SheetNumber(ByVal theSheet As Drawings.DrawingSheet) As String

Dim sheetNum As Integer
Dim theSheetBuilder As Drawings.DrawingSheetBuilder = theSession.Parts.Work.DrawingSheets.DrawingSheetBuilder(theSheet)
sheetNum = theSheetBuilder.Number

theSheetBuilder.Destroy()

Return sheetNum.ToString

End Function

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module

Public Class NXJSheetZoneInfo

Private _sheet As String = ""
Public Property Sheet() As String
Get
Return _sheet
End Get
Set(ByVal value As String)
_sheet = value
End Set
End Property

Private _horizontalZone As String = ""
Public Property HorizontalZone() As String
Get
Return _horizontalZone
End Get
Set(ByVal value As String)
_horizontalZone = value
End Set
End Property

Private _verticalZone As String = ""
Public Property VerticalZone() As String
Get
Return _verticalZone
End Get
Set(ByVal value As String)
_verticalZone = value
End Set
End Property

Public Sub New()

End Sub

End Class

Thank you very much for your health. I finally got the result I wanted. there is another responsibility if you can support it. is it possible to transfer a tabular note on the drawing page?