Home > Mobile >  Modify a text box of an xlsm file from C# in Visual Studio
Modify a text box of an xlsm file from C# in Visual Studio

Time:10-21

I am trying to insert information into a text box (not a cell) inside an .xlsm file, but I have not been able to access its properties.

I have used this code here to try and access it, but I always get an error on the line in which I try to access.

private void button1_Click(object sender, EventArgs e)
{
    WorkBook workbook = WorkBook.LoadExcel("C://template//format.xlsm");
    WorkSheet sheet = workbook.WorkSheets.First();
    sheet["B11"].Value = "5";

    sheet.GetColumn("CX_4").Value = "11"; //<---TEXT BOX ERROR

    workbook.SaveAs(@"C://template"   "//" "XMLCopy" ".xlsm");
}

How could I access the Excel text box from C#?

CodePudding user response:

Given the name of the method is "GetColumn" I would assume you are passing an incorrect value of "CX_4".

From researching the methods in use I presume you are using the IronSoftware Excel API. Here is the spec for the method you are using: https://ironsoftware.com/csharp/excel/object-reference/api/IronXL.WorkSheet.html#IronXL_WorkSheet_GetColumn_System_String_

In case you aren't aware, this is a paid for SDK and there is a free alternative API supplied by Microsoft: https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/interop/how-to-access-office-onterop-objects

  • Related