如果你使用 fpSpread1.ActiveSheet.AddSpanCell(0, 0, 4, 1); 合并单元格,那么选中一个合并范围时,只有左上角的单元格的 IsSelected = true,这种情况需要使用以下代码来获取任意一个单元格的 IsSelected 状态:
- private void Form2_Load(object sender, EventArgs e)
- {
- fpSpread1.ActiveSheet.AddSpanCell(0, 0, 4, 1);
- }
- private void button1_Click(object sender, EventArgs e)
- {
- int row = Convert.ToInt32(textBox1.Text);
- int col = Convert.ToInt32(textBox2.Text);
- CellRange cr = fpSpread1.ActiveSheet.GetSpanCell(row, col);
- bool selected = fpSpread1.ActiveSheet.IsSelected(row, col) || fpSpread1.ActiveSheet.IsSelected(cr.Row, cr.Column);
- MessageBox.Show(string.Format("Cells({0},{1}) IsSelected = {2}",row,col,selected));
- }
复制代码 |