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()
--
Hope that helps.
Vergel Adriano
"SkyKid" wrote:
> 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?
|