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関連

    PDFファイル上のフィールドの値を操作するVBAマクロ

    「PDFファイルに差し込み印刷するVBAマクロ」で、Acrobatを操…

  2. Office関連

    Office 365 unified APIをVBAから呼び出す

    前回の記事で、VBAからOffice 365 APIを呼び出す手順につ…

  3. Office関連

    UI Automationの参考資料

    VBAからUI Automationを扱う際に参考になりそうな資料への…

  4. アイコン一覧

    Office 365アイコン(imageMso)一覧(M)

    Office 365のデスクトップ版Officeアプリケーション(Wo…

  5. Office関連

    Google Docs APIを使ってGoogle ドキュメントを操作するVBAマクロ

    前回の記事で新しく追加されたGoogle Docs APIを紹介しまし…

  6. Office関連

    モヤさまのショウ君にいろいろ喋らせるVBAマクロ(1)

    「「VoiceText Web API」(β版) の提供を開始」にある…

コメント

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

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

Time limit is exhausted. Please reload CAPTCHA.

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

Translate

最近の記事

アーカイブ

PAGE TOP