Forum Discussion
simon_glet
12 years agoRegular Contributor
Azedding,
Ok so the file exists :-)
I copy-pasted the code at Working With Excel Files via COM and it worked just fine after creating the excel file. My tests were done with Excel already running with previously loaded files and with Excel not running before the test.
As far as comparing your code to:
function ReadDataFromExcel()
{
var Excel = Sys["OleObject"]("Excel.Application");
Excel["Workbooks"]["Open"]("C:\\MyFile.xls");
var RowCount = Excel["ActiveSheet"]["UsedRange"]["Rows"]["Count"];
var ColumnCount = Excel["ActiveSheet"]["UsedRange"]["Columns"]["Count"];
for (var i = 1; i <= RowCount; i++)
{
var s = "";
for (var j = 1; j <= ColumnCount; j++)
s = s + VarToString(Excel["Cells"](i, j)) + Chr(13) + Chr(10)
Log["Message"]("Row: " + VarToString(i), s);
}
Excel["Quit"]();
}
It is not necessary to activate the workbook and the way the cell value is fetched is different.
So please try to code above because I am starting to run out of ideas.
Sincerely
Ok so the file exists :-)
I copy-pasted the code at Working With Excel Files via COM and it worked just fine after creating the excel file. My tests were done with Excel already running with previously loaded files and with Excel not running before the test.
As far as comparing your code to:
function ReadDataFromExcel()
{
var Excel = Sys["OleObject"]("Excel.Application");
Excel["Workbooks"]["Open"]("C:\\MyFile.xls");
var RowCount = Excel["ActiveSheet"]["UsedRange"]["Rows"]["Count"];
var ColumnCount = Excel["ActiveSheet"]["UsedRange"]["Columns"]["Count"];
for (var i = 1; i <= RowCount; i++)
{
var s = "";
for (var j = 1; j <= ColumnCount; j++)
s = s + VarToString(Excel["Cells"](i, j)) + Chr(13) + Chr(10)
Log["Message"]("Row: " + VarToString(i), s);
}
Excel["Quit"]();
}
It is not necessary to activate the workbook and the way the cell value is fetched is different.
So please try to code above because I am starting to run out of ideas.
Sincerely