其实关于程序自动启动完全可以用WINDOWS中的计划任务指定时间。
但。NET程序中如何设计一个指取完数据自动关闭程序的功能。也就是说。每次启动程序之后就进行读取。这后自动关闭。

解决方案 »

  1.   

    为了方便高手指导问题。
    我将程序指定读取URL的地址公布如下。http://www.sxsqxt.com/yh2/ydnr1.htm
      

  2.   

    首先获取网页内容,即网页的Html内容.
    代码示例如下:
    private string GetHtmlFromURL(string sAddress)
    {
    System.Text.StringBuilder sbHtml=new System.Text.StringBuilder();
    //Disable button
    btnGetHtml.Enabled=false; HttpWebRequest hwReq=(HttpWebRequest)WebRequest.Create(sAddress);
    HttpWebResponse hwResponse=(HttpWebResponse)hwReq.GetResponse();
    Stream stream=hwResponse.GetResponseStream();
    StreamReader reader=new StreamReader(stream,System.Text.Encoding.GetEncoding("GB2312"));// char[] read = new char[256];
    // Reads 256 characters at a time.    
    int count = reader.Read( read, 0, 256 );
    while (count > 0) 
    {
    // Dumps the 256 characters on a string and displays the string to the console.
    string str = new string(read, 0, count);
    sbHtml.Append(str);
    count =reader.Read(read,0,256);
    }
    // Releases the resources
    hwResponse.Close();
    stream.Close();
    reader.Close();                           return sbHtml.ToString();
    }然后,将string保存为一个文件,注意~文件后缀名为xls(即Excel)的文件名.
    然后直接用Excel就可以打开.//呵呵~这是因为Excel会自动读取Htmal格式.如果你希望将其保存为真正的xls格式的文件,那就在后台打开一个Excel,读取这个文件
    然后将它另存为一个xls格式(注意不光是文件后缀名)的文件.
    关于怎么调用Excel打开一个文件和另存一个文件.可参考相关文章.这里不再重复.
      

  3.   

    如何生产一个新的Excel文件以写入数据并保存1.       首先,产生一个文件夹来存放Excel文件private string genReportPath()         {              try              {                   string _path="..//ReportDoc//DRI";                                                       if (!Directory.Exists(Server.MapPath(_path)))                   {                                                   Directory.CreateDirectory(Server.MapPath(_path));                    }                       return _path;              }              catch(Exception er)              {                   throw er;              }         }2.确定Excel文件string reportpath=this.genReportPath()+"//"+_reportname+".xls";  3.生成Excel文件this.genExcel(ds_DRI,Server.MapPath(reportpath).ToString());4.生成函数(需要一个DataSet,还需要一个路径)private void genExcel(DataSet ds,string ReportPath)         {              try              {                   //删除重复的文件;                   if (File.Exists(ReportPath))                   {                        File.Delete(ReportPath);                   }                   FileStream fsobj=new FileStream(ReportPath,System.IO.FileMode.Create,FileAccess.ReadWrite);                                 //生成一个文件流                   StreamWrite     _sw=new StreamWriter(fsobj,System.Text.UnicodeEncoding.Unicode);//生成一个写入器//开始写入DataTable dt=ds.Tables[0];              for(int j=0;j<countMRD;j++)                   {                        _sw.Write(dt.Rows[j][0].ToString().Trim()+"\t");                        _sw.Write(dt.Rows[j][1].ToString().Trim()+"\t");                        _sw.Write(dt.Rows[j][2].ToString().Trim()+"\t");                        _sw.Write(dt.Rows[j][3].ToString().Trim()+"\t");                        _sw.Write(dt.Rows[j][4].ToString().Trim()+"\t");                        _sw.Write(dt.Rows[j][5].ToString().Trim()+"\t");                        _sw.Write(dt.Rows[j][6].ToString().Trim()+"\t");                        _sw.Write(dt.Rows[j][7].ToString().Trim()+"\t");                        _sw.Write(dt.Rows[j][8].ToString().Trim()+"\t");                        _sw.Write(dt.Rows[j][9].ToString().Trim()+"\t");}_sw.close();fsobj.close();     }     catch(Exception er)     {         throw er;     }