Saturday, February 5, 2011

Excel column names

What column names cannot be used when creating an Excel spreadsheet with ADO.

I have a statement that creates a page in a spreadsheet.

CREATE TABLE [TableName] (Column string, Column2 string);

I have found that using a column name of Date or Container will generate an error when the statement is executed.

Does anyone have a complete (or partial) list of words that cannot be used as column names? This is for use in a user-driven environment and it would be better to "fix" the columns than to crash.

My work-around for these is to replace any occurences of Date or Container with Date_ and Container_ respectively.

  • Here are the reserved words for MS Query:

    http://support.microsoft.com/kb/125948

    Cell naming rules:

    http://ezinearticles.com/?Rules-For-Naming-Cells-in-Microsoft-Excel&id=218607

    Brad Bruce : I still cannot find why "container" is flagged as invalid. Definitely like the cell naming rules link.
    From nathaniel
  • It seems more like an issue with SQL reserved words. This is a good list

    From Swati
  • You can use brackets for any fieldname, e.g.:

    CREATE TABLE [TableName] ([Date] string, [Container] string)
    

    Full example:

    using (OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\temp\\test.xls;Extended Properties='Excel 8.0;HDR=Yes'"))
    {
      conn.Open();
      OleDbCommand cmd = new OleDbCommand("CREATE TABLE [TableName] ([Date] string, [Container] string)", conn);
      cmd.ExecuteNonQuery();
    }
    
    Brad Bruce : This was the best answer to the problem
    From Panos

0 comments:

Post a Comment