8.1.33
Trying to use File upload component to upload a excel file. Then I am trying to test out excel dataset read (I might when done put the read script inside the file upload component but currently just testing with script console while I figure out how I want to do script functions.)
So I have file upload that is saving file on gateway.
confirmed file is actually on the gateway
then in script console running this code that I found in forum
from org.apache.poi.ss.usermodel import WorkbookFactory as WorkbookFactory, DateUtil as DateUtil, Row, CellType
from java.io import FileInputStream
from java.util import Date
def excelToDataSet(fileName, hasHeaders = False, sheetNum = 0, firstRow = None, lastRow = None, firstCol = None, lastCol = None):
fileStream = FileInputStream(fileName)
wb = WorkbookFactory.create(fileStream)
sheet = wb.getSheetAt(sheetNum)
if firstRow is None:
firstRow = sheet.firstRowNum
if lastRow is None:
lastRow = sheet.lastRowNum
data = []
for i in range(firstRow , lastRow + 1):
row = sheet.getRow(i)
if i == firstRow:
if firstCol is None:
firstCol = row.firstCellNum
if lastCol is None:
lastCol = row.lastCellNum
else:
# if lastCol is specified add 1 to it.
lastCol += 1
if hasHeaders:
headers = list(row)[firstCol:lastCol]
else:
headers = ['Col'+str(cNum) for cNum in range(firstCol, lastCol)]
rowOut = []
for j in range(firstCol, lastCol):
if not (i == firstRow and hasHeaders):
cell = row.getCell(j,Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)
cellTypes = (cell.cellType,cell.cachedFormulaResultType if cell.cellType == CellType.FORMULA else None)
if CellType.NUMERIC in cellTypes:
if DateUtil.isCellDateFormatted(cell):
value = cell.dateCellValue
else:
value = cell.numericCellValue
if value == int(value):
value = int(value)
elif CellType.STRING in cellTypes:
value = cell.stringCellValue
elif CellType.BOOLEAN in cellTypes:
value = cell.booleanCellValue
elif CellType.BLANK in cellTypes:
value = None
else:
value = None
rowOut.append(value)
if len(rowOut) > 0:
data.append(rowOut)
fileStream.close()
return system.dataset.toDataSet(headers, data)
dataset= excelToDataSet('<U+202A>C:\IgnitionUploads\Loadsheet1.xlsx', hasHeaders = False, sheetNum = 5, firstRow = 3, lastRow = 5, firstCol = 1, lastCol = 4)
But getting this response
Java Traceback:
Traceback (most recent call last):
File "<input>", line 62, in <module>
File "<input>", line 6, in excelToDataSet
at java.base/java.io.FileInputStream.open0(Native Method)
at java.base/java.io.FileInputStream.open(Unknown Source)
at java.base/java.io.FileInputStream.<init>(Unknown Source)
at java.base/java.io.FileInputStream.<init>(Unknown Source)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Unknown Source)
at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.python.core.PyReflectedConstructor.constructProxy(PyReflectedConstructor.java:213)
java.io.FileNotFoundException: java.io.FileNotFoundException: âªC:\IgnitionUploads\Loadsheet1.xlsx (The filename, directory name, or volume label syntax is incorrect)
any ideas why it is failing to get the file?