DataExcel 设置单元格,列,行只读 ReadOnly属性


  ///清除所有行,列,合并单元格,扩展单元格,等
            dataexcel1.Clear();
            ///初始化默认行,列
            dataexcel1.Init();
             
            //获取行 通过GetRow函数获取行会自动创建行 
            IRow row = dataexcel1.GetRow(1);
            row.Height = 30; 
            row = dataexcel1.GetRow(2);
            //设置行只读
            row.InhertReadOnly = false;
            row.ReadOnly = true;
            row.BackColor = Color.AliceBlue;
            row.Height = 30;
            row = dataexcel1.GetRow(3);
            row.Height = 30;

            IColumn column = dataexcel1.GetColumn(1);
            column.Width = 120; 
            column = dataexcel1.GetColumn(2);
            //设置列只读
            column.InhertReadOnly = false;
            column.ReadOnly = true;
            column.Width = 120;
            column.BackColor = Color.AntiqueWhite;
            column = dataexcel1.GetColumn(3);
            column.Width = 120;
            column = dataexcel1.GetColumn(4);
            column.Width = 120;

            ICell cell = dataexcel1[1, 1];
            cell.Name = "name1";
            cell.Value = "只读单元格";
            //设置单元格只读
            cell.ReadOnly = true;
            cell.InhertReadOnly = false;

            cell = dataexcel1[2, 1];
            cell.Name = "name2";
            cell.Value = "只读单元格";
            //设置单元格只读
            cell.ReadOnly = true;
            cell.InhertReadOnly = false;


            cell = dataexcel1[3, 2];
            cell.Value = "只读列";


            cell = dataexcel1[2, 4];
            cell.Value = "只读行";




效果如图:





























猜你喜欢

转载自blog.csdn.net/zanfeng/article/details/76189428
今日推荐