0

When I execute this progammatically, I get a table with row heights much larger than when I do this manually.

Note : Sel is the Word.Selection object and the Clipboard contains an Excel Table.

       public void AddClipboard()
        {
            Sel.PasteExcelTable(false,false, false);
            var t = Sel.Tables[Sel.Tables.Count];
            t.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
        }
2
Contributors
2
Replies
14
Views
11 Months
Discussion Span
Last Post by PerplexedB
0

Just a note. I've seen the printer selected to influence formatting and cell width/height. So there's that.
If I was working this I'd use the following call to see what the height was on good and bad table.
https://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.cell.height(v=office.11)

If the height is set to auto, then it's possible that won't show until the display is refreshed or the printer is selected.
You appear to know about Word and how it's WYSIWYG is not set in stone. That is, it changes with each printer we print to. Some think that's a bug but that's how it works.

A call to set the printer for the doc and repaginate is not unusual to see how it will look on this printer.

0

Many thanks. But I solved the problem. See the new version below. Sel.set_Style(App.ActiveDocument.Styles["No Spacing"]);did the trick for me. In fact by default the style inserts a linefeed. By changing the style, I succeeded in suppressing this linefeed and the table comes out nicely.

        public void AddClipboard()
        {
            Sel.PasteExcelTable(false,false, false);
            var t = Sel.Tables[Sel.Tables.Count];
            t.Range.Select();           
            Sel.set_Style(App.ActiveDocument.Styles["No Spacing"]);
            t.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
            Doc.Paragraphs.Add().Range.Select();
            Sel.set_Style(App.ActiveDocument.Styles["No Spacing"]);
            Sel.TypeText("\n");
        }

Edited by PerplexedB

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.