Problem getting the content of a table cell using ole object in powerbuilder

S

sergio

Hi all,

I have a document with a table, and I need to get the content off a
cell to later paste it in a RichTextEdit control. The problem is that
I don't want the borders of the cell, I just need the content.


I have the beginning of the cell marked with a bookmark called "TEXT"


Plan A:
Here is the code for the first thing I thought,


ole_1 = CREATE OLEObject


ole_1.ConnectToNewObject("Word.Application.8")


ole_1.Application.Visible = false


//Get the document
ole_1.Application.Documents.Add (ls_filename)


//Copy cell
if ole_1.ActiveDocument.Bookmarks.Exists( "TEXT" ) then
ole_1.ActiveDocument.Bookmarks.Item ("TEXT").Select
ole_1.Application.Selection.SelectCell
ole_1.Application.Selection.Copy
ole_1.ActiveDocument.Close(0)
end if


//Paste the content of the cell into a blank document and then
insertdocument onto the RichTextEdit Control.
ole_1.Application.Documents.Add()
ole_1.Application.Selection.PasteAndFormat(5)
ole_1.ActiveDocument.SaveAs(ls_new_filename)
ole_1.ActiveDocument.Close(0)
rte_1.InsertDocument (ls_new_filename, True, FileTypeDoc!)
FileDelete (ls_new_filename)


PasteAndFormat (5): This function will paste the content of the
cell
without borders and It works perfect. For a moment I thought that I
have had the solution, but I realize that if I insert a table inside
the cell I want to copy, BOOM!!!, does not work. Argument (5) is
wdSingleCellText. Have tried passing all other arguments with no
luck.


Plan B:


Added a new bookmark called "END" that will mark the end of the cell
content, that way I could select the content of the whole cell
without
having to select the cell wich carries the borders. Code for that
very
simple:


ole_1 = CREATE OLEObject


ole_1.ConnectToNewObject("Word.Application.8")


ole_1.Application.Visible = false


//Get the document
ole_1.Application.Documents.Add (ls_filename)


//Copy cell
if ole_1.ActiveDocument.Bookmarks.Exists( "TEXT" ) then
long ll_start, ll_end


ll_start = ole_1.ActiveDocument.Bookmarks.item("TEXT").Range.Start
ll_end =
ole_1.ActiveDocument.Bookmarks.item("END").Range.End
ole_1.ActiveDocument.Range(ll_start, ll_end).Select()
ole_1.Application.Selection.SelectCell
ole_1.Application.Selection.Copy
ole_1.ActiveDocument.Close(0)
end if


//Paste the content of the cell into a blank document and then
insertdocument onto the RichTextEdit Control.
ole_1.Application.Documents.Add()
ole_1.Application.Selection.PasteAndFormat(5)
ole_1.ActiveDocument.SaveAs(ls_new_filename)
ole_1.ActiveDocument.Close(0)
rte_1.InsertDocument (ls_new_filename, True, FileTypeDoc!)
FileDelete (ls_new_filename)
 
C

Cindy M.

Hi Sergio,
I have a document with a table, and I need to get the content off a
cell to later paste it in a RichTextEdit control. The problem is that
I don't want the borders of the cell, I just need the content.
The trick is to back up the range (or selection) to not include the
end-of-cell marker. When using a Range object, this means two
characters; when using the Selection object, it's one character. Look
at the MoveEnd method.

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 :)
 

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

Top