1.怎样设置jsp生成word文档以页面视图来显示
1-apache的POI,此方法对Excel的导出做的很好,目前对Word的导出方面的功能尚未完全。
2-纯JavaScript脚本实现。主要通过客户端调用本机Office组件来实现。
3-在JSP页面引入头文件实现。纯JavaScript脚本实现细节方面大体是创建一个word组件ActiveXObject('Word.Application'),用js通过表ID取得表内容然后保存到word,要注意的是js实现有很多不好的地方,例如Internet选项需要把ActiveX空间全部启用,安全级别设置为中。
这样的话岂不是每台机器都要配置一下。其次每次生成word文档以后弹出对话框(无法保存此文件,因为它已在别处打开(C:\。
\STARTUP\Powerword.dot)),出现此问题就需要把C:\Documents and Settings\当前用户名\Application Data\Microsoft\Word\STARTUP下的Powerword.dot文件删除,每次遇到此问题就需要删除文件来解决,十分不方便。JSP页面引入来实现Word保存就方便多了,但是也有不足的地方,首先如果需要引入
接分,顺便贡献点想法。
第一,用IE 打开word,鼠标右键点 doc 文件,选 open with,选IE。
第二, <a href="a.doc" target="_blank">open a.doc </a>; 这样也是在IE 里打开word。
下面是我用的几种方法
<script language="javascript">
function openmydoc(){
var doc=new ActiveXObject("Word.Application");
doc.visible=true;
doc.Documents.Open("jsp学习笔记.doc");
}
</script>
</head>
<body>
<input type="button" value="ok" name="b1" onclick="openmydoc()" />
<a href="jsp学习笔记.doc" type="application/ms-word">;打开word </a>
<a href="worddocument.doc" target=_blank>clickme </a>
6.关于javascript操作word
js表单word常用操作1>tablesObj.Cell(行, 列).Split(1,3);//将某行某列单元格拆分成一行三列2>tablesObj.Cell(行,列).Merge(tablesObj.Cell(行,列));//合并某行某列到某行某列。
4>tablesObj = this.office.obj.ActiveDocument.Tables(1);//得到表格5> tablesObj.rows(fixlength+uselength+1).Borders(2).LineStyle=0;//左边虚线0,实线1,其中1 上 2左 3下 4右,常用于连续添加WORD表格的情况6> tablesObj.Rows(行).Delete();//删除行,注意:只有未合并列的情况下才能进行删除。7> tablesObj.Cell(行, 列) .Font.Name=”宋体” //字体设置,同样还有.Font.Size字体大小等。
8> tablesObj.Cell.ParagraphFormat.Alignment= align;//居中对齐希望对你有帮助。
7.如何用JavaScript打开WORD写入文本
必须用JS写吗?
你的 var text 能把内容存到这个text变量中
你可以在把这个变量传给Action或者Servlet中
然后通过输出流和FILE类 就能实现了
text变量在控制器中只定是汉字(String类型)
你给他转成字节类型的数组 就能用输出流了
我只能告诉你这个想法 我没理解你要写WORD 是不是纯JS写
不经过控制器。
补充回答:用我上面告诉你那思路就可以实现 就是JS只是负责把参数接过来传到控制器中并写入DOC文件 JAVA的代码 你要我能给你。
8.求大神指点
用jscript实现新建和保存一个word文档Demonstration script that retrieves network adapter data from a computer, displays that data in a Microsoft Word document, and then saves the document as C:\Scripts\Word\Testdoc.doc.复制代码 代码如下:Set objWord = CreateObject("Word.Application") objWord.Caption = "Test Caption" objWord.Visible = True Set objDoc = objWord.Documents.Add() Set objSelection = objWord.Selection objSelection.Font.Name = "Arial" objSelection.Font.Size = "18" objSelection.TypeText "Network Adapter Report" objSelection.TypeParagraph() objSelection.Font.Size = "14" objSelection.TypeText "" & Date() objSelection.TypeParagraph() objSelection.TypeParagraph() objSelection.Font.Size = "10" strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery _ ("Select * from Win32_NetworkAdapterConfiguration") For Each objItem in colItems objSelection.Font.Bold = True objSelection.TypeText "ARP Always Source Route: " objSelection.Font.Bold = False objSelection.TypeText "" & objItem.ArpAlwaysSourceRoute objSelection.TypeParagraph() objSelection.Font.Bold = True objSelection.TypeText "ARP Use EtherSNAP: " objSelection.Font.Bold = False objSelection.TypeText "" & objItem.ArpUseEtherSNAP objSelection.TypeParagraph() objSelection.Font.Bold = True objSelection.TypeText "Caption: " objSelection.Font.Bold = False objSelection.TypeText "" & objItem.Caption objSelection.TypeParagraph() objSelection.Font.Bold = True objSelection.TypeText "Database Path: " objSelection.Font.Bold = False objSelection.TypeText "" & objItem.DatabasePath objSelection.TypeParagraph() objSelection.Font.Bold = True objSelection.TypeText "Dead GW Detection Enabled: " objSelection.Font.Bold = False objSelection.TypeText "" & objItem.DeadGWDetectEnabled objSelection.TypeParagraph() objSelection.Font.Bold = True objSelection.TypeText "Default IP Gateway: " objSelection.Font.Bold = False objSelection.TypeText "" & objItem.DefaultIPGateway objSelection.TypeParagraph() objSelection.Font.Bold = True objSelection.TypeText "Default TOS: " objSelection.Font.Bold = False objSelection.TypeText "" & objItem.DefaultTOS objSelection.TypeParagraph() objSelection.Font.Bold = True objSelection.TypeText "Default TTL: " objSelection.Font.Bold = False objSelection.TypeText "" & objItem.DefaultTTL objSelection.TypeParagraph() objSelection.Font.Bold = True objSelection.TypeText "Description: " objSelection.Font.Bold = True objSelection.Font.Bold = False objSelection.TypeText "" & objItem.Description objSelection.TypeParagraph() objSelection.TypeParagraph() Next objDoc.SaveAs("C:\Scripts\Word\testdoc.doc") objWord.Quit。
转载请注明出处51数据库 » javascriptword
小孩哥哥