467,166 Members | 1,133 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,166 developers. It's quick & easy.

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)objFields.Current;

Expand|Select|Wrap|Line Numbers
  1.  for (int n = 0; n < nFields; n++)
  2.                                 {
  3.                                     switch (objField.Type.ToString())
  4.                                     {
  5.                                         case "adVarWChar":
  6.                                         case "advarwchar":
  7.                                             {
  8.                                                break;
  9.                                             }
  10.                                         case "adDBTimeStamp":
  11.                                         case "addbtimestamp":
  12.                                             {
  13.                                                 ((Range)sheet1.Cells[1, n + 1]).EntireColumn.NumberFormat = "dd-mmm-yy";
  14.                                                 break;
  15.                                             }
  16.                                         case "adNumeric":
  17.                                         case "adnumeric":
  18.                                             {
  19.                                                 ((Range)sheet1.Cells[1, n + 1]).EntireColumn.NumberFormat = "0.00";
  20.                                                 break;
  21.                                             }
  22.                                     }
  23.                                 }
Aug 15 '08 #1
  • viewed: 6935
Share:
2 Replies
8TB
You are not looping through all the fields. You are running the loop for only the current field.
Aug 15 '08 #2
You are not looping through all the fields. You are running the loop for only the current field.
Yes looping is the problem :) Thanks
Aug 16 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by thomasp@msala.net | last post: by
18 posts views Thread by gonzlobo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.