您的位置:首页 > 编程语言 > ASP

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

2012-05-31 22:55 393 查看
为了给朋友做一个系统,需要将数据的内容取出来生成固定格式的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为单位而是百分比
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息