Hello,
I have a problem when I import the content of excel files. I adapted the code of Laurent Seiler from http://www.ariscommunity.com/comment/16050#comment-16050.
My code:
function openExcelFile()
{
var selFile = Dialogs.getFilePath("", 2010 (*.xlsx)|*.xlsx| Chart Files (*.xlc)|*.xlc| Worksheet Files (*.xls)|*.xls| Data Files (*.xlc;*.xls)|*.xlc; *.xls| All Files (*.*)|*.*||", "Context.getSelectedPath()", "Choose an excel file that should be parsed", 0);
if (selFile != null)
{
var excelReader = Context.getExcelReader(selFile[0].getData());
var data = parseExcelFile(excelReader);
return data;
}
return null;
}
function parseExcelFile(excelFile)
{
var data = [];
for (var i = 0; i < excelFile.getSheetCount(); i++) // This loop iterates through each sheet
{
var rows = excelFile.getSheetAt(i).getRows();
data[i] = [];
for (var j = 0; j < rows.length; j++) // This loop iterates through each filled row
{
var cells = rows[j].getCells();
data[i][j] = [];
for (var k = 0; k < cells.length; k++) // This loop iterates through each filled cell
{
data[i][j][k] = cells[k].getCellValue();
}
}
}
return data;
}
It works fine for cell indexes below 16 but as soon as I try to access cell 16 it get the value of cell 17. When I access cell 17 I get the value of 16 and so on. Anyone got an idea what the mistake is?
Just for info: I tried this with several different excel files, each time with the same result.
I would be thankful for any help.
Regards Richard
Robert Goldenbaum on
Hi,
well, you only get the rows that are not empty - so it seems that somewhere a row is empty ? I use it like this:
while (g_oSheet.getCell(1 + lCount, 3) != null && g_oSheet.getCell(1 + lCount, 4) != null) {
Context.writeStatus("Importing line " + lCount);
asOutput[0] = 2 + lCount;
asOutput[1] = g_oSheet.getCell(1 + lCount, 3).getCellValue().toString();
asOutput[2] = g_oSheet.getCell(1 + lCount, 4).getCellValue().toString();
lCount++;
}
This should go through all rows until an empty cell is encountered in 3 or 4 in which case it breaks...
BR Robert