代码一:
<html>     
  <head>     
  <meta   http-equiv="Content-Type"   c>     
  <meta   name="GENERATOR"   c>     
  <meta   name="ProgId"   c>     
  <title>New   Page   1</title>     
  </head>     
  <body>     
  <Table   id="myData"   border=1   align=center>     
  <Tr   align=center>     
  <Td>表格转换</Td>     
  <Td>表格转换</Td>     
  <Td>表格转换</Td>     
  <Td>表格转换</Td>     
  </Tr>     
  <Tr   align=center>     
  <Td>表格转换</Td>     
  <Td>表格转换</Td>     
  <Td   align=right>表格转换</Td>     
  <Td>表格转换</Td>     
  </Tr>     
  <Tr   align=center>     
  <Td>表格转换</Td>     
  <Td>表格转换</Td>     
  <Td   align=right>表格转换</Td>     
  <Td>表格转换</Td>     
  </Tr>     
  <Tr   align=center>     
  <Td>表格转换</Td>     
  <Td>表格转换</Td>     
  <Td   align=right>表格转换</Td>     
  <Td>表格转换</Td>     
  </Tr>     
  </Table>     
  <center><input   type=button      value="转换成Wor     
  d文档"><script   language="vbscript">     
  Sub   buildDoc(theTemplate,intTableRows)     
  Dim   Table1     
  set   Table1   =   document.all.myData     
  row   =   Table1.rows.length     
  Set   objWordDoc   =   CreateObject(" Word.Document")     
  ObjWordDoc.Application.Visible=True     
  Dim   theArray(4,4)     
  'Redim   Preserve   theArray(4,row)     
  colnum   =   Table1.rows(1).cells.length     
  for   i=0   to   row-1     
  for   j=0   to   colnum-1     
  theArray(j+1,i+1)   =   Table1.rows(i).cells(j).innerHTML     
  next     
  next     
  intNumrows   =   4     
  objWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore("转换     
  后的表格")     
  objWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore("")     
  objWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore("")     
  Set   rngPara   =   objWordDoc.Application.ActiveDocument.Paragraphs(1).Range     
  With   rngPara     
  .Bold   =   True     
  .ParagraphFormat.Alignment   =   1     
  .Font.Name   =   "Arial"     
  .Font.Size   =   12     
  End   With     
  Set   rngCurrent   =   objWordDoc.Application.ActiveDocument.Paragraphs(3).Range     
  Set   tabCurrent   =   ObjWordDoc.Application.ActiveDocument.Tables.Add(rngCurrent     
  ,intNumrows,4)     
  for   i   =   1   to   colnum     
  objWordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.Inser     
  tAfter   theArray(i,1)     
  objWordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.Parag     
  raphFormat.alignment=1     
  next     
  tabRow   =   2     
  For   j   =   2   to   intNumrows     
  'ObjWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Borders.Enable     
  =False     
  objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(1).Range.     
  InsertAfter   theArray(1,j)     
  objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(1).Range.     
  ParagraphFormat.alignment=1     
  objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(2).Range.     
  InsertAfter   theArray(2,j)     
  objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(2).Range.     
  ParagraphFormat.alignment=1     
  objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(3).Range.     
  InsertAfter   FormatCurrency(theArray(3,j))     
  objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(3).Range.     
  ParagraphFormat.alignment=2     
  objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(4).Range.     
  InsertAfter   theArray(4,j)     
  'objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(4).Range     
  .InsertAfter   Chr(10)     
  objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(4).Range.     
  ParagraphFormat.alignment=1     
  tabRow   =   tabRow   +   1     
  Next     
  objWordDoc.Application.ActiveDocument.SaveAs   "tempSample.doc",   0,False,"",Tr     
  ue,"",False,False,False,   False,False     
  'objWordDoc.Application.printout()     
  End   Sub     
  </script>     
  </body>     
  </html>
   
代码二:
利用OLE對象   
   
  Option   Public   
  Option   Declare   
   
  '   WdGoToItem   Constants   
  Const   wdGoToLine%   =   3   
  Const   wdGoToLast%   =   -1   
   
  '   WdTableFormat   Constants   
  Const   wdTableFormatClassic2%   =   5   
   
  '   WdColorIndex   Constants   
  Const   wdAuto%   =   0   
  Const   wdBlack%   =   1   
  Const   wdBlue%   =   2   
  Const   wdBrightGreen%   =   4   
  Const   wdByAuthor%   =   -1   
  Const   wdDarkBlue%   =   9   
  Const   wdDarkRed%   =   13   
  Const   wdDarkYellow%   =   14   
  Const   wdGray25%   =   16   
  Const   wdGray50%   =   15   
  Const   wdGreen%   =   11   
  Const   wdNoHighlight%   =   0   
  Const   wdPink%   =   5   
  Const   wdRed%   =   6   
  Const   wdTeal%   =   10   
  Const   wdTurquoise%   =   3   
  Const   wdViolet%   =   12   
  Const   wdWhite%   =   8   
  Const   wdYellow%   =   7   
   
  '   WdParagraphAlignment   Constants   
  Const   wdAlignParagraphCenter%   =   1   
  Const   wdAlignParagraphLeft%   =   0   
  Const   wdAlignParagraphRight%=   2   
   
  Sub   Initialize   
   
  '   Set   the   Microsoft   Word   Object   
  Dim   varWrdApp   As   Variant   
  Set   varWrdApp   =   CreateObject(   "Word.Application"   )   
   
  '   Show   Word   
  varWrdApp.Visible   =   True   
   
  '   Add   a   new   document   
  varWrdApp.Documents.Add   
   
  '   Set   the   Word   Selection   
  Dim   varWrdSelection   As   Variant   
  Set   varWrdSelection   =   varWrdApp.Selection   
   
  '   Start   a   loop   to   create   sections   
  Dim   varWrdRange   As   Variant   
  Dim   varWrdTable   As   Variant   
  Dim   intPos   As   Integer   
  Dim   x   As   Integer   
  For   x%   =   1   To   5   '   loops   this   many   times   for   example's   sake   
   
  '   Find   the   end   of   the   Word   selection   
  intPos   =   varWrdSelection.End   
   
  '   Define   the   range   to   the   end   of   the   selection   and   add   a   new   table   
  Set   varWrdRange   =   varWrdApp.ActiveDocument.Range(   intPos,   intPos   )   
  Set   varWrdTable   =   varWrdApp.ActiveDocument.Tables.Add(   varWrdRange,   1,   1   )   '   simple   1   x   1   table   
  varWrdSelection.TypeText   "Heading   "   &   x%   
  With   varWrdTable   
  '   Set   the   shading   on   the   first   row   to   light   gray   
  .Rows(   1   ).Cells.Shading.BackgroundPatternColorIndex   =   wdGray25%   '   could   expand   to   multiple   rows   
  '   Bold   the   first   row   
  .Rows(   1   ).Range.Bold   =   True   
  '   Center   the   text   in   Cell   (1,1)   
  .Cell(   1,   1   ).Range.Paragraphs.Alignment   =   wdAlignParagraphCenter%   
  End   With   
   
  '   Put   the   cursor   at   the   end   of   the   selection   
  varWrdSelection.GoTo   wdGoToLine%,   wdGoToLast%   
   
  '   Add   text   to   document   
  Call   InsertLines(   varWrdSelection,   1)   
  varWrdSelection.TypeText   "Here's   line   one   of   Heading   "   &   x%   &   "'s   report."   
  Call   InsertLines(   varWrdSelection,   1)   
  varWrdSelection.TypeText   "Here's   line   two   of   Heading   "   &   x%   &   "'s   report."   
  Call   InsertLines(   varWrdSelection,   1)   
  varWrdSelection.TypeText   "Here's   line   three   of   Heading   "   &   x%   &   "'s   report."   
  Call   InsertLines(   varWrdSelection,   2)   
   
  Next   
   
   
  '   Delete   the   objects   
  Set   varWrdTable   =   Nothing   
  Set   varWrdRange   =   Nothing   
  Set   varWrdSelection   =   Nothing   
  Set   varWrdApp   =   Nothing   
   
  End   Sub   
   
  Sub   InsertLines(   varWrdSelection   As   Variant,   intNumLine   As   Integer   )   
   
  Dim   intCount   As   Integer   
   
  '   Insert   the   specified   number   of   blank   lines   
  For   intCount   =   1   To   intNumLine   
  varWrdSelection.TypeParagraph   
  Next   intCount   
   
  End   Sub

转载于:https://www.cnblogs.com/hannover/archive/2008/12/04/1347908.html

表单的内容用WORD形式保存相关推荐

  1. php判断表单修改内容,JavaScript判断用户是否对表单进行了修改的方法_javascript技巧...

    本文实例讲述了JavaScript判断用户是否对表单进行了修改的方法.分享给大家供大家参考.具体分析如下: 这段JS代码可以判断出用户是否对表单内容进行了修改,如果修改了表单,并退出浏览器,则会提醒用 ...

  2. JSP 表单request内容

    1. 表单request内容的获取 2. request.setCharacterEncoding("utf-8")对request内容进行编码 3. fullformreques ...

  3. Bootstrap4+MySQL前后端综合实训-Day08-PM【ajax获取表单标签内容、根据“栏目信息”添加“新闻信息”、新闻管理系统-项目展示】

    [Bootstrap4前端框架+MySQL数据库]前后端综合实训[10天课程 博客汇总表 详细笔记][附:实训所有代码] 目   录 ajax获取表单标签内容 ajax根据数据库加载select下来列 ...

  4. oracle无法减小列长度,中国港湾扩展表单分配时调整字段后保存时报错,无法正常维护表单定义...

    版本号: 7.0.4 业务场景(如下):中国港湾扩展表单分配时调整字段后保存时报错,无法正常维护表单定义 异常提示: 异常信息:添加业务实体的时候出错. 导致错误的应用程序或对象的名称:Generso ...

  5. 2021-10-15 验证form表单的内容是否已存在数据库

    验证form表单的内容是否已存在数据库 <template><el-dialog:visible.sync="dialogVisible"width=" ...

  6. php js获取表单内容,jquery form表单获取内容以及绑定数据_javascript技巧

    在日常开发的过程中,难免会用到form表单,我们需要获取表单的数据保存到数据库,或者拿到后台的一串json数据,要将数据绑定到form表单上,这里我写了一个基于jquery的,formHelp插件,使 ...

  7. Ajax提交form表单的内容,并判断是否提交成功,提交确认提示框,确认提交,取消,回退缓存的数据

    //保存按钮提交表单内容function submitForm(t) {//提交前把单选按钮选的值给上隐藏的hiddenvar VNeedRegister = $("input[name=' ...

  8. html表单存储功能,纯前端实现保存表单数据功能

    本文作者:IMWeb zzbozheng 未经同意,禁止转载 最近在用管理后台配置数据时,发现辛辛苦苦配置好的表单无缘无故地被覆盖,之后了解到由于我们都是在同一台开发机上做开发,难免会遇到其他同学做数 ...

  9. php表单验证内容不能为空,php校验表单检测字段是否为空的方法_PHP教程

    php校验表单检测字段是否为空的方法 这篇文章主要介绍了php校验表单检测字段是否为空的方法,涉及php验证表单的技巧,非常具有实用价值,需要的朋友可以参考下 本文实例讲述了php校验表单检测字段是否 ...

最新文章

  1. 谭浩强课后题之----输出10个数中最大的
  2. 音视频低延迟应用的四个技术实践
  3. (4) hibernate增删查改+批量操作+类似Mybatis动态sql
  4. cocoscreator editbox 只允许数字_《Cocos Creator游戏实战》做一个数字调节框
  5. rocksdb ubuntu c++源码编译测试
  6. ZZULIOJ 1118: 数列有序
  7. Java基础中的基础
  8. Fiddler的一系列学习瞎记3
  9. 【GIS开发者】(GISDeveloper) 11-14期 提供下载
  10. SQL注入漏洞解决心得
  11. linux系统双显卡切换显卡驱动,自动化系统Linux显卡驱动及BIOS设置笔记(NVIDIA/ATI)...
  12. 实验一、安卓开发环境基本配置实验
  13. 2014 年移动设备界面设计有哪些趋势?
  14. 容错性低是什么意思_容错率高是什么意思(容错率高还是低比较好)
  15. Python也有对象了哈哈哈哈哈哈嗝
  16. EMCC Vmware 安装82%出错
  17. 如何判断两个IP地址是不是同一个网段(超实用)
  18. 手机CPU与电脑CPU性能究竟相差多少?
  19. verilog学习五点经验分享 http://bbs.21ic.com/icview-402231-1-1.html
  20. 俞军PM12条军规+产品决策简单三步法

热门文章

  1. 最简版Seq2Seq的英法机器翻译实践和详细代码解释
  2. python 声音基频f0_音高和基频(Pitch and F0)
  3. python爬虫4.1模拟登录古诗词网并通过Cookie处理获取个人信息
  4. HDU 4966:GGS-DDU
  5. python提取word文件中的图片,并上传阿里云OSS,返回html图片标签
  6. 休闲食品战场竞争激烈,店宝宝:三只松鼠还能稳居第一吗?
  7. net start mysql无法启动请键入 NET HELPMSG 3523 已获得更多的帮助
  8. 8个零代码数据爬取工具,不会Python也能轻松爬数!(附教程)
  9. 众美集团携手行业伙伴 聚焦城镇创新与城市更新
  10. 微信小游戏存在的安全风险