组件

组件:是对象的集合,功能完备的单元,他又对外的接口
1  如何使用已有的组件(例如Word和Excel)
   首先你要将要引用的组件添加到程序中去
   private void UserWord(string filenamepath)
   {
      try
      {
         object nothing=System.Reflection.Missing.Value;//调用默认值,以后只需要写nothing就可以了
         //创建Word组件对象
         Word.Application app=new Word.ApplicationClass();
         //创建WordDoc的文档
         Word.Document doc=app.Document.Add(ref nothing,ref nothing,ref nothing);
         //增减表格
         Word.Table tb=doc.Table.Add(app.Selection.Range,1,1,ref nithing,ref nothing);
         tb.Cell(1,1).Range.Text="prolove";
         //在文档的空白处添加文字
         doc.Paragraphs.Last.Range.Text="2007-11-21";
         doc.SaveAs(ref filenamepath,ref nothinf,ref nothing,ref nothing,...... );
         doc.Close(ref nothing,ref nothing,ref nothing);
         app.Quit(ref nothing,ref nothing,ref nothing);
      }
      catch
      {
        ....
      }
   }
   2)利用ADONET操作Excel
     private void AddExcel(string filenamepath)
     {
        OleDbConnection conn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+filenamepath+";Extended Properties=Excel 8.0");
        conn.Open();
        OleDb cmd=new OleDbCommand();
        cmd.Connection=conn;
        //创建一个新的工作表
        //cmd.CommandText="create table prolove(username char(20),pwd char(20))";
       // cmd.ExecuteNonQuery();
       //向一个工作表中添加数据
       cmd.CommandText="insert into prolove(username,pwd) values ('prolove','12345')";
       cmd.ExecuteNonQuery();
       conn.Close(); 
     }
 2  创建用户的控件(.ascx)
    1).aspx是继承.cs文件的,所以你可以直接使用.cs中的方法和public 属性
    例如:
     .cs中
     public string strColor="Red";
     .aspx
     <td bgcolor="<%=strcolor%>"></td>
    2)怎样使用控件
      直接拖动到窗口
                   //前缀          //名称        //来源
      <%@ Register TagPrefix="uc1" TagName="KJ" Src="KJ.ascx" %>
      通过编码方式
        Control cr=LoadControl("KJ.ascx");
        ((KJ)cr).属性="数值";
        Page.Controls.Add(cr);
     
    
    
     
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值