埋め込んだExcelワークブックのセルにデータを入力するコードです。
複数のセルにまとめて入力することも可能です。
<script type="text/javascript" src="http://r.office.microsoft.com/r/rlidExcelWLJS?v=1&kip=1"></script> <script type="text/javascript"> var fileToken = "SD92A165759188B352!265/-7880906317294423214/"; if (window.attachEvent) { window.attachEvent("onload", loadEwaOnPageLoad); } else { window.addEventListener("DOMContentLoaded", loadEwaOnPageLoad, false); } function loadEwaOnPageLoad() { var props = { uiOptions: { showGridlines: false, showRowColumnHeaders: false, selectedCell: "'Sheet1'!A1" }, interactivityOptions: { } }; Ewa.EwaControl.loadEwaAsync(fileToken, "myExcelDiv", props, onEwaLoaded); } function onEwaLoaded(result) { ewa = Ewa.EwaControl.getInstances().getItem(0); } function fnc1() { ewa.getActiveWorkbook().getActiveCell().getValuesAsync(0,getRangeValues,null); } function getRangeValues(asyncResult) { if (asyncResult.getCode() == 0) { alert(asyncResult.getReturnValue()[0][0]); } else { alert("Err:" + asyncResult.getDescription()); } } function fnc2() { var ary = new Array(); ary[0] = new Array(); ary[0][0] = "1234567"; ewa.getActiveWorkbook().getActiveCell().setValuesAsync(ary,setRangeValue,null); } function setRangeValue(asyncResult) { if (asyncResult.getCode() != 0) { alert("Err:" + asyncResult.getDescription()); } } function fnc3() { var ary = new Array(); ary[0] = new Array(); ary[1] = new Array(); ary[0][0] = "abc"; ary[0][1] = "def"; ary[0][2] = "ghi"; ary[1][0] = "jkl"; ary[1][1] = "mno"; ary[1][2] = "pqr"; ewa.getActiveWorkbook().getActiveSelection().setValuesAsync(ary,setRangeValues,null); } function setRangeValues(asyncResult) { if (asyncResult.getCode() != 0) { alert("Err:" + asyncResult.getDescription()); } } </script> <input type="button" value="値取得" onclick="fnc1();"></input><br> <input type="button" value="値入力" title="1セルのみ選択して実行" onclick="fnc2();"></input><br> <input type="button" value="値入力(複数セル)" title="2x3のセル範囲を選択して実行" onclick="fnc3();"></input> <div id="myExcelDiv" style="width: 400px; height: 150px"></div>
・Ewa.Range.getValuesAsync(format, callback, userContext)
http://msdn.microsoft.com/en-us/library/ee589012.aspx
・Ewa.Range.setValuesAsync(values, callback, userContext)
http://msdn.microsoft.com/en-us/library/ee588957.aspx
・Ewa.Workbook.getActiveSelection()
http://msdn.microsoft.com/en-us/library/ee660082.aspx
この記事へのコメントはありません。