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 thep
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/