Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping though nested tables

Status
Not open for further replies.

ehaze

Technical User
Oct 16, 2009
254
US
I'm trying to find a way to loop on a table within another table.

Layout is like this:
-Table
-Row
--Table
--Row
--Row
-Row
--Table
--Row

Using the script below, I can loop through the rows and export the data to Excel. But the nested tables are exported into a single cell in Excel.

How do get the data into Excel, and maintain the correct row layout?


<script type="text/javascript">
function isIE() // Function to Determine IE or Not
{
return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

function exportToExcel() // Function to Export the Table Data to Excel.
{
var isIEBrowser = isIE();
if(isIEBrowser== false)
{
alert('Please use Internet Explorer for Excel Export Functionality.');
return false;
}
else
{
var strTableID = "1x1x"; // It's the Table ID of Table in Webpart
var detailsTable = document.getElementById(strTableID);
var objExcel = new ActiveXObject("Excel.Application");
var objWorkBook = objExcel.Workbooks.Add;
var objWorkSheet = objWorkBook.Worksheets(1);

for (var intRowIndex=0;intRowIndex<detailsTable.rows.length;intRowIndex++)
{
for (var intColumnIndex=0;intColumnIndex<detailsTable.rows(intRowIndex).cells.length;intColumnIndex++)
{
if(intColumnIndex != 20)
objWorkSheet.Cells(intRowIndex+1,intColumnIndex+1) = detailsTable.rows(intRowIndex).cells(intColumnIndex).innerText;
}
}
objExcel.Visible = true;
objExcel.UserControl = true;
}
}
</Script>



 
I think you want this in the Javascript forum.

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top