本帖最后由 江故里 于 2024-9-20 11:22 编辑
用的是 v11
spdList_Sheet1.Protect = false;
spdList_Sheet1.Cells[44, tsuikaKubunIndex].Locked = false;44行为上移行
private void spreadRowMove()
{
CellRange[] cellRanges = spdList_Sheet1.GetSelections();
if (cellRanges.Length <= 0)
return;
cellRanges = cellRanges.OrderBy(c => c.Row).ToArray();
CellRange cellRange = cellRanges[0];
int selectedRowIndexStart = cellRange.Row;
int selectedRowCount = cellRange.RowCount;
for (int i = 1; i < cellRanges.Length; i++)
{
CellRange c = cellRanges;
if (c.Row > selectedRowIndexStart + selectedRowCount)
{
int rowsBetweenRanges = c.Row - selectedRowIndexStart - selectedRowCount;
for (int j = 0; j < rowsBetweenRanges; j++)
{
if (spdList_Sheet1.Rows[selectedRowIndexStart + selectedRowCount].Visible == true)
return;
else
selectedRowCount = selectedRowCount + 1;
}
}
else
selectedRowCount = selectedRowCount + c.RowCount;
}
//一番下の行を選択する場合、処理なし
if (selectedRowIndexStart + selectedRowCount >= spdList_Sheet1.RowCount)
return;
//選択されている行の下の行番号を取得
int downVisibleRowIndex = -1;
for (int i = 0; i < spdList_Sheet1.RowCount - selectedRowIndexStart - selectedRowCount; i++)
{
if (spdList_Sheet1.Rows[selectedRowIndexStart + selectedRowCount + i].Visible == true)
{
downVisibleRowIndex = selectedRowIndexStart + selectedRowCount + i;
break;
}
else
selectedRowCount = selectedRowCount + 1;
}
if (downVisibleRowIndex == -1)
return;
//移動
spdList_Sheet1.MoveRow(downVisibleRowIndex, selectedRowIndexStart, 1, true);
spdList_Sheet1.ClearSelection();
spdList_Sheet1.ActiveRowIndex = selectedRowIndexStart + 1;
spdList_Sheet1.AddSelection(selectedRowIndexStart + 1, 0, selectedRowCount, spdList_Sheet1.ColumnCount);
isChange = true;
}
不走 spdList_Sheet1.MoveRow(downVisibleRowIndex, selectedRowIndexStart, 1, true);这句代码的话 tsuikaKubunIndex列当前单元格能够正常赋值 走了之后 locked = true; 值清空,再改回 locked =false 也无法赋值 |