Add DVWP using SharePoint designer.
DVWP is binding data to MyTable. If your table name is different, please change the table name in the below script.
So that is the key to export data in to excel.
Open your page using browser.
Click Edit page.
Add content editor web part.
Now Edit content editor web part.
Click on "Source Editor.."
Copy below code and paste.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> | |
<html> | |
<head> | |
<script language="javascript"> | |
function ExportToExcel() { | |
var i; | |
var j; | |
var mycell; | |
var tableID = "MyTable"; | |
var objXL = new ActiveXObject("Excel.Application"); | |
var objWB = objXL.Workbooks.Add(); | |
var objWS = objWB.ActiveSheet; | |
for (i = 0; i < document.getElementById(tableID).rows.length; i++) { | |
for (j = 0; j < document.getElementById(tableID).rows(i).cells.length; j++) { | |
mycell = document.getElementById(tableID).rows(i).cells(j); | |
objWS.Cells(i + 1, j + 1).Value = mycell.innerText; | |
} | |
} | |
objWS.Range("A1", "Z1").Entirecolumn.AutoFit(); | |
objXL.Visible = true; | |
} | |
</script> | |
</head> | |
<body> | |
<a href="#" onclick="ExportToExcel(); return false;">Export To CSV</a> | |
</body> | |
</html> |