Question

In my project, I use the .NET library npoi to create some Excel documents. If MS Office is installed, checkboxes and a combobox with the MS interop Excel DLL will be added. Because different Excel sheets will be created with different column weights, the left and the top values in the code below should be dynamic:

//Top value of the first checkbox
double top = 68;

for (int i = 6; i <= rowcount; i++)
{
    Microsoft.Office.Interop.Excel.OLEObject obj2 = objs.Add("Forms.CheckBox.1",
    System.Reflection.Missing.Value,
    System.Reflection.Missing.Value,
    false,
    false,
    System.Reflection.Missing.Value,
    System.Reflection.Missing.Value,
    1055, //static left value
    top,  //static top value
    10,
    10);

    top += 15.43;
    top -= 1.0295;
}

Microsoft.Office.Interop.Excel.OLEObject combobox = objs.Add("Forms.ComboBox.1",
    System.Reflection.Missing.Value,
    System.Reflection.Missing.Value,
    false,
    false,
    System.Reflection.Missing.Value,
    System.Reflection.Missing.Value,
    1080, //static left value
    27,   //static top value
    50,
    15);

I have tried to get the left and the top value from the excel cells, but I can't find a way to do that. Does anyone know a way to get these two values dynamically from the cell?

Was it helpful?

Solution

Because I have found no answer for this question. I have made it now in another way.

I have created a template xls file which contains vba code. This code create the combobox and the checkboxes while the worksheet start.

Because of this new way Excel Interop is no longer needed. NPOI creates the excel sheets now from the template.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top