【问题标题】:Change Absolute picture size in Word Doc using C#使用 C# 在 Word Doc 中更改绝对图片大小
【发布时间】:2018-08-13 20:56:36
【问题描述】:

我已将图片添加到 Word Doc 中:

var app = new Word.Application();
DocForPrint = app.Documents.Add();
Range docRange = DocForPrint.Range();
Word.InlineShape picShape = docRange.InlineShapes.AddPicture(imgPath);

现在我想像在 Word 编辑器中一样更改/设置它的 Absolute 大小

问题是我找不到它是否有属性,因为

picShape.Width = 50;

似乎是 pxl 大小。

你知道这是怎么做到的吗?

【问题讨论】:

  • 你有 Application.CentimetersToPoints(21.89) 方法吗?这是来自 VBA。

标签: c# ms-word docx


【解决方案1】:

由于 Word 是一个文字处理器,它使用的许多度量单位是 - 这是一种打印度量。幸运的是,Word 应用程序还提供了点、像素、厘米和英寸的转换功能。

Word.Document DocForPrint = wdApp.Documents.Add();
Word.Range docRange = DocForPrint.Content;
Word.InlineShape picShape = docRange.InlineShapes.AddPicture(imgPath);
picShape.Width = wdApp.CentimetersToPoints(21.89f);
picShape.Height = wdApp.CentimetersToPoints(15.6f); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-13
    • 2016-11-22
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 2012-12-05
    • 2015-12-24
    相关资源
    最近更新 更多