Haley Bryson
Haley Bryson

Reputation: 11

Using JavaScript to Export to Excel and Filter/Frezze First Row - Sharepoint2007, DataView

On a SharePoint2007 site I have create a page and inserted a DataView. I have also inserted a button that will export the DataView to Excel. This works great, however I want to freeze the first row and set auto filters on since they are the column headers. Please let me know if there is any code I can add in to make this possible.

<Script Language="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 = "table1"; // 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;
  objWorkSheet.Cells(intRowIndex+1,intColumnIndex+1).Interior.ColorIndex="2";
 } 
}
objExcel.Visible = true;
objExcel.UserControl = true;
objExcel.Range("A1", "Z1").EntireColumn.AutoFit();
objExcel.Range("A1", "J1").Font.Bold = true;
objExcel.Range("A1", "J1").Interior.ColorIndex="20";
objExcel.Range("A1", "Z1").EntireColumn.WrapText = True;
objExcel.ActiveWorkBook.ActiveSheet.PageSetup.Orientation = 2;
objExcel.ActiveWorkBook.ActiveSheet.PageSetup.PaperSize = 5;
*objExcel.setAutoFilterRange("A1", "J1");
objExcel.Range("A1", "Z1").ActiveWindow.FreezePanes = True;*
}
}
</Script>


<P><button onclick="exportToExcel();">Export to Excel</button> 

Upvotes: 1

Views: 937

Answers (0)

Related Questions