PC Review


Reply
Thread Tools Rate Thread

C# adding textbox to excel sheet

 
 
=?Utf-8?B?U2t5S2lk?=
Guest
Posts: n/a
 
      7th Aug 2007
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?
 
Reply With Quote
 
 
 
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      8th Aug 2007
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?

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
REFRENCE A TEXTBOX ON A SHEET IN EXCEL 2000 Songoku Microsoft Excel Programming 5 23rd Jul 2008 04:02 PM
Loading data of a excel sheet or excel sheet format in Rich TextBox Control natrajsr@gmail.com Microsoft C# .NET 3 11th Sep 2006 07:23 PM
Adding shape-type textbox into excel chart sheet linsq2005@gmail.com Microsoft Excel Programming 2 20th Aug 2006 08:26 AM
Display a textbox embedded in the Excel sheet Tom Shi Microsoft Excel Programming 1 2nd Jun 2005 09:32 PM
Textbox on excel sheet do not update with VBA Ben Joiner Microsoft Excel Programming 4 6th Nov 2003 11:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:49 PM.