Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / VS Tools for Office / September 2008

Tip: Looking for answers? Try searching our database.

C# Accessor for Excel.Comment.Text ?????

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
EmmanuelE - 08 Nov 2006 00:25 GMT
I'm stumped.  How does one READ the text in an Excel.Range.Comment in C#?

There is a Text method which is used to set the value but I cannot find
anything for reading the text.  I tried Comment.ToString() but that throws an
exception.
Cindy M. - 08 Nov 2006 15:08 GMT
Hi =?Utf-8?B?RW1tYW51ZWxF?=,

> I'm stumped.  How does one READ the text in an Excel.Range.Comment in C#?
>  
> There is a Text method which is used to set the value but I cannot find
> anything for reading the text.  I tried Comment.ToString() but that throws an
> exception.

Yes, it's sneaky - that's the only polite term that occurs to me. Excel packs
the comments into a special kind of text box, meaning it's part of the Shapes
collection. Didn't you wonder why a Comment would have a Shape property :-)?

string s = WS.Comments[1].Shape.TextFrame.Characters(missing, missing).Text;

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)
EmmanuelE - 08 Nov 2006 16:16 GMT
Thanks, not very intuitive indeed!  However, I still have a problem...

TextFrame.Character(Type.Missing, Type.Missing).Text returns only the first
255 characters of my comments (for some reason "missing" was not defined so I
used Type.Missing assuming that was longhand for "missing").

I've tried Character(1, 500).Text and Characters(1, Type.Missing) and get
"-2146826273" - which is not my comment ;)

Very confusing.

> Hi =?Utf-8?B?RW1tYW51ZWxF?=,
>
[quoted text clipped - 17 lines]
> This reply is posted in the Newsgroup; please post any follow question or reply
> in the newsgroup and not by e-mail :-)
EmmanuelE - 08 Nov 2006 16:29 GMT
I figured it out!

Characters(start, length) accepts only values represented by 1 byte (and
cast to object, of course).  So, I have to test the length of my comment
using the Character.Count property and if longer than 256 characters, then I
have to make additional call(s) to Characters(s,l) and build the full comment
up that way.

The MSDN docs for this are aweful as usual!

Thanks for your help!

> Thanks, not very intuitive indeed!  However, I still have a problem...
>
[quoted text clipped - 28 lines]
> > This reply is posted in the Newsgroup; please post any follow question or reply
> > in the newsgroup and not by e-mail :-)
Cindy M. - 09 Nov 2006 14:15 GMT
Hi =?Utf-8?B?RW1tYW51ZWxF?=,

> I figured it out!
>  
[quoted text clipped - 3 lines]
> have to make additional call(s) to Characters(s,l) and build the full comment
> up that way.

Thanks very much for posting the solution :-)!

I was getting ready to suggest InvokeMember (late-binding) or, as a last resort,
a VB.NET project with Option Strict Off so that you could access the object's
default property (s = Comment) the same way VBA does.

   Cindy Meister
abhimanyu - 04 Dec 2006 11:40 GMT
Instead of using a loop with TextFrame.Characters() you can get the
comment directly from Comment::Text() method.
       cell.Comment.Text(Type.Missing, Type.Missing, Type.Missing);
will return the full comment.
chandrakant - 22 Sep 2008 17:03 GMT
Hi  Abhimanyu

                       I tried following code but it is not working. Please
explain it briefly and add sample code

>Instead of using a loop with TextFrame.Characters() you can get the
>comment directly from Comment::Text() method.
>        cell.Comment.Text(Type.Missing, Type.Missing, Type.Missing);
>will return the full comment.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.