Export to excel Sharepoint 2010 data view web part using Javascript without using any custom code.

Posted by Sagarp under Others category on | Points: 40 | Views : 15251
Description:This code use for Export to excel sharepoint 2010 data view web part.bind any list to dataview web part ,data view web part content export in excel without using any custom code.

function exportToExcel(strTableID ) // Function to Export the Table Data to Excel.


//var strTableID = "{B509589B-7F27-4638-B431-9458560F6870}-{G_AA5F8FE4_A574_4A79_BD96_BBCAB621737E}"; // It's the Table ID of Table in Webpart

var detailsTable = document.getElementById(strTableID);
var columns = detailsTable.getElementsByTagName("th");
var oExcel = new ActiveXObject("Excel.Application");
var oBook = oExcel.Workbooks.Add;
var oSheet = oBook.Worksheets(1);
oSheet.cells(1,i+1).value= columns[i].innerText; //XlSheetHeader[i];
oSheet.cells(1,i+1).columnwidth =20;
for (var y=0;y<detailsTable.rows.length;y++)
// detailsTable is the table where the content to be exported is
for (var x=0;x<detailsTable.rows(y).cells.length;x++)
oSheet.Cells(y+1,x+1) = detailsTable.rows(y).cells(x).innerText;

oExcel.Visible = true;
oExcel.UserControl = true;

Comments or Responses

Posted by: SheoNarayan on: 2/10/2011 Level:HonoraryPlatinum | Status: [Administrator] | Points: 10
Hi Sagar,

Thanks for the post, some explanations of your code shall add value. Just copy-paste code the code is hard to understand by readers.

Posted by: Sagarp on: 2/10/2011 Level:Bronze | Status: [Member] | Points: 10
hi Sheo Narayan ,

Thnaks to suggest i have update with description.
Posted by: Rajanishshukla on: 5/3/2012 Level:Starter | Status: [Member] | Points: 10
Hello Sagar,

This looks like an interesting post, but if you could provide some more information it would help.

I am not able to locate the Table id. Can you tell me how you got that. I am creating a new display form and inserting a dataview webpart. I get wep part id but not the table id.

Thanks for your help.

- Rajanish
Posted by: Whyme1025 on: 11/12/2013 Level:Starter | Status: [Member] | Points: 10
Hello Sagar,

I tried to find Table ID with IE and press F12 in HTML tab. but there is no luck.
would you please more explain on this?
Thank you.

Posted by: Aparna on: 3/5/2014 Level:Starter | Status: [Member] | Points: 10
I am not able to find Table ID. Can anyone please help me!!!

Login to post response