C# Format columns in excel

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DeelynBaNi
    New Member
    • Aug 2008
    • 7

    C# Format columns in excel

    Hi all...i'm having a problem in formatting columns in excel. For example i have column Name, Birth Date and Salary and i want to format it to string, date and numeric respectively. When i format the columns using the codes below, all columns format become numeric. Any advise @ reference i can refer to?

    objField = (ADODB.Field)ob jFields.Current ;

    Code:
     for (int n = 0; n < nFields; n++)
                                    {
                                        switch (objField.Type.ToString())
                                        {
                                            case "adVarWChar":
                                            case "advarwchar":
                                                {
                                                   break;
                                                }
                                            case "adDBTimeStamp":
                                            case "addbtimestamp":
                                                {
                                                    ((Range)sheet1.Cells[1, n + 1]).EntireColumn.NumberFormat = "dd-mmm-yy";
                                                    break;
                                                }
                                            case "adNumeric":
                                            case "adnumeric":
                                                {
                                                    ((Range)sheet1.Cells[1, n + 1]).EntireColumn.NumberFormat = "0.00";
                                                    break;
                                                }
                                        }
                                    }
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    You are not looping through all the fields. You are running the loop for only the current field.

    Comment

    • DeelynBaNi
      New Member
      • Aug 2008
      • 7

      #3
      Originally posted by r035198x
      You are not looping through all the fields. You are running the loop for only the current field.
      Yes looping is the problem :) Thanks

      Comment

      Working...