Office関連

[Excel Services ECMAScript]jPrintAreaで埋め込んだブック部分のみを印刷する。

jQuery + jPrintAreaを利用して、埋め込んだExcelワークブック部分のみを印刷する方法を紹介します。
下記コードではGoogle Libraries APIを利用してjQueryを読み込んでいますが、バージョンを1.4にしている理由は特にありません。

※ ローカルサーバー上でテストした際には問題なく印刷できたのですが、当ブログ上(WordPress上)から印刷した際はなぜかキレイに出力されません。原因は未調査で、何か分かり次第対応する予定です。

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">google.load("jquery","1.4");</script>
<script type="text/javascript" src="http://r.office.microsoft.com/r/rlidExcelWLJS?v=1&kip=1"></script>
<script type="text/javascript">
    /* 
     * jPrintArea(http://www.designerkamal.com/jPrintArea/)にjsファイルが無かったので
     * Internet Archive(http://j.mp/rTnPBB)からコード取得
     */
    jQuery.jPrintArea = function(el) {
        var iframe = document.createElement('IFRAME');
        var doc = null;
        $(iframe).attr('style', 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;');
        document.body.appendChild(iframe);
        doc = iframe.contentWindow.document;
        var links = window.document.getElementsByTagName('link');
        for (var i = 0; i < links.length; i++) {
            if (links[i].rel.toLowerCase() == 'stylesheet') {
                doc.write('<link type="text/css" rel="stylesheet" href="' + links[i].href + '"></link>');
            }
            doc.write('<div class="' + $(el).attr("class") + '">' + $(el).html() + '</div>');
            doc.close();
            iframe.contentWindow.focus();
            iframe.contentWindow.print();
            //alert('Printing...'); thanks alex
            alert('印刷しています。');
            wait(1);
            document.body.removeChild(iframe);;
        }
    }
    
    $(document).ready(function() {
        $('#btnPrint').click(function(){$.jPrintArea('#myExcelDiv')});
    });
    var fileToken = "SD92A165759188B352!260/-7880906317294423214/";

    if (window.attachEvent) {
        window.attachEvent("onload", loadEwaOnPageLoad);
    } else {
        window.addEventListener("DOMContentLoaded", loadEwaOnPageLoad, false);
    }

    function loadEwaOnPageLoad() {
        var props = {
            uiOptions: {
                showGridlines: false,
                showRowColumnHeaders: false
            },
            interactivityOptions: { }
        };

        Ewa.EwaControl.loadEwaAsync(fileToken, "myExcelDiv", props, onEwaLoaded);
    }

    function onEwaLoaded(result) { }
</script>

<input type="button" id="btnPrint" value="印刷する"></input>
<div id="myExcelDiv" style="width: 600px; height: 500px"></div>




・印刷範囲を指定できるjavascript「jPrintArea」
http://www.skuare.net/2007/10/javascriptjprintarea.html

[Excel Services ECMAScript]JSON形式で取得したデータを元にグラフを描画する。前のページ

Accessible Explorerのダウンロード先次のページ

関連記事

  1. Office関連

    Google Calendar APIを使って日本の祝日を取得するVBAマクロ

    祝日の一覧を用意する必要があったので、Google Calendar …

  2. Office関連

    「クラシックスタイルメニュー」の誤検知?

    2013/07/16 追記:cx20さんにコメントで"Google…

  3. Office関連

    「文書のスタイル」を設定するWordマクロ

    Wordのオプション画面 → 文章校正 → Word のスペル チェッ…

  4. Office関連

    「印刷の向き」の変更を検知するExcelマクロ

    MSDNフォーラムに「「印刷の向き」の「縦」「横」ボタンがクリックされ…

  5. Office関連

    コマンドマクロ一覧(Word 2013 Customer Preview)

    Word 2013 CP版に組み込まれている「コマンドマクロ」のコマン…

  6. Office関連

    Office 2013 オンラインヘルプのリンクを集めてみました。

    新機能を把握するためにはヘルプを見るのが一番早い、というわけでOffi…

コメント

  1. この記事へのコメントはありません。

  1. この記事へのトラックバックはありません。

Time limit is exhausted. Please reload CAPTCHA.

※本ページはプロモーションが含まれています。

Translate

最近の記事

アーカイブ

PAGE TOP