仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 708|回复: 6
打印 上一主题 下一主题

[学习教程] ASP.NET编程:在.net中操纵Word

[复制链接]
愤怒的大鸟 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 22:33:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
我实在想不明白java的机制,为什么非要那么蛋疼,在同一个平台下重复编译。word  要操纵Word,我们就必要Word的工具库文件“MSWORD.OLB”(word2000为MSWORD9.OLB),一般安装了OfficeWord后,你就能够在office安装目次的Office10文件夹上面找到这个文件,当我们将这个文件引进到项目后,我们就能够在源码中利用各类操纵函数来操纵Word。详细做法是翻开菜单栏中的项目>增加援用>扫瞄,在翻开的“选择组件”对话框中找到MSWORD.OLB后按断定便可引进此工具库文件,vs.net将会主动将库文件转化为DLL组件,如许我们只需在源码中创立该组件工具便可到达操纵Word的目标!在CS代码文件中对定名空间的使用,如:usingWord;典范以下:
  
  usingSystem;
  usingSystem.Drawing;
  usingSystem.Collections;
  usingSystem.ComponentModel;
  usingSystem.Windows.Forms;
  usingWord;
  namespaceExamSecure
  {
  ///
  ///ItemToDoc的择要申明。
  ///
  publicclassItemToDoc:System.Windows.Forms.Form
  {
  objectstrFileName;
  ObjectNothing;
  Word.ApplicationClassmyWordApp=newWord.ApplicationClass();
  Word.DocumentmyWordDoc;
  stringstrContent="";
  privateSystem.ComponentModel.Containercomponents=null;
  publicItemToDoc()
  {
  //
  //Windows窗体计划器撑持所必须的
  //
  InitializeComponent();
  //
  //TODO:在InitializeComponent挪用后增加任何机关函数代码
  //
  }
  [STAThread]
  staticvoidMain()
  {
  System.Windows.Forms.Application.Run(newItemToDoc());
  }
  ///
  ///清算一切正在利用的资本。
  ///
  protectedoverridevoidDispose(booldisposing)
  {
  if(disposing)
  {
  if(components!=null)
  {
  components.Dispose();
  }
  }
  base.Dispose(disposing);
  }
  #regionWindowsFormDesignergeneratedcode
  ///
  ///计划器撑持所需的办法-不要利用代码编纂器修正
  ///此办法的内容。
  ///
  privatevoidInitializeComponent()
  {
  //
  //ItemToDoc
  //
  this.AutoScaleBaseSize=newSystem.Drawing.Size(6,14);
  this.ClientSize=newSystem.Drawing.Size(292,273);
  this.Name="ItemToDoc";
  this.Text="ItemToDoc";
  this.Load+=newSystem.EventHandler(this.ItemToDoc_Load);
  }
  #endregion
  privatevoidItemToDoc_Load(objectsender,System.EventArgse)
  {
  WriteFile();
  }
  privatevoidWriteFile()
  {
  
  strFileName=System.Windows.Forms.Application.StartupPath+"试题库【"+GetRandomString()+"】.doc";
  ObjectNothing=System.Reflection.Missing.Value;
  myWordDoc=myWordApp.Documents.Add(refNothing,refNothing,refNothing,refNothing);
  
  #region将数据库中读获得数据写进到word文件中
  strContent="试题库

";
  WriteFile(strContent);
  
  strContent="试题库";
  WriteFile(strContent);
#endregion
  
  //将WordDoc文档工具的内容保留为DOC文档
  myWordDoc.SaveAs(refstrFileName,refNothing,refNothing,refNothing,refNothing,refNothing,refNothing,refNothing,refNothing,refNothing,refNothing,refNothing,refNothing,refNothing,refNothing,refNothing);
  //封闭WordDoc文档工具
  myWordDoc.Close(refNothing,refNothing,refNothing);
  //封闭WordApp组件工具
  myWordApp.Quit(refNothing,refNothing,refNothing);
  }
  ///
  ///猎取一个随即字符串
  ///
  ///
  privatestringGetRandomString()
  {
  DateTimeiNow=DateTime.Now;
  stringstrDate=iNow.ToString("yyyyMMddHHmmffff");
  
  Randomran=newRandom();
  intiRan=Convert.ToInt32(10000*ran.NextDouble());
  stringstrRan=iRan.ToString();
  //位数不敷则补0
  intiRanlen=strRan.Length;
  for(inti=0;i<4-iRanlen;i++)
  {
  strRan="0"+strRan;
  }
  returnstrDate+strRan;
  }
  ///
  ///将字符串写进到Word文件中
  ///
  ///要写进的字符串
  privatevoidWriteFile(stringstr)
  {
  myWordDoc.Paragraphs.Last.Range.Text=str;
  }
  }
  }
觉得J2EE好像有很多工具,比如servlet,jboss,tomcat,ejb什么的,可是微软的.NET怎么什么也没有啊?
莫相离 该用户已被删除
沙发
发表于 2015-1-19 16:28:59 | 只看该作者
Asp.net:首先来说,Asp.net和Asp没什么关系,看着像是升级版本什么的,其实没什么联系。Asp是脚本编程,用的是ASP语言,而ASP.net用的是C#语言,完全不同的东西。
愤怒的大鸟 该用户已被删除
板凳
 楼主| 发表于 2015-2-5 05:07:01 | 只看该作者
现在的ASP.net分为两个版本:1.1和2.0Asp.net1.1用VS2003(visualstudio2003)编程。Asp.net2.0用VS2005(visualstudio2005)编程。现在一般开发用的是VS2003。
分手快乐 该用户已被删除
地板
发表于 2015-2-11 05:43:46 | 只看该作者
大哥拜托,Java在95年就出来了,微软垄断个妹啊,服务器市场微软完全是后后来者,当年都是Unix的市场,现在被WindowsServer和Linux抢下大片,包括数据库也一样。
第二个灵魂 该用户已被删除
5#
发表于 2015-3-1 22:38:28 | 只看该作者
ASP.Net和ASP的最大区别在于编程思维的转换,而不仅仅在于功能的增强。ASP使用VBS/JS这样的脚本语言混合html来编程,而那些脚本语言属于弱类型、面向结构的编程语言,而非面向对象。
6#
发表于 2015-3-17 17:10:52 | 只看该作者
以上是语言本身的弱点,在功能方面ASP同样存在问题,第一是功能太弱,一些底层操作只能通过组件来完成,在这点上是远远比不上PHP/JSP,其次就是缺乏完善的纠错/调试功能,这点上ASP/PHP/JSP差不多。
山那边是海 该用户已被删除
7#
发表于 2015-3-24 14:50:17 | 只看该作者
众所周知,Windows以易用而出名,也因此占据不少的服务器市场。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-6 19:02

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表