[Help] HTML with Excel using Javascript

Well it’s my first time in this forum and here I go…Need help.

My problem is: I have a web application in HTML who need interact with a local excel sheet for show some excel data like a comment.

Images to show how I need:

I’m not a programmer, but use javascript (must be any code) for your simplicity (aparently). If someone have a solution, or have one efficient code…please!!! Contact me!!!

Below a code for start…

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title>Teste de Excel através do Javascript</title>
<link rel="stylesheet" type="text/css" href="style.css" />

<script type="text/javascript" src="js/boxOver.js"></script>
<script type="text/javascript" src="js/GetData.js"></script>

<!-- // Here a Javascript function who "catch" data and put in "div1"

function GetData(cell,row){
 var excel = new ActiveXObject("Excel.Application");
 var excel_file = excel.Workbooks.Open("C:\\\\aria.xlsx");
 var excel_sheet = excel.Worksheets("Plan1");
 var data = excel_sheet.Cells(cell,row).Value;
 document.getElementById('div1').innerText =data;
 } -->

</head>
<body>

 <div id="header"> </div>


<table
width="50"
 height="50"
 border="4"
 cellpadding="10"
 bgColor="white" class="adjust_table">

<!-- os dados da planilha são capturados por GetData e passados através de "div1". Deveria aparecer depois de Boxes -->
<!-- Ao passar o mouse deveria aparecer "1801 - ...." -->

 <tr><td align="center" bgcolor="#FFFFFF"> <div id="div1" > </div>
 <a href="#" onMouseOver="GetData(2,1);" /><text="" title="" header= [] body=[ ] fade=[on]");"/>1801</a></td></tr>

<!-- Ao passar o mouse deveria aparecer "1701 - .... " -->

 <tr><td align="center" bgcolor="#EFEFEF"> <div id="div1" > </div>
 <a href="#" onMouseOver="GetData(3,1);" /><text="" title="" header=[] body=[ ] fade=[on]);">1701</a></td></tr>

</table>

</body>
</html> 

Nobody? I don’t believe! Where are the javascript genious? hehehe

The answer and author credit!

<html>
<head>

<!–All development credits to enhzflep –>

<title>Get data from excel sheet</title>
<script language=“javascript” >
var excelApp=null, excelFile=null, excelSheet=null;
var filename = “C:\\Users\\enhzflep\\Documents\\Book2.xlsx”;

function initExcel(filename)
{
excelApp = new ActiveXObject(“Excel.Application”);
excelFile = excelApp.Workbooks.Open(filename);
excelSheet = excelApp.Worksheets(‘Sheet1’);
}

function myShutdownExcel()
{
excelApp.Quit();
excelApp=null;
excelFile=null;
excelSheet=null;
}

function myGetData(column, row)
{
return excelSheet.Cells(column, row).Value;
}

function byId(e) {return document.getElementById(e);}

function myOnLoad2()
{
var numRows = 5, numCols = 7;
var tBody = byId(‘dataTableBody’);
var rowIndex, colIndex, curVal;
var curRow, curCell, curCellText;
initExcel(filename);

for (rowIndex=1; rowIndex<=numRows; rowIndex++)
{
curRow = document.createElement(‘tr’);
for (colIndex=1; colIndex<=numCols; colIndex++)
{
curVal = myGetData(rowIndex, colIndex);
curCell = document.createElement(‘td’);
curCell.setAttribute(‘title’, ‘The value of cell [’ + rowIndex + ‘,’ + colIndex +']
is: ’ + curVal);
curCellText = document.createTextNode(curVal);
curCell.appendChild(curCellText);
curRow.appendChild(curCell);
}
tBody.appendChild(curRow);
}
myShutdownExcel();
}
</script>
<style>
table
{
border: solid 1px #555;
}
td
{
width: 32px;
border: solid 1px #aaa;
}
</style>

</head>
<body onload=“myOnLoad2();”>
<b>Get data from excel sheets</b>
<table id=‘dataTable’>
<tbody id=‘dataTableBody’>
</tbody>
</table>
</body>
</html>

Hi ZecaPOA,

Sorry you didn’t get a timely response to your question.

This really isn’t a great solution I’m afraid, ActiveX controls are IE only and frowned upon.
All excel file processing should definitely happen on the server-side, you’ll want to allow upload of an excel document, parse it saving what you need in a database so that you can process it.

If you want to go down that path post something in one the server-side forums like PHP.

Hi Mark,

Thank you for your feedback.

I decided to share the code because it was the fruit of the effort and dedication from a developer friend who spent their time and intelligence to help me.

Perhaps this little code will help others, as I searched for help for two months and only got now. I saw hundreds of questions as my unsolved.

My application will run local (maybe in a site, I don’t decide), on a desktop. The solution that I could hardly solves my problem, but if you have a better solution I would rate coded.

I’m waiting to be code.

Very grateful.