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

Recommended Answers

All 2 Replies

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.

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");
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.