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>
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>