html - 使用 MSO 样式前缀格式化 word 页面

标签 html css ms-word asp-classic

I need to pre-format an MS page. Particularly fonts so that they are consistent with a website. MS seems to ignore at the very least the font-family MSO styles set.

我已经尝试过 !important 并将 word 文档保存为网页,编辑样式并使用我尝试在 word 页面上设置格式的原始 HTML 文件中的样式。

我的代码:

<style>
h1 {
    font-family:'Trebuchet MS', Arial, sans-serif!important;
    mso-fareast-font-family:"Trebuchet MS"!important;
    }

p { 
    font-family:"Arial",Helvetica,sans-serif!important;
    mso-fareast-font-family:"Arial"!important;
  }
</style>

<%
  Dim file
  file = "saveddocument.doc"

  With Response
        .Buffer = True
        .ContentType = "application/msword"
        .AddHeader "content-disposition", "inline; filename=" & file
        .Write "<h1>This text should be formatted as Trebuchet MS</h1>" _
             & "<p> This text should be formatted as Arial</p>"

        .Flush
        .End
  End With
%>

预期结果:

When MS Word is opened the h1 headings should be styled with the font Trebuchet MS and the p tags with Arial.

当前结果:

Defaulting to Times New Roman

我错过了什么?非常感谢任何帮助。

最佳答案

我的答案如下:

    Response.ContentType = "application/msword"
    Response.AddHeader "Content-Disposition", "attachment;filename=HelpFile.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/'>") 

我的代码中特别缺少 xmlns 代码,因此无法读取 css

将其添加到文档中确保了它的可读性并解决了我的字体格式问题。我希望这个答案可以帮助以后遇到类似情况的其他人。

关于html - 使用 MSO 样式前缀格式化 word 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57730280/

相关文章:

html - 如何使我的椭圆形带在 css 中有波浪?

javascript - 如何在运行时动态关注输入元素

css - 父级悬停时的不透明度正在转移到子菜单;如何使用 CSS 防止这种情况

javascript - DOM Javascript : creating an array just with elements that display something

javascript - Img 点击不起作用

javascript - 如何找出重叠的 DIV

javascript - 如何用GWT或HTML+CSS+JavaScript画对 Angular 线?

c#-4.0 - 使用互操作替换 Word 中页眉和页脚中的字段

ms-word - 是否有 Microsoft Graph MS Word API?

c# - 有没有办法在机器上没有word的情况下动态生成word文档