ASP生成WORD后以页面视图打开文件

为了给朋友做一个系统,需要将数据的内容取出来生成固定格式的WORD文档,于是就写了程序导出成WORD文档,用的是WORD先导出标准格式的HTML文件,然后再改成ASP取数据。

<% Response.ContentType = "application/msword" 

response.AddHeader "content-disposition", "inline; filename=测试.doc" 

' 此处可添加变量处理等语句,如打开数据库获取记录集等。 
%> 



 

这个语句在ASP头部插入,是为了实现变成WORD下载并且不调用IE打开。

但是有个问题就是这种文件打开后是WEB模式,总觉得不像正统的WORD文档,在研究了导出的文件并百度了下后发现很简单只要在<w:WordDocument>...</w:WordDocument>之间加上 <w:View>Print</w:View>这句就行了。其实所有的HTML文件改过后都可以用WORD的视图模式打开,只要做以下两点就可以了。

1.更改<HTML>标签为

 

<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">


2.在<head>...</head>之间加入

 

!--[if gte mso 9]><xml>
 <o:DocumentProperties>

  <o:Author>MC SYSTEM</o:Author>
  <o:LastAuthor>MC SYSTEM</o:LastAuthor>
  <o:Revision>2</o:Revision>
  <o:TotalTime>1</o:TotalTime>
  <o:Created>2012-05-31T14:42:00Z</o:Created>
  <o:LastSaved>2012-05-31T14:42:00Z</o:LastSaved>
  <o:Pages>1</o:Pages>
  <o:Characters>5</o:Characters>
  <o:Company>MC SYSTEM</o:Company>
  <o:Lines>1</o:Lines>
  <o:Paragraphs>1</o:Paragraphs>
  <o:CharactersWithSpaces>5</o:CharactersWithSpaces>
  <o:Version>11.5606</o:Version>
 </o:DocumentProperties>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:View>Print</w:View>
  <w:SpellingState>Clean</w:SpellingState>
  <w:GrammarState>Clean</w:GrammarState>
  <w:PunctuationKerning/>
  <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
  <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
  <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
  <w:ValidateAgainstSchemas/>
  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
  <w:IgnoreMixedContent>false</w:IgnoreMixedContent>
  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
  <w:Compatibility>
   <w:SpaceForUL/>
   <w:BalanceSingleByteDoubleByteWidth/>
   <w:DoNotLeaveBackslashAlone/>
   <w:ULTrailSpace/>
   <w:DoNotExpandShiftReturn/>
   <w:AdjustLineHeightInTable/>
   <w:BreakWrappedTables/>
   <w:SnapToGridInCell/>
   <w:WrapTextWithPunct/>
   <w:UseAsianBreakRules/>
   <w:DontGrowAutofit/>
   <w:UseFELayout/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:LatentStyles DefLockedState="false" LatentStyleCount="156">
 </w:LatentStyles>
</xml><![endif]-->


注:另外要注意的就是WORD的表格里面不是以PX为单位而是百分比

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值