javaGrowing

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            92 隨筆 :: 33 文章 :: 49 評論 :: 0 Trackbacks
          function MakeExcel(){
          var i,j;
          ? ?try {
          ? ? ?var xls ? ?= new ActiveXObject ( "Excel.Application" );
          ? ? }
          ? ?catch(e) {
          ? ? ? ? alert( "要打印該表,您必須安裝Excel電子表格軟件,同時瀏覽器須使用“ActiveX 控件”,您的瀏覽器須允許執(zhí)行控件。 請點擊【幫助】了解瀏覽器設(shè)置方法!");
          ? ? ? ? ? ? ?return "";
          ? ? }

          ? ?xls.visible =true; ?//設(shè)置excel為可見

          ? ?var xlBook = xls.Workbooks.Add;
          ? ?var xlsheet = xlBook.Worksheets(1);
          ? ?
          ? ? ?xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(1,7)).mergecells=true;
          ? ? ?xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(1,7)).value="發(fā)卡記錄";
          ? ? // ?xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(1,6)).Interior.ColorIndex=5;//設(shè)置底色為藍(lán)色
          ? ? ? ? ? ? ? ?// ? xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(1,6)).Font.ColorIndex=4;//設(shè)置字體色 ? ? ? ?
          ? // xlsheet.Rows(1). Interior .ColorIndex = 5 ;//設(shè)置底色為藍(lán)色 ?設(shè)置背景色 Rows(1).Font.ColorIndex=4 ?

          ? ?
          ? ?xlsheet.Rows(1).RowHeight = 25;
          ? ?
          ? ?xlsheet.Rows(1).Font.Size=14;
          ? ?
          ? ?xlsheet.Rows(1).Font.Name="黑體";
          ? ?

          ? ?xlsheet.Columns("A:D").ColumnWidth =18;
          ? ?
          ? ?xlsheet.Columns(2).NumberFormatLocal="@";
          ? ?xlsheet.Columns(7).NumberFormatLocal="@";


          ? ? //設(shè)置單元格內(nèi)容自動換行 range.WrapText ?= ?true ?;
          ? ? //設(shè)置單元格內(nèi)容水平對齊方式 range.HorizontalAlignment ?= ?Excel.XlHAlign.xlHAlignCenter;//設(shè)置單元格內(nèi)容豎直堆砌方式
          ? ? ?//range.VerticalAlignment=Excel.XlVAlign.xlVAlignCenter
          ? ?//range.WrapText ?= ?true; ?xlsheet.Rows(3).WrapText=true ?自動換行
          ?
          ? ?//設(shè)置標(biāo)題欄

          ? ? xlsheet.Cells(2,1).Value="卡號";
          ? ? xlsheet.Cells(2,2).Value="密碼";
          ? ? xlsheet.Cells(2,3).Value="計費方式";
          ? ? xlsheet.Cells(2,4).Value="有效天數(shù)";
          ? ? xlsheet.Cells(2,5).Value="金額";
          ? ? xlsheet.Cells(2,6).Value="所屬服務(wù)項目";
          ? ? ? xlsheet.Cells(2,7).Value="發(fā)卡時間";

          ? ? var oTable=document.all['fors:data'];
          ? ? var rowNum=oTable.rows.length;
          ? ? for(i=2;i<=rowNum;i++){
          ? ? for (j=1;j<=7;j++){
          //html table類容寫到excel

          ? ? ? xlsheet.Cells(i+1,j).Value=oTable.rows(i-1).cells(j-1).innerHTML;
          ? ? ? ? ? ?}


          ? ?}
          ? ?
          ? ?// xlsheet.Range(xlsheet.Cells(i, 4), xlsheet.Cells(i-1, 6)).BorderAround , 4
          ? ? // for(mn=1,mn<=6;mn++) . ? ? xlsheet.Range(xlsheet.Cells(1, mn), xlsheet.Cells(i1, j)).Columns.AutoFit;
          ? ? ?xlsheet.Columns.AutoFit;
          ? ? ? ? ? ? ? ? xlsheet.Range( xlsheet.Cells(1,1),xlsheet.Cells(rowNum+1,7)).HorizontalAlignment =-4108;//居中
          ? ? ? ? ? ? ? ? ? xlsheet.Range( xlsheet.Cells(1,1),xlsheet.Cells(1,7)).VerticalAlignment =-4108;
          ? ? ? ? ? ? ? ? xlsheet.Range( xlsheet.Cells(2,1),xlsheet.Cells(rowNum+1,7)).Font.Size=10;

          ? ? ?xlsheet.Range( xlsheet.Cells(2,1),xlsheet.Cells(rowNum+1,7)).Borders(3).Weight = 2; //設(shè)置左邊距
          ? ? ? xlsheet.Range( xlsheet.Cells(2,1),xlsheet.Cells(rowNum+1,7)).Borders(4).Weight = 2;//設(shè)置右邊距
          ? ? ? ? ? ? xlsheet.Range( xlsheet.Cells(2,1),xlsheet.Cells(rowNum+1,7)).Borders(1).Weight = 2;//設(shè)置頂邊距
          ? ? ? xlsheet.Range( xlsheet.Cells(2,1),xlsheet.Cells(rowNum+1,7)).Borders(2).Weight = 2;//設(shè)置底邊距
          xls.UserControl = true; ?//很重要,不能省略,不然會出問題 意思是excel交由用戶控制
          ? ? ? xls=null;
          ? ? ? xlBook=null;
          ? ? ? xlsheet=null;

          }
          posted on 2006-11-09 21:24 javaGrowing 閱讀(634) 評論(0)  編輯  收藏 所屬分類: javascript
          主站蜘蛛池模板: 宕昌县| 绥化市| 万全县| 建始县| 恩施市| 左云县| 彩票| 辽中县| 临沂市| 铜鼓县| 年辖:市辖区| 监利县| 博白县| 齐河县| 临安市| 勃利县| 海宁市| 台东县| 来宾市| 蛟河市| 石景山区| 白水县| 涡阳县| 兴文县| 黔南| 紫阳县| 肥西县| 威信县| 永和县| 长春市| 泗阳县| 通山县| 金沙县| 安宁市| 揭西县| 临澧县| 宁陵县| 开封市| 虎林市| 镇宁| 德钦县|