ユーザーがテーブルをExcelにドラッグ/ドロップできるように、アプリケーションでテーブル要素を選択するために次を使用しています。
$('#footer').on("click", "#exportSel", function () {
var el = document.getElementById(curTable);
var body = document.body, range, sel;
if (document.createRange && window.getSelection) {
range = document.createRange();
var sel = window.getSelection ? window.getSelection() : document.selection;
if (sel) {
if (sel.removeAllRanges) {
sel.removeAllRanges();
} else if (sel.empty) {
sel.empty();
}
}
try {
range.selectNodeContents(el);
sel.addRange(range);
} catch (e) {
range.selectNode(el);
sel.addRange(range);
}
} else if (body.createTextRange) {
range = body.createTextRange();
range.moveToElementText(el);
range.select();
}
});
...そして、すべてが正常に機能しています。私のテーブルの1つが列に画像を持っていることを除いて、この列(またはその列のtd)を選択から削除したいと思います。
「Picture」td を「nosel」クラスに追加し、そのクラスにないテーブル内のすべての td を変数に入れることができました。
cells = $("#" + curTable + " tr td:not(.nosel)");
次に、現在の選択を削除または空にするコードを省略し、各セルを選択に追加しようとしました。
range.selectNode(cells[i]);
sel.addRange(range);
...しかし、最初の td のみが選択されています。
2つの質問:
これは可能ですか?
addRange よりも優れた方法はありますか? 拡張しようとしましたが、うまくいきませんでした。
要求に応じて、これが私のテーブルの例です。
<table class="sortable" id="resultsTable" border="1">
<thead id="resultsHeader">
<th>OID</th>
<th>Image</th>
<th>Address</th>
<th>Parcel ID</th>
</thead>
<tbody id="resultsBody" data-ssimplename="results">
<tr>
<td>1</td>
<td align="center" class="nosel"><img style="width: 125px;" src="http://www.vanderburghassessor.org/assessor_images/12/180/34/213/020/12-180-34-213-020-S.jpg"></td>
<td align="center">5830 N KERTH AVE</td>
<td align="center">82-06-04-034-213.020-020</td>
</tr>
</tbody>
</table>