国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 語(yǔ)言 > JavaScript > 正文

javascript操作excel生成報(bào)表示例

2024-05-06 16:05:26
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
最近做一個(gè)項(xiàng)目,用到j(luò)avascript操縱excel以生成報(bào)表,下面是標(biāo)有詳細(xì)注解的實(shí)例

復(fù)制代碼 代碼如下:


<html>

<head>
<script language="javascript" type="text/javascript">
function MakeExcel(){
var i,j;
    try {
      var xls    = new ActiveXObject ( "Excel.Application" );
     }
    catch(e) {
         alert( "要打印該表,您必須安裝Excel電子表格軟件,同時(shí)瀏覽器須使用“ActiveX 控件”,您的瀏覽器須允許執(zhí)行控件。 請(qǐng)點(diǎn)擊【幫助】了解瀏覽器設(shè)置方法!");
              return "";
     }

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

    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 

    <!--設(shè)置行高-->
    xlsheet.Rows(1).RowHeight = 25;
    <!--設(shè)置字體 ws.Range(ws.Cells(i0+1,j0), ws.Cells(i0+1,j1)).Font.Size = 13 -->
    xlsheet.Rows(1).Font.Size=14;
    <!--設(shè)置字體 設(shè)置選定區(qū)的字體  xlsheet.Range(xlsheet.Cells(i0,j0), ws.Cells(i0,j0)).Font.Name = "黑體" -->
    xlsheet.Rows(1).Font.Name="黑體";
    <!--設(shè)置列寬 xlsheet.Columns(2)=14;-->

    xlsheet.Columns("A:D").ColumnWidth =18;
     <!--設(shè)置顯示字符而不是數(shù)字-->
    xlsheet.Columns(2).NumberFormatLocal="@";
    xlsheet.Columns(7).NumberFormatLocal="@";


     //設(shè)置單元格內(nèi)容自動(dòng)換行 range.WrapText  =  true  ;
     //設(shè)置單元格內(nèi)容水平對(duì)齊方式 range.HorizontalAlignment  =  Excel.XlHAlign.xlHAlignCenter;//設(shè)置單元格內(nèi)容豎直堆砌方式
      //range.VerticalAlignment=Excel.XlVAlign.xlVAlignCenter
    //range.WrapText  =  true;  xlsheet.Rows(3).WrapText=true  自動(dòng)換行

    //設(shè)置標(biāo)題欄

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

     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類(lèi)容寫(xiě)到excel

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


    }
    <!--   xlsheet.Range(xls.Cells(i+4,2),xls.Cells(rowNum,4)).Merge; -->
    // 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;  //很重要,不能省略,不然會(huì)出問(wèn)題 意思是excel交由用戶控制
       xls=null;
       xlBook=null;
       xlsheet=null;

}

 


</script>  <link href="css/styles3.css" type="text/css"/>
<title>ziyuanweihu</title>
</head>
<body>
  <form method="post" action="/WebModule/admins/card/showcard.faces" enctype="application/x-www-form-urlencoded">

   

     

    <table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td><img src="images/jiao1.gif" /></td>
<td></td>
<td><img src="images/jiao2.gif" /></td>
</tr>
</tbody>
</table>           

 

     
    <table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td></td>
<td><table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td><input type="button" value="生成excel文件" /><input type="submit" value="返回" /></td>
</tr>
</tbody>
</table>
<table cellpadding="0" cellspacing="1">
<thead>
<tr>
<th scope="col"><span>卡号</span></th>
<th scope="col"><span>密码</span></th>
<th scope="col"><span>计费方式</span></th>
<th scope="col"><span>有效天数</span></th>
<th scope="col">金额</th>
<th scope="col"><span>所属服务项目</span></th>
<th scope="col"><span>发卡时间</span></th>
</tr>
</thead>
<tbody>
<tr>
<td>h000010010</td>
<td>543860</td>
<td>计点</td>
<td></td>
<td>2.0</td>
<td>测试项目</td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010011</td>
<td>683352</td>
<td>计点</td>
<td></td>
<td>2.0</td>
<td>测试项目</td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010012</td>
<td>433215</td>
<td>计点</td>
<td></td>
<td>2.0</td>
<td>测试项目</td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010013</td>
<td>393899</td>
<td>计点</td>
<td></td>
<td>2.0</td>
<td>测试项目</td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010014</td>
<td>031736</td>
<td>计点</td>
<td></td>
<td>2.0</td>
<td>测试项目</td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010015</td>
<td>188600</td>
<td>计点</td>
<td></td>
<td>2.0</td>
<td>测试项目</td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010016</td>
<td>363407</td>
<td>计点</td>
<td></td>
<td>2.0</td>
<td>测试项目</td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010017</td>
<td>175315</td>
<td>计点</td>
<td></td>
<td>2.0</td>
<td>测试项目</td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010018</td>
<td>354437</td>
<td>计点</td>
<td></td>
<td>2.0</td>
<td>测试项目</td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010019</td>
<td>234750</td>
<td>计点</td>
<td></td>
<td>2.0</td>
<td>测试项目</td>
<td>2006-06-23 10:14:40.843</td>
</tr>
</tbody>
</table>
</td>
<td></td>
</tr>
</tbody>
</table>

    <table cellpadding="0" cellspacing="0">
      <tbody>
        <tr>
          <td>
            <img src="images/jiao3.gif" />
          </td>
          <td>          </td>
          <td>
            <img src="images/jiao4.gif" />
          </td>
        </tr>
      </tbody>
    </table>
 <input type="hidden" value="fors" /></form>
</body>

</html>

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 茶陵县| 运城市| 同江市| 华安县| 梁河县| 莱西市| 北碚区| 巴中市| 呼玛县| 黑龙江省| 石家庄市| 镇平县| 天全县| 班玛县| 甘南县| 合作市| 观塘区| 贡嘎县| 江安县| 罗源县| 阿尔山市| 高台县| 乐山市| 武平县| 平昌县| 贡嘎县| 威宁| 集贤县| 永福县| 宽甸| 龙胜| 华安县| 萝北县| 页游| 金秀| 黄梅县| 离岛区| 伊春市| 隆安县| 丰宁| 通化市|