html - 使用 MSO 前缀调整图像属性

标签 html css asp-classic ms-office

I need to resize an image using Microsoft Office prefixes (MSO)
It's important to note that I am unable to use inline styles.

我已经使用 %px 尝试了 CSSHTML 版本,但没有显示规范这里:

img {
    display: block;
    width: 600;
    height: auto;
}

然而这些都没有效果。

我知道我很可能需要改用 MSO 前缀。虽然,我似乎找不到任何可以让我更改图像属性的东西。

预期结果:

Images are resized once sent to the word document

实际结果:

Images are not affected by any styling.

作为引用,我正在寻找的前缀类型与以下内容完全相同: https://gist.github.com/webtobesocial/ac9d052595b406d5a5c1

但只是具有更改图像而不是更改字体系列等的能力。
你知道我错过了什么吗?任何帮助深表感谢。

    <!-- /* Style Definitions */
    img {
         height: auto;
         max-width: 8.5in ;
    }
    @page firstSection{
      size:8.5in 11.0in; 
      margin:1.0in 1.25in 1.0in 1.25in ;
      mso-header-margin:.5in;
      mso-footer-margin:.5in; mso-paper-source:0;
      }
    -->

    Response.ContentType = "application/msword"
    Response.AddHeader "Content-Disposition","attachment;filename=documentName.doc" 
    Response.write("<html " & _ 
        "xmlns:o='urn:schemas-microsoft-com:office:office' " & _
        "xmlns:w='urn:schemas-microsoft-com:office:word'" & _ 
        "xmlns='https://www.w3.org/TR/html401/'>") 

    Response.Write "<!--[if mso]>" _
              & "<tr><td style='padding:0px;margin:0px;'>&nbsp;</td><td style='padding:0px;margin:0px;' width='560'>" _
              & "<![endif]-->"

    Response.Write"<!--[if gte mso]><xml><w:WordDocument> 
        <w:View>Print</w:View>" & _
        "<w:Zoom>90</w:Zoom><w:DoNotOptimizeForBrowser/></w:WordDocument></xml>" & _
        "<![endif]-->"

     <body lang=EN-US style='tab-interval:.5in'>
      <div class=Section1>
       <!--Printable Content is added here EG-->
       <img="/image/l60Hf.png"/>
      </div>
     </body>
    </html>

    Response.Write "<!--[if mso]></td><td style='padding:0px;margin:0px;'>&nbsp;</td></tr><tr>" _
              & "<td colspan='3' style='padding:0px;margin:0px;font-size:20px;height:20px;' height='20'>&nbsp;</td></tr></table>" _
              & "<![endif]-->"

最佳答案

对于将来寻找此答案的任何其他人来说,不幸的是解决方案是内联样式。

MSO不会接受 CSS图像上的属性。但是,您可以使用基本的 HTML属性:

width='640' height='400'

Microsoft Word 将实际收听的内容。唯一的缺点是它们必须在线。

Thus, in this scenario I used Replace() to edit any <img style= tags with: "<img style= width: 640px;'" width='640'

这解决了我在 word 中的大部分图像大小格式问题,我希望有一天这个答案对其他人有用。

关于html - 使用 MSO 前缀调整图像属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57790320/

相关文章:

javascript - 单击一次后如何禁用提交按钮

javascript - 尝试制作 CSS3 对 Angular 线滑动动画,但没有按预期工作

html - 在表中使用固定填充和百分比宽度

jquery - 显示/隐藏内容,从头开始显示第一个

javascript - ng-repeat - 一旦弹出,就无法推送

javascript - 当用户在屏幕上拖动/平移时 Canvas 清晰

html - 如何向所有HTML页面添加音频

iis - 经典 ASP - 请求对象为空

javascript - 如何使模态窗口的标题固定在顶部

sql - ADO 命令参数未传递到存储过程或存储过程 'Ignoring' 参数