1

在 SharePoint2007 网站上,我创建了一个页面并插入了一个 DataView。我还插入了一个将 DataView 导出到 Excel 的按钮。这很好用,但是我想冻结第一行并设置自动过滤器,因为它们是列标题。如果我可以添加任何代码来实现这一点,请告诉我。

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

0 回答 0