绿豆.Net

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
//=======
// 打印
//=======
function CTRL242_5::OnClick(eventObj)
{
 try
    {
  var ExcelApp = new ActiveXObject("Excel.Application");
  var ExcelBook = ExcelApp.WorkBooks.Add();
 }
 catch(e)
 {
     XDocument.UI.Alert("不能创建对象,权限太低,请在IE选项安全中‘本地intranet’自定义级别设置一下!");
  return;
 }
 
 var title = XDocument.DOM.selectSingleNode("//my:年度").text + XDocument.DOM.selectSingleNode("//my:班级名称").text + XDocument.DOM.selectSingleNode("//my:学期").text + "总分排名";
 
 ExcelApp.Visible=true;
 
    ExcelSheet = ExcelBook.WorkSheets.Add();
   
 ExcelSheet.name = title;
 ExcelApp.Caption = title;
 ExcelSheet.Cells(1,1).value = title;
 ExcelSheet.Cells(1,1).HorizontalAlignment = 3;
 ExcelSheet.Cells(1,1).Font.Size = 18;
 ExcelSheet.Cells(1,1).Font.Bold = true;
 ExcelSheet.Range("A1:M1").merge();
 
 var i=2;
 ExcelSheet.Cells(i,1).value = "姓名";
 ExcelSheet.Cells(i,2).value = "学号";
 ExcelSheet.Cells(i,3).value = XDocument.DOM.selectSingleNode("//my:课程1").text;
 ExcelSheet.Cells(i,4).value = XDocument.DOM.selectSingleNode("//my:课程2").text;
 ExcelSheet.Cells(i,5).value = XDocument.DOM.selectSingleNode("//my:课程3").text;
 ExcelSheet.Cells(i,6).value = XDocument.DOM.selectSingleNode("//my:课程4").text;
 ExcelSheet.Cells(i,7).value = XDocument.DOM.selectSingleNode("//my:课程5").text;
 ExcelSheet.Cells(i,8).value = XDocument.DOM.selectSingleNode("//my:课程6").text;
 ExcelSheet.Cells(i,9).value = XDocument.DOM.selectSingleNode("//my:课程7").text;
 ExcelSheet.Cells(i,10).value = XDocument.DOM.selectSingleNode("//my:课程8").text;
 ExcelSheet.Cells(i,11).value = "总分";
 ExcelSheet.Cells(i,12).value = "段名";
 ExcelSheet.Cells(i,13).value = "排名";
 ExcelSheet.Rows(i).HorizontalAlignment = 3;
 
 var curNodes = XDocument.DOM.selectNodes("//my:学生表");
 var leng = curNodes.length;
 
 i = 3;
 for(var n=0;n<leng;n++)
 {
     ExcelSheet.Cells(i,1).value = curNodes[n].selectSingleNode("my:姓名").text;
  ExcelSheet.Cells(i,2).value = curNodes[n].selectSingleNode("my:统一编号").text;
  ExcelSheet.Cells(i,3).value = curNodes[n].selectSingleNode("my:成绩1").text;
  ExcelSheet.Cells(i,4).value = curNodes[n].selectSingleNode("my:成绩2").text;
  ExcelSheet.Cells(i,5).value = curNodes[n].selectSingleNode("my:成绩3").text;
  ExcelSheet.Cells(i,6).value = curNodes[n].selectSingleNode("my:成绩4").text;
  ExcelSheet.Cells(i,7).value = curNodes[n].selectSingleNode("my:成绩5").text;
  ExcelSheet.Cells(i,8).value = curNodes[n].selectSingleNode("my:成绩6").text;
  ExcelSheet.Cells(i,9).value = curNodes[n].selectSingleNode("my:成绩7").text;
  ExcelSheet.Cells(i,10).value = curNodes[n].selectSingleNode("my:成绩8").text;
  ExcelSheet.Cells(i,11).value = curNodes[n].selectSingleNode("my:总分").text;
  ExcelSheet.Cells(i,12).value = curNodes[n].selectSingleNode("my:段名").text;
  ExcelSheet.Cells(i,13).value = curNodes[n].selectSingleNode("my:排名").text;
  
  ExcelSheet.Rows(i).HorizontalAlignment = 3;
  
  i++;
 }
 
 // 设置边框
 ExcelSheet.Range("A2:M" + (i-1)).Borders.LineStyle = 1;
      
 ExcelBook.Sheets("sheet1").Delete;
 ExcelBook.Sheets("sheet2").Delete;
 ExcelBook.Sheets("sheet3").Delete;
}
posted on 2008-11-18 15:51  杜军  阅读(510)  评论(0编辑  收藏  举报