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