Determine the local excel version when exporting an excel file

Source: Internet
Author: User

Public bool ExistsRegedit ()
{
Bool ifused = false;
RegistryKey rk = Registry. LocalMachine;
RegistryKey akey = rk. OpenSubKey (@ "SOFTWARE \ Microsoft \ Office \ 11.0 \ Word \ InstallRoot \\");
RegistryKey akeytwo = rk. OpenSubKey (@ "SOFTWARE \ Microsoft \ Office \ 12.0 \ Word \ InstallRoot \\");
// Check whether Office2003 is installed on the local machine
If (akey! = Null)
{
String file03 = akey. GetValue ("Path"). ToString ();
If (File. Exists (file03 + "Excel.exe "))
{
Ifused = true;
}
}
// Check whether the local machine has Office2007 installed
If (akeytwo! = Null)
{
String file07 = akeytwo. GetValue ("Path"). ToString ();
If (File. Exists (file07 + "Excel.exe "))
{
Ifused = true;
}
}
Return ifused;
}

 

RegistryKey bkey = rk. OpenSubKey (@ "SOFTWARE \ Microsoft \ Office \ 9.0 \ Word \ InstallRoot \\");
// Check whether Office2003 is installed on the local machine
If (bkey! = Null)
{
String file00 = bkey. GetValue ("Path"). ToString ();
If (File. Exists (file00 + "Excel.exe "))
{
Ifused = true;
}
}

 

// Dynamically concatenate the connection string

DataSet ds = new DataSet (); string strConn = "";
If (ExistsRegedit03 ())
{
StrConn = "Provider = Microsoft. Jet. OLEDB.4.0;" + "Data Source =" + strpath + ";" + "Extended Properties = Excel 8.0 ;";
} Else if (ExistsRegedit07 ())
{
StrConn = "Provider = Microsoft. Ace. OLEDB.12.0;" + "Data Source =" + strpath + ";" + "Extended Properties = Excel 12.0 ;";
}
OleDbConnection conn = new OleDbConnection (strConn );
OleDbDataAdapter myCommand = new OleDbDataAdapter ("SELECT * FROM [RelationerTable $]", strConn );
MyCommand. Fill (ds );
DataTable dt = ds. Tables [0];
// Dt is the set of read data.

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.