none
Reading Excel Chinese table names using OleDbConnection RRS feed

  • Question

  • I have an Excel xls file which contains Chinese table names. I use OleDbConnection to obtain the table names, and get "????$", thus cannot use "select * from [Chinese table name]" to read data. But when I open the xls file by Excel 2003 and then run my code, I can read out Chinese table name as "中文表名$" and get data by "select * from [Chinese table name]". I dnn't know why. How can I read Chinese xls file without opening it by Excel? Thank you!

    The code is as follows:

    public static void PrintSchemaTable(string filePath)
    {
     string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties= ""Excel 8.0;HDR=YES;""";
     connectionString = string.Format(connectionString, filePath);
    
     using (OleDbConnection conn = new OleDbConnection(connectionString))
     {
      conn.Open();
      DataTable schemaTable = conn.GetOleDbSchemaTable(
       OleDbSchemaGuid.Tables,
       new object[] { null, null, null, "TABLE" });
    
      DataTable dtSheetName = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "Table" });
    
      for (int k = 0; k < dtSheetName.Rows.Count; k++)
      {
       string tableName = dtSheetName.Rows[k]["TABLE_NAME"].ToString();
       Console.WriteLine(tableName);
      }
     }
    } 
    
    
    Sunday, October 17, 2010 3:26 AM

Answers

  • If I am not mistaken, there were multiple editions of Jet OLEDB provider to support different locales. I cannot find download for it though. You can try to search for it at http://www.microsoft.com/downloads/en/default.aspx

    If that does not work, you can use Excel reader provider from my web site as it supports Chinese and it is native .NET data provider.


    Val Mazur (MVP) http://www.xporttools.net
    • Marked as answer by liurong luo Monday, October 25, 2010 1:49 AM
    Monday, October 18, 2010 10:41 AM
    Moderator