C# adding textbox to excel sheet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Anytime I try to add a textbox to my excel sheet in the following manner an
exception is generated.

Excel.Shape textbox;
textbox =
(Excel.Shape)excelWorksheet.Shapes.AddFormControl(Excel.XlFormControl.xlEditBox, cellx, celly, cellwidth, cellheight);

What am I doing wrong?
 
This worked for me, but it's in VB.. But I believe it shouldn't be too hard
to port to C#.


Dim xlApp As New Excel.Application
Dim xlWb As Excel.Workbook
Dim sht As Excel.Worksheet
Dim tb As Excel.OLEObject

xlWb = xlApp.Workbooks.Add
With xlWb.Sheets("Sheet1")
sht = xlWb.Worksheets("Sheet1")
tb = sht.OLEObjects.add(ClassType:="Forms.TextBox.1",
Link:=False, _
DisplayAsIcon:=False, Left:=120, Top:=48, Width:=132,
Height:=53.25)
End With

xlWb.SaveAs("C:\TEMP\Sample.xls")

xlWb.Close(False)
xlApp.Quit()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top