Forums:
Does anyone have experience with SpreadsheetManager in VB? I found an example for Python that works good when ran. When I looked it up in the API doc it appears that should work for opening both Native and Teamcenter Excel files. I can't seem to make it work in VB for either in my testing though.
Original Python Working Example (nx_api6227):
def readFile(self): try: xlsFile =self.theSession.SpreadsheetManager.OpenFile(self.xlsFileSpec, NXOpen.SpreadsheetManagerOpenMode.Read) self.theLW.Open()self.theLW.WriteLine("Reading: " + self.xlsFileSpec) if xlsFile: data =[]#ReadRange(worksheet, rowstart, colstart, rowend, colend) data = xlsFile.ReadRange(1,1,1,2,3) numData =len(data)self.theLW.WriteLine("Data Entries: " + str(numData))for i inrange(numData): cellType = data[i].Type info ="Data:" + str(i) + ", Type:" + str(cellType) if cellType == NXOpen.SpreadsheetCellDataTypes.Int: info +=" IntValue = " + str(data[i].IntValue)elif cellType == NXOpen.SpreadsheetCellDataTypes.Double: info +=" DoubleValue = " + str(data[i].DoubleValue)elif cellType == NXOpen.SpreadsheetCellDataTypes.Formula: info +=" FormulaValue = " + str(data[i].FormulaValue)elif cellType == NXOpen.SpreadsheetCellDataTypes.Logical: info +=" LogicalValue = " + str(data[i].LogicalValue)else: info +=" StringValue = " + str(data[i].StringValue) self.theLW.WriteLine(" " + info) except: self.reportException() finally: if xlsFile: xlsFile.CloseFile(False)
My VB Code:
Dim xlFileLocation AsString="C:\temp\test.xlsx"'xlFileLocation = "@DB/TEST/001" InfoWindow.WriteLine(xlFileLocation)Dim theSpreadSheetManager As SpreadsheetManager = theSession.SpreadsheetManagerDim xlsFile = theSpreadSheetManager.OpenFile(xlFileLocation, SpreadsheetManager.OpenMode.Read) InfoWindow.WriteLine(xlsFile.GetNumberofsheets&" Sheets found")IfNot IsNothing(xlsFile)ThenDim Data()As SpreadsheetCellData =Nothing'ReadRange(worksheet, rowstart, colstart, rowend, colend) Dim worksheet = xlsFile.GetWorksheetIndex("INSTRUCTIONS") xlsFile.ReadRange(worksheet, 1, 1, 2, 3, Data)Dim numData = Data.Length ForEach theData In Data Dim cellType = theData.Type'info = "Data:" + Str(i) + ", Type:" + Str(cellType) InfoWindow.WriteLine("in the data") NextEndIf