Programmatically create checkboxes in c# in an excel spreadsheet

后端 未结 3 2138
无人及你
无人及你 2020-12-19 14:29

As part of a project I am working on, I a need to be able to create checkboxes inside an excel spreadsheet, could anyone provide a simple example or direct me to a useful re

3条回答
  •  心在旅途
    2020-12-19 15:27

    here is what I used for c#

    OLEObjects objs = worksheet.OLEObjects();
    OLEObject obj = objs.Add("Forms.CheckBox.1", System.Reflection.Missing.Value, System.Reflection.Missing.Value, false, false, System.Reflection.Missing.Value, System.Reflection.Missing.Value, cell.Left + 1, cell.Top + 1, cell.Width - 2, cell.Height - 2);
    obj.Object.Caption = "";
    if (text == "TRUE")
    {
        obj.Object.value = true;
    }
    else
    {
        obj.Object.value = false;
    }
    

    I used cell.Left + 1, cell.Top + 1, cell.Width - 2, cell.Height - 2 to maintain borders in four sides of the cell

提交回复
热议问题