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

 or register to reply.

Notify Moderator