SharePoint - How to export data view webpart to excel

Asked By kashish sinha on 28-Jun-12 06:16 AM

how to export the data view webpart contents to an excel sheet. the workaround i saw was a java script , but i am not sure as to where to use it and which is the  table id they mentioned in the java script in the following link . 

http://share-the-point.blogspot.in/2009/08/how-to-export-dataview-webpart-to-excel.html

Lalit M replied to kashish sinha on 28-Jun-12 07:25 AM
Use following JS to export Dataview Webpart data in a excel sheet.

// JS SCRIPT
<Script Language="Javascript">
function isIE()
// Function to Determine IE or Not
{
 return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}
function exportToExcel()
{
var isIEBrowser = isIE();
if(isIEBrowser== false)
{
 // This script works for IE. If browser is not IE throw alert
 alert('Please use Internet Explorer for Excel Export Functionality.');
 return false;
}
else
{
 var strTableID = "dataTable"; // 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 != 3)
 objWorkSheet.Cells(intRowIndex+1,intColumnIndex+1) = detailsTable.rows(intRowIndex).cells(intColumnIndex).innerText;
 }
}
 objExcel.Visible = true;
 objExcel.UserControl = true;
}
}
</Script>

 // CALL A JS FUNCTION ON A BUTTON CLICK
<button onclick="exportToExcel();">Export to Excel</button>
kashish sinha replied to Lalit M on 28-Jun-12 08:15 AM
where exactly should i use this javascript
kashish sinha replied to Lalit M on 02-Jul-12 05:13 AM
The first half works, like when i try to export from firefox the error alert comes up. which excel sheet should i look into. the second half doesn work for me i guess