3

我正在使用 OpenXml 将图像添加到 Word 文档。

我可以知道要添加的图像的大小,如果我愿意,我可以调整它的大小。但我真正想要的是仅在它比当前列宽时才调整它的大小。(就我而言,只有一列,但也许这可能会改变。)

有什么方法可以知道当前列的宽度,从而能够确保图像适合该列?事实上,大图像正在扩展页面之外。

4

1 回答 1

3

我已经更新了我的答案,因为这是涉及表格列的情况的答案,但问题中的单词column表示列或文本,而不是表中的列。

在文档中,您应该能够获得以下值:

// ...
var sectionProperties = body.GetFirstChild<SectionProperties>();
// pageSize contains Width and Height properties
var pageSize = sectionProperties.GetFirstChild<PageSize>();

// this contains information about surrounding margins
var pageMargin = sectionProperties.GetFirstChild<PageMargin>();

// this contains information about spacing between neighbouring columns of text
// this can be useful if You use page layout with multiple text columns
var columns = sectionProperties.GetFirstChild<Columns>();
var spaceBetweenColumns = columns.Space.Value;
var columnsCount = columns.ColumnCount.Value;

我没有对此进行测试,但我想您可以使用这些值计算文本列的实际宽度。

于 2014-01-31T22:00:30.603 回答