I have a master table in one word document.
First column of the table has keys. I have to create another table based upon the keys (rows) selected by the user.
The user can select a key (row) more than one time.
Table1:
TaskName Data Group
abc data1 group1
pqr data2 group2
lmn data3 group3
TaskName column is the key column, A user can select abc,pqr,abc,pqr,lmn
This should generate a table as follows:
TaskName Data Group
abc data1 group1
pqr data2 group2
abc data1 group1
pqr data2 group2
lmn data3 group3
I cannot use table.Cell().Range.Text
as by doing this formatting is lost.
I tried first using Word.Selection, but I could not figure out a way in which I can take one row at a time and copy paste it. It might be possible to do using Word.Selection.
The next thing I thought about was copy pasting a cell at a time, but Range Property keeps a hold of table cell structure. I looked into the Word Model and tried to find out if there is some kind of termination character after every row to distinguish it as end of row. There is such a character but it's for all the cells. To find this character out, click on the office button(besides Home), click on word options, click on display,in the section always show these formatting marks on the screen, tick show all formatting marks. This displays all the non-printable characters in a word document. This is the symbol you'll be able to see ยค.
This symbol holds the structural information of the cell and the exposed ANSI characters are 13 + 7. 13 is a paragraph mark and 7 is the "end-of-cell"marker. This holds further information that points to cell structure management in the file. In Word 2007 these two characters appear as one character, so what we need to do is drop this character from the cell's Range.
I created a list to hold all the cells that I need from the master Table.
After that the following code removes the last character from Range
The purpose was to obtain formatted text and by removing the character from each cell Range , we are able to point to only that particular cell's structure and not the whole tables.
If you try to run a loop with only formatted text property, you will get a table corrupt error. Hope this helps.