这个取决于你单元格中的值是什么,比如就是True和False的字符串,你就判断字符串就行
比如是0,1,要1的时候就选中,可以参考下面的代码
DrawingObject
- class MyDrawingObjectProvider : IDrawingObjectProvider
- {
- public DrawingObject[] GetDrawingObjects(Worksheet sheet, int row, int column, int rowCount, int columnCount)
- {
- DrawingObject dobj;
- int value = -1;
- object obj = sheet.GetValue(row, column);
- if (obj != null)
- {
- if (obj is int) value = (int)obj;
- else
- {
- int.TryParse(obj.ToString(), out value);
- }
- if (value > 2) value = -1;
- }
-
- CheckBox control = new CheckBox() ;
- int intvalue = 0;
- if(obj!=null)
- int.TryParse(obj.ToString(),out intvalue);
- control.IsChecked = intvalue==1?true:false;
- control.Checked += new RoutedEventHandler((sender, args) => {
- sheet.SetValue(row, column, 1);
- });
- control.Unchecked += new RoutedEventHandler((sender, args) => {
- sheet.SetValue(row, column, 0);
- });
- dobj = new ControlDrawingObject(row, column, control);
- return new DrawingObject[] { dobj };
- }
- }
复制代码
应用
- public MainWindow()
- {
- InitializeComponent();
- ss.ActiveSheet.ColumnCount = 3;
- ss.ActiveSheet.RowCount = 3;
- ss.ActiveSheet.Cells[0, 0].Value = 1;
- ss.ActiveSheet.Cells[1,1].Value = 1;
- DrawingObjectManager.SetDrawingObjectProvider(ss, new MyDrawingObjectProvider());
-
- }
复制代码
|