1

我的代码创建了一个 1 列 2 行的表。

然后,我的代码操作现有的行。我的目标是选择这两行并在 Word 中执行与这些手动命令等效的操作:Home -> Paragraph -> Line and Page breaks -> Keep Lines Together

问题是不Paragraphs p = wordApp.Selection.Paragraphs;返回任何段落

我需要获取和操作什么 Word Interop 对象才能将保持线一起应用于我的选择?

currentRow = imagesTable.Rows.First;

Cell ulCell = currentRow.Cells[1];

// Code to load cell with text

currentRow = currentRow.Next;

// Insert image
currentRow.Height = wordApp.InchesToPoints(5.5F);
currentRow.Cells[1].Select();

InlineShape inlineShape = wordApp.Selection.InlineShapes.AddPicture(imageAttachment.P_AttachmentFqfn);
inlineShape.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoTrue;
inlineShape.Height = wordApp.InchesToPoints(3F);

Cell lrCell = currentRow.Cells[1];

document.Range(ulCell.Range.Start, lrCell.Range.End).Select();

Paragraphs p = wordApp.Selection.Paragraphs;
p.KeepTogether = 1;
p.KeepWithNext = 1;
4

0 回答 0