<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    java隨記

    堅(jiān)持就是勝利!

     

    javascript 操作 excel 全攻略

    最近做一個(gè)項(xiàng)目,用到了javascript操縱excel以生成報(bào)表,下面是標(biāo)有詳細(xì)注解的實(shí)例

    ?


    <html>

    <head>
    <script language="javascript" type="text/javascript">


    </script><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類容寫到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" rel="stylesheet" type="text/css"/>
    <title>ziyuanweihu</title>
    </head>
    <body>
    ? <form id="fors" method="post" action="/WebModule/admins/card/showcard.faces" enctype="application/x-www-form-urlencoded">

    ???
    ?????
    ?????
    ?????
    ??? <table id="fors:top" border="0" cellpadding="0" cellspacing="0" width="100%">
    <tbody>
    <tr>
    <td class="left"><img src="images/jiao1.gif" alt="" /></td>
    <td class="topMiddle"></td>
    <td class="right"><img src="images/jiao2.gif" alt="" /></td>
    </tr>
    </tbody>
    </table>????????????
    ????????????
    ??
    ??????
    ??????
    ??? <table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tbody>
    <tr>
    <td class="middleLeft"></td>
    <td class="btstyle"><table id="fors:sort" border="0" cellpadding="0" cellspacing="0" style="valign:center" width="100%">
    <tbody>
    <tr>
    <td class="btstyle"><input type="button" name="fors:_id7" value="&#29983;&#25104;excel&#25991;&#20214;" onclick="MakeExcel()" /><input type="submit" name="fors:_id8" value="&#36820;&#22238;" /></td>
    </tr>
    </tbody>
    </table>
    <table id="fors:data" border="1" cellpadding="0" cellspacing="1" width="100%">
    <thead>
    <tr>
    <th scope="col"><span id="fors:data:headerText1">&#21345;&#21495;</span></th>
    <th scope="col"><span id="fors:data:headerText2">&#23494;&#30721;</span></th>
    <th scope="col"><span id="fors:data:headerText3">&#35745;&#36153;&#26041;&#24335;</span></th>
    <th scope="col"><span id="fors:data:headerText4">&#26377;&#25928;&#22825;&#25968;</span></th>
    <th scope="col">&#37329;&#39069;</th>
    <th scope="col"><span id="fors:data:headerText6">&#25152;&#23646;&#26381;&#21153;&#39033;&#30446;</span></th>
    <th scope="col"><span id="fors:data:headerText7">&#21457;&#21345;&#26102;&#38388;</span></th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td>h000010010</td>
    <td>543860</td>
    <td>&#35745;&#28857;</td>
    <td></td>
    <td>2.0</td>
    <td>&#27979;&#35797;&#39033;&#30446;</td>
    <td>2006-06-23 10:14:40.843</td>
    </tr>
    <tr>
    <td>h000010011</td>
    <td>683352</td>
    <td>&#35745;&#28857;</td>
    <td></td>
    <td>2.0</td>
    <td>&#27979;&#35797;&#39033;&#30446;</td>
    <td>2006-06-23 10:14:40.843</td>
    </tr>
    <tr>
    <td>h000010012</td>
    <td>433215</td>
    <td>&#35745;&#28857;</td>
    <td></td>
    <td>2.0</td>
    <td>&#27979;&#35797;&#39033;&#30446;</td>
    <td>2006-06-23 10:14:40.843</td>
    </tr>
    <tr>
    <td>h000010013</td>
    <td>393899</td>
    <td>&#35745;&#28857;</td>
    <td></td>
    <td>2.0</td>
    <td>&#27979;&#35797;&#39033;&#30446;</td>
    <td>2006-06-23 10:14:40.843</td>
    </tr>
    <tr>
    <td>h000010014</td>
    <td>031736</td>
    <td>&#35745;&#28857;</td>
    <td></td>
    <td>2.0</td>
    <td>&#27979;&#35797;&#39033;&#30446;</td>
    <td>2006-06-23 10:14:40.843</td>
    </tr>
    <tr>
    <td>h000010015</td>
    <td>188600</td>
    <td>&#35745;&#28857;</td>
    <td></td>
    <td>2.0</td>
    <td>&#27979;&#35797;&#39033;&#30446;</td>
    <td>2006-06-23 10:14:40.843</td>
    </tr>
    <tr>
    <td>h000010016</td>
    <td>363407</td>
    <td>&#35745;&#28857;</td>
    <td></td>
    <td>2.0</td>
    <td>&#27979;&#35797;&#39033;&#30446;</td>
    <td>2006-06-23 10:14:40.843</td>
    </tr>
    <tr>
    <td>h000010017</td>
    <td>175315</td>
    <td>&#35745;&#28857;</td>
    <td></td>
    <td>2.0</td>
    <td>&#27979;&#35797;&#39033;&#30446;</td>
    <td>2006-06-23 10:14:40.843</td>
    </tr>
    <tr>
    <td>h000010018</td>
    <td>354437</td>
    <td>&#35745;&#28857;</td>
    <td></td>
    <td>2.0</td>
    <td>&#27979;&#35797;&#39033;&#30446;</td>
    <td>2006-06-23 10:14:40.843</td>
    </tr>
    <tr>
    <td>h000010019</td>
    <td>234750</td>
    <td>&#35745;&#28857;</td>
    <td></td>
    <td>2.0</td>
    <td>&#27979;&#35797;&#39033;&#30446;</td>
    <td>2006-06-23 10:14:40.843</td>
    </tr>
    </tbody>
    </table>
    </td>
    <td class="middleRight"></td>
    </tr>
    </tbody>
    </table>

    ??? <table id="fors:bottom" border="0" cellpadding="0" cellspacing="0" width="100%">
    ????? <tbody>
    ??????? <tr>
    ????????? <td class="left">
    ??????????? <img src="images/jiao3.gif" alt=""/>
    ????????? </td>
    ????????? <td class="bottomMiddle">????????? </td>
    ????????? <td class="right">
    ??????????? <img src="images/jiao4.gif" alt=""/>
    ????????? </td>
    ??????? </tr>
    ????? </tbody>
    ??? </table>
    ?<input type="hidden" name="fors" value="fors" /></form>
    </body>

    </html>
    歡迎加入QQ群:30406099?

    posted on 2006-06-27 11:12 傻 瓜 閱讀(30347) 評(píng)論(18)  編輯  收藏 所屬分類: javascript

    評(píng)論

    # re: javascript 操作 excel 全攻略 2006-06-27 12:42 我心飛翔

    不錯(cuò)  回復(fù)  更多評(píng)論   

    # re: javascript 操作 excel 全攻略 2006-08-23 10:23 2

    2323  回復(fù)  更多評(píng)論   

    # re: javascript 操作 excel 全攻略 2007-01-28 16:41 mstu

    尋找中的,謝謝??!  回復(fù)  更多評(píng)論   

    # re: javascript 操作 excel 全攻略[未登錄](méi) 2007-03-16 14:45 vivi

    感謝提供^_^  回復(fù)  更多評(píng)論   

    # re: javascript 操作 excel 全攻略 2007-08-01 10:46 xin

    bucuo  回復(fù)  更多評(píng)論   

    # re: javascript 操作 excel 全攻略 2007-08-16 14:00 菜鳥先飛

    不錯(cuò),非常感謝

    請(qǐng)?jiān)賹懸黄瑯拥纳蓋ord的.  回復(fù)  更多評(píng)論   

    # re: javascript 操作 excel 全攻略 2008-08-28 11:02 predancompany@gmail.com

    直接將上面代碼放在一個(gè)html文件運(yùn)行是可以的,但是我放在j2ee的應(yīng)用中,并具改為.jsp文件,就不行了,不知道是什么原因,help me...........  回復(fù)  更多評(píng)論   

    # re: javascript 操作 excel 全攻略 2008-08-28 11:03 predancompany@gmail.com

    異常提示為下面的代碼:
    alert( "要打印該表,您必須安裝Excel電子表格軟件,同時(shí)瀏覽器須使用“ActiveX 控件”,您的瀏覽器須允許執(zhí)行控件。 請(qǐng)點(diǎn)擊【幫助】了解瀏覽器設(shè)置方法!");  回復(fù)  更多評(píng)論   

    # re: javascript 操作 excel 全攻略 2008-10-16 12:27 akchen

    學(xué)習(xí),IE沒(méi)問(wèn)題,不過(guò)Firefox 不支持,一定要用ActiveX方式嗎?討論下,呵呵(E-Mai:akchen@126.coml)  回復(fù)  更多評(píng)論   

    # re: javascript 操作 excel 全攻略 2008-12-18 11:13 流浪的貓

    這里有一個(gè)問(wèn)題,每導(dǎo)出一次,就打開一個(gè)EXCELE進(jìn)程!請(qǐng)問(wèn)這個(gè)問(wèn)題如何解決?  回復(fù)  更多評(píng)論   

    # re: javascript 操作 excel 全攻略 2008-12-23 16:53 hillhua

    不錯(cuò),拿用了!  回復(fù)  更多評(píng)論   

    # re: javascript 操作 excel 全攻略 2008-12-26 10:48 as

    那是因?yàn)镮E跟firefox調(diào)用控件函數(shù)不一樣,如果搞過(guò)ajax就應(yīng)該知道怎樣辦了  回復(fù)  更多評(píng)論   

    # re: javascript 操作 excel 全攻略 2008-12-26 10:49 as

    去掉xls.UserControl = true; 這一句就會(huì)在同一個(gè)excel進(jìn)程里打開  回復(fù)  更多評(píng)論   

    # re: javascript 操作 excel 全攻略 2009-07-29 15:44 lasuk

    看了幾篇文章,發(fā)現(xiàn)一個(gè)字都不差

    唉 ~

    在哪抄的都?  回復(fù)  更多評(píng)論   

    # re: javascript 操作 excel 全攻略 2009-08-03 12:36 fool

    發(fā)布了rss,會(huì)被其它的網(wǎng)站抓取的老大.  回復(fù)  更多評(píng)論   

    # re: javascript 操作 excel 全攻略 2009-08-03 12:40 fool

    放心,轉(zhuǎn)抄的我會(huì)注明出處的  回復(fù)  更多評(píng)論   

    # re: javascript 操作 excel 全攻略 2011-10-18 08:21 怒云

    關(guān)于事件的呢?怎么定義事件

    下面是我的代碼,本地腳本:

    var ExcelApp=new ActiveXObject("Excel.Application");
    var wb=ExcelApp.Workbooks.Add();
    ExcelApp.Visible=true;
    wb.BeforeClose=function (Cancel){
    WScript.Echo("Workbook was closing");
    }
    wb.Close();
    WScript.Sleep(3000)
    ExcelApp.Quit();
    可惜出錯(cuò)了。。。求正解  回復(fù)  更多評(píng)論   

    # re: javascript 操作 excel 全攻略 2015-03-18 10:06 416119174

    這個(gè)只能導(dǎo)出靜態(tài)的,我是動(dòng)態(tài)的,有記錄集,查詢記錄是分頁(yè)顯示的  回復(fù)  更多評(píng)論   


    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     

    導(dǎo)航

    統(tǒng)計(jì)

    常用鏈接

    留言簿(7)

    我參與的團(tuán)隊(duì)

    隨筆分類

    隨筆檔案

    文章分類

    友情鏈接

    搜索

    積分與排名

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 精品剧情v国产在免费线观看| 亚洲日韩AV一区二区三区四区| 午夜亚洲国产理论片二级港台二级| 国产精品高清全国免费观看| 亚洲黄色免费网址| 久久爰www免费人成| 亚洲2022国产成人精品无码区| 在线观看免费无码专区| 亚洲一区二区三区久久久久| 一区二区三区亚洲视频| 人妻丰满熟妇无码区免费| 亚洲1区2区3区精华液| 亚洲电影一区二区三区| 免费观看日本污污ww网站一区| 自拍偷自拍亚洲精品播放| 免费国产a国产片高清| 日本激情猛烈在线看免费观看| 亚洲人成网www| 亚洲国产成人爱av在线播放| 精品久久8x国产免费观看| 免费大片av手机看片| 亚洲国产成人精品青青草原| 久久国产成人精品国产成人亚洲| 一二三四免费观看在线视频中文版| 亚洲人成网站在线在线观看| 亚洲AV无码久久精品狠狠爱浪潮| 国产中文字幕免费观看| 91久久精品国产免费直播| 91成人免费观看在线观看| 亚洲人成网站影音先锋播放| 亚洲国产天堂久久综合| 毛片免费视频观看| 看Aⅴ免费毛片手机播放| 亚洲免费中文字幕| 亚洲爆乳无码专区| 国产日韩成人亚洲丁香婷婷| 成年女人喷潮毛片免费播放| 最近免费中文字幕mv电影| 亚洲欧洲日本在线观看| 亚洲日韩国产精品乱| 99久久久国产精品免费牛牛四川|