【スクリプト】 読み取り専用のセルをスキップしたい
対象製品
SPREAD for .NET 2.5J Web Forms Edition
詳細
アクティブセルが移動する際にはonActiveCellChanging イベントが発生します。onActiveCellChanging イベントを使用し、移動後のセル読み取り専用属性を調べ、読み取り専用ではないセルにアクティブセルを設定することで、読み取り専用のセルをスキップすることが可能です。
なお、アクティブセルの設定はSetActiveCell メソッドを使用します。また、onActiveCellChanging イベント内で「event.cancel = true」とすることでアクティブセルの移動をキャンセルすることができます。
【JavaScript サンプルコード】
なお、アクティブセルの設定はSetActiveCell メソッドを使用します。また、onActiveCellChanging イベント内で「event.cancel = true」とすることでアクティブセルの移動をキャンセルすることができます。
【JavaScript サンプルコード】
<script language="javascript">
var clicked;
function window.onload(){
var spread = document.all("FpSpread1");
if ( spread != null ){
spread.onActiveCellChanging = CheckCell;
spread.onmousedown = ClickSpread;
}
}
function CheckCell(){
var spread = document.all("FpSpread1");
var cell = spread.GetCellByRowCol(event.row,event.col);
var r = spread.ActiveRow;
var c = spread.ActiveCol;
if(cell.FpCellType == "readonly"){
if (clicked == true){
//クリックによる移動はキャンセルします
event.cancel = true;
}
else{
if (r==event.row){
if (c==event.col-1){
//左から右に移動中
c = event.col;
while(cell != null && cell.FpCellType == "readonly"){
c = c + 1;
cell = spread.GetCellByRowCol(event.row,c);
}
}
else{
//右から左に移動中
c = event.col;
while(cell != null && cell.FpCellType == "readonly"){
c = c - 1;
cell = spread.GetCellByRowCol(event.row,c);
}
}
//既定のセル移動処理をキャンセルします
event.cancel = true;
if (cell != null){
spread.SetActiveCell(event.row,c);
}
}
else{
if (r==event.row-1){
//上から下に移動中
r = event.row;
while(cell != null && cell.FpCellType == "readonly"){
r = r + 1;
cell = spread.GetCellByRowCol(r,event.col);
}
}
else{
//下から上に移動中
r = event.row;
while(cell != null && cell.FpCellType == "readonly"){
r = r - 1;
cell = spread.GetCellByRowCol(r,event.col);
}
}
//既定のセル移動処理をキャンセルします
event.cancel = true;
if (cell != null){
spread.SetActiveCell(r,event.col);
}
else{
spread.SetActiveCell(spread.ActiveRow,event.col);
}
}
}
}
clicked = false;
}
function ClickSpread(){
clicked = true;
}
</script>
var clicked;
function window.onload(){
var spread = document.all("FpSpread1");
if ( spread != null ){
spread.onActiveCellChanging = CheckCell;
spread.onmousedown = ClickSpread;
}
}
function CheckCell(){
var spread = document.all("FpSpread1");
var cell = spread.GetCellByRowCol(event.row,event.col);
var r = spread.ActiveRow;
var c = spread.ActiveCol;
if(cell.FpCellType == "readonly"){
if (clicked == true){
//クリックによる移動はキャンセルします
event.cancel = true;
}
else{
if (r==event.row){
if (c==event.col-1){
//左から右に移動中
c = event.col;
while(cell != null && cell.FpCellType == "readonly"){
c = c + 1;
cell = spread.GetCellByRowCol(event.row,c);
}
}
else{
//右から左に移動中
c = event.col;
while(cell != null && cell.FpCellType == "readonly"){
c = c - 1;
cell = spread.GetCellByRowCol(event.row,c);
}
}
//既定のセル移動処理をキャンセルします
event.cancel = true;
if (cell != null){
spread.SetActiveCell(event.row,c);
}
}
else{
if (r==event.row-1){
//上から下に移動中
r = event.row;
while(cell != null && cell.FpCellType == "readonly"){
r = r + 1;
cell = spread.GetCellByRowCol(r,event.col);
}
}
else{
//下から上に移動中
r = event.row;
while(cell != null && cell.FpCellType == "readonly"){
r = r - 1;
cell = spread.GetCellByRowCol(r,event.col);
}
}
//既定のセル移動処理をキャンセルします
event.cancel = true;
if (cell != null){
spread.SetActiveCell(r,event.col);
}
else{
spread.SetActiveCell(spread.ActiveRow,event.col);
}
}
}
}
clicked = false;
}
function ClickSpread(){
clicked = true;
}
</script>
関連情報
キーワード
クライアント側スクリプト
この文書は、以前は次のFAQ IDで公開されていました : 9696