回复 1楼lh8350的帖子
你好,
ClearRange 方法不能排除 Locked Cell ,我想可以通过循环,逐一 Locked 单元格,判断该单元格是否被 Locked,逐一进行删除。
测试代码:
- private void button1_Click(object sender, EventArgs e)
- {
- int startrow = 0;
- int startcolumn = 0;
- int columncount = 3;
- int rowcount = 3;
- for (int i = startrow; i < rowcount; i++)
- {
- for (int j = startcolumn; j < columncount; j++)
- {
- if (!this.fpSpread1.Sheets[0].Cells[i, j].Locked)
- {
- this.fpSpread1.Sheets[0].ClearRange(i, j, 1, 1, false);
- }
- }
- }
- if (!this.fpSpread1.Sheets[0].Cells[0,0].Locked)
- {
- this.fpSpread1.Sheets[0].ClearRange(0, 0, 1, 1, false);
- }
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- //this.fpSpread1.Sheets[0].Cells[0, 0].Locked = true;
- //this.fpSpread1.Sheets[0].Rows[0].Locked = true;
- for (int i = 0; i < 10; i++)
- {
- this.fpSpread1.Sheets[0].Cells[0, i].Locked = true;
- }
- this.fpSpread1.Sheets[0].Cells[0, 0].Text = "fdasfdas";
- }
复制代码 |