ADO Excel Templates

Source: Internet
Author: User

ADO Excel Templates

private static void Excute ()
        {
             while (true)
             {
                String TemplatePath = System.Environment.CurrentDirectory + "\\template.xls";
                String NewPath = System.Environment.CurrentDirectory + "\\temp.xls";
                if (! File.exists (TemplatePath))
                     return;

                if (! File.exists (NewPath))
                     file.copy (TemplatePath, newpath,true);

                FileInfo FileInfo = New FileInfo (NewPath);
                String s = FileInfo.Attributes.ToString ();
                if ( FileInfo.Attributes.ToString (). ToLower (). IndexOf ("readonly")! =-1)
                 {
                     fileinfo.attributes = Fileattributes.normal;
               }

                String connstr = " provider=microsoft.jet.oledb.4.0; "+
                     "Extended properties=\" Excel 8.0; Hdr=yes;imex=2\ ";" +
                    //Specify Extended Properties for Microsoft Excel 8.0 (97) 9.0 (2000) 10.0 (2002), and the first row is returned as data and is read as text  & nbsp;     
                     "Data source=" + NewPath;

OleDbConnection conn = new OleDbConnection (CONNSTR);
OleDbCommand cmd = new OleDbCommand ("", conn);

Try
{
Conn. Open ();

String sql = "INSERT INTO [sheet2$] (name, gender, contact phone) VALUES (41,51,61)";
Cmd.commandtext = SQL;
Cmd. ExecuteNonQuery ();
Conn. Close ();

FileStream reader = File.openread (NewPath);
int length = (int) reader. Length;
byte[] buffer = new Byte[length];
int bytetoread;
while (length > 0)
//{
The client is still open.
Bytetoread = reader. Read (buffer, 0, length);
Length-= Bytetoread;
When the client disconnects
length =-1;
//}

                    //The following is a transaction
                     file.copy (NewPath, "2011.xls", true);
                     if (file.exists (NewPath))
                         File.delete (NewPath);


               }
                 catch (Exception e)
                {
                    
               }
                 finally
                 {
                     Conn. Dispose ();
               }

Thread.Sleep (1000);
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.