If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Getting the format of a table
I have a situation where I create a table programmatically. I now want
to set the format of this table based on another table. I have code similar to the following: object oformat = (object)oldTable.AutoFormatType; newTable.AutoFormat(ref oformat, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); As you can see, getting the format type of the old table is easy enough. But how do I get the other properties, ie Apply Border, Apply Shading, Apply Font etc from the oldTable? (These are the parameters to the AutoFormat method). Eg something like oldTable.Format.ApplyBorder NB: I cannot copy and paste the table, and then write cell by cell as this has performance implications. Therefore, I create the table contents in text, convert the text to a table and then I want to simply get the table format from the old table to apply it to the new table. |
#2
|
|||
|
|||
Getting the format of a table
Hi Mystery,
Version of Word? From what I can see, you'd need to apply the AutoFormat, then compare the settings of the two tables. Then apply the AutoFormat again with these settings. Since you're having to do this, may one assume this is a document a user will have been working with? What guarantee do you have the user won't have made manual adjustments to the auto formatting? I have a situation where I create a table programmatically. I now want to set the format of this table based on another table. I have code similar to the following: object oformat = (object)oldTable.AutoFormatType; newTable.AutoFormat(ref oformat, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); As you can see, getting the format type of the old table is easy enough. But how do I get the other properties, ie Apply Border, Apply Shading, Apply Font etc from the oldTable? (These are the parameters to the AutoFormat method). Eg something like oldTable.Format.ApplyBorder NB: I cannot copy and paste the table, and then write cell by cell as this has performance implications. Therefore, I create the table contents in text, convert the text to a table and then I want to simply get the table format from the old table to apply it to the new table. Cindy Meister INTER-Solutions, Switzerland http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004) 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 :-) |
#3
|
|||
|
|||
Getting the format of a table
Thanks Cindy
The version of Word is 2000 and above. How can I compare the settings of these two tables programmatically. If I had access to these properties, then all would be solved. No, the user does not modify the document. This happens all behinds the scene. The user is simply presented with the end result. Cindy M -WordMVP- wrote in message news:VA.00009cd8.01470355@speedy... Hi Mystery, Version of Word? From what I can see, you'd need to apply the AutoFormat, then compare the settings of the two tables. Then apply the AutoFormat again with these settings. Since you're having to do this, may one assume this is a document a user will have been working with? What guarantee do you have the user won't have made manual adjustments to the auto formatting? I have a situation where I create a table programmatically. I now want to set the format of this table based on another table. I have code similar to the following: object oformat = (object)oldTable.AutoFormatType; newTable.AutoFormat(ref oformat, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); As you can see, getting the format type of the old table is easy enough. But how do I get the other properties, ie Apply Border, Apply Shading, Apply Font etc from the oldTable? (These are the parameters to the AutoFormat method). Eg something like oldTable.Format.ApplyBorder NB: I cannot copy and paste the table, and then write cell by cell as this has performance implications. Therefore, I create the table contents in text, convert the text to a table and then I want to simply get the table format from the old table to apply it to the new table. Cindy Meister INTER-Solutions, Switzerland http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004) 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 :-) |
#4
|
|||
|
|||
Getting the format of a table
Hi Mystery,
The version of Word is 2000 and above. That precludes using Table Styles, then. How can I compare the settings of these two tables programmatically. If I had access to these properties, then all would be solved. You have the original table you want to match; you have the second table formatted with the "default" AutoFormat. You compare each of the possible things that could be affected and see if they match. If they don't, the option was different. If the borders are different, then ApplyBorders must have been "false" when the original table was formatted. If the font formatting of the first columns is different (bold vs. non-bold, usually), then ApplyFirstColumn was "false" for the original table. Etc. No, the user does not modify the document. This happens all behinds the scene. The user is simply presented with the end result. If that's the case, then why don't you already know what AutoFormat was used on the original table? Cindy Meister INTER-Solutions, Switzerland http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004) 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 :-) |
#5
|
|||
|
|||
Getting the format of a table
Thanks Cindy
You have the original table you want to match; you have the second table formatted with the "default" AutoFormat. You compare each of the possible things that could be affected and see if they match. If they don't, the option was different. I apolgise if its a really dumb question, but how do I programatically get access to the following properties in the original table: ApplyBorders ApplyShading ApplyFont ApplyColor ApplyHeadingRows ApplyLastRow ApplyFirstColumn ApplyLastColumn AutoFit I have checked the object model and no property is obvious to me. The property AutoFormatType simply returns a WdTableFormat. This would only be the first parameter in the call to the AutoFormat method when setting up the new table. Thanks for your patience Cindy M -WordMVP- wrote in message news:VA.00009ce3.00568af7@speedy... Hi Mystery, The version of Word is 2000 and above. That precludes using Table Styles, then. How can I compare the settings of these two tables programmatically. If I had access to these properties, then all would be solved. You have the original table you want to match; you have the second table formatted with the "default" AutoFormat. You compare each of the possible things that could be affected and see if they match. If they don't, the option was different. If the borders are different, then ApplyBorders must have been "false" when the original table was formatted. If the font formatting of the first columns is different (bold vs. non-bold, usually), then ApplyFirstColumn was "false" for the original table. Etc. No, the user does not modify the document. This happens all behinds the scene. The user is simply presented with the end result. If that's the case, then why don't you already know what AutoFormat was used on the original table? Cindy Meister INTER-Solutions, Switzerland http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004) 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 :-) |
#6
|
|||
|
|||
Getting the format of a table
Hi Mystery Man
The macro recorder is very useful for learning about this kind of thing. Tools Macros Record New Macro. Try inserting and formatting a table, and then inspect the code that Word creates. In particular, look for code like the following: With Selection.Tables(1) With .Borders(wdBorderLeft) .LineStyle = wdLineStyleSingle .LineWidth = wdLineWidth050pt .Color = wdColorAutomatic End With End With Hope this helps. Shauna Kelly. Microsoft MVP. http://www.shaunakelly.com/word "Mystery Man" wrote in message m... Hi Cindy (or anyone else) Sorry to keep asking, but how do I programatically get access to the following properties in a table: ApplyBorders ApplyShading ApplyFont ApplyColor ApplyHeadingRows ApplyLastRow ApplyFirstColumn ApplyLastColumn AutoFit I have checked the object model and no property is obvious to me. Thanks (Mystery Man) wrote in message om... Thanks Cindy You have the original table you want to match; you have the second table formatted with the "default" AutoFormat. You compare each of the possible things that could be affected and see if they match. If they don't, the option was different. I apolgise if its a really dumb question, but how do I programatically get access to the following properties in the original table: ApplyBorders ApplyShading ApplyFont ApplyColor ApplyHeadingRows ApplyLastRow ApplyFirstColumn ApplyLastColumn AutoFit I have checked the object model and no property is obvious to me. The property AutoFormatType simply returns a WdTableFormat. This would only be the first parameter in the call to the AutoFormat method when setting up the new table. Thanks for your patience Cindy M -WordMVP- wrote in message news:VA.00009ce3.00568af7@speedy... Hi Mystery, The version of Word is 2000 and above. That precludes using Table Styles, then. How can I compare the settings of these two tables programmatically. If I had access to these properties, then all would be solved. You have the original table you want to match; you have the second table formatted with the "default" AutoFormat. You compare each of the possible things that could be affected and see if they match. If they don't, the option was different. If the borders are different, then ApplyBorders must have been "false" when the original table was formatted. If the font formatting of the first columns is different (bold vs. non-bold, usually), then ApplyFirstColumn was "false" for the original table. Etc. No, the user does not modify the document. This happens all behinds the scene. The user is simply presented with the end result. If that's the case, then why don't you already know what AutoFormat was used on the original table? Cindy Meister INTER-Solutions, Switzerland http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004) 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 :-) |
#7
|
|||
|
|||
Hi Mystery,
Sorry to keep asking I apologize: "real life" took me away from the groups for quite a while... do I programatically get access to the following properties in a table: You can't access what was applied or not applied using AutoFormat (although I'd think that, since you programmatically insert all the tables you'd KNOW that, and could save the information somewhere to look up later). But what you can do is compare the actual formatting of the existing table and see if it matches the formatting of a table inserted with all the defaults. Does it have the same border colors? Same shading? Same font formattting? If not, then the first was inserted with that aspect set to "False". Cindy Meister INTER-Solutions, Switzerland http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004) 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 :-) |
#8
|
|||
|
|||
Thanks for the helpful suggestions of defining table behaviour with VBA.
I've been experimenting with the TableAutoFormat and discovered contention between style definitions and Table AutoFormat definitions. This new feature (Table Autoformat) bulldozes over styles. Thus, if I've set the header row with a Table Heading style defined as bold centered text, when I apply the TableTemplate, the first row bold setting in the TableAutoFormat toggles this attribute to not bold. Reveal formatting is willy-nilly: TableFormat defines the paragraph alignment as left. The paragraph style is defined as centered. Its centered. TableFormat defines the font style as Arial. But I can't get the Bold to stick. Selecting Clear Formatting in the Reveal Formatting pane (when the table is selected), formats all the cells to be the selected Table style- I can't get a paragraph or character style to display, but the paragaphs jump to 6 points above and below--I presume based on Normal paragraph style. I didn't set paragraph spacing in the Table AutoFormat, yet it pulled one out of somewhere. How to erase/squelch/remove Table AutoFormat from a table? I can figure out table to text, text to table--I want to know where to find--and alter-- the hidden attributes for an entire table? Reveal all formatting doesn't permit me to delete the table's AutoFormat setting--and "clear formatting" defaults to the AutoFormat which has hidden controls for paragraph spacing, special character formatting (i.e., empahsis on certain words). |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Newbie? Do I use Report or Query | John Egan | New Users | 11 | June 28th, 2004 08:31 PM |
DATABASE field table format - changes not saved over Citrix | Michael Matuszak | Mailmerge | 7 | June 26th, 2004 03:02 PM |
Data Table Format | Jim Chaney | Charts and Charting | 0 | June 4th, 2004 03:26 PM |
Table format changes after conditional mail merge | Cherie McClintock | Mailmerge | 3 | May 12th, 2004 09:56 AM |
Format Report Option missing from 2003 version -pivot table | misty | Worksheet Functions | 0 | March 8th, 2004 08:13 PM |