After getting the NumberFormat
from the Excel range, you can convert it using this table of formatting codes, or this reference from Microsoft. Keep in mind that mixed formats are possible if customized.
If you just want the base values (my defaults from drop down in Excel 2010):
- "0.00" - Number
- "$#,##0.00" - Currency
- "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??);(@_)" - Accounting
- "m/d/yyyy" - Short date
- "[$-F800]dddd, mmmm dd, yyyy" - Long date
- "[$-F400]h:mm:ss AM/PM" - Time
- "0.00%" - Percentage
- "# ?/?" - Fraction
- "0.00E+00" - Scientific
- "@" - Text
- "General" - General
I got these values by recording a macro and modifying the number format for the selected cell.
EDIT:
A little more help to get where you want to go - assuming that you are using the Excel interop library (the only way I know how to access the NumberFormat
function):
string fileName = @"c:\Book1.xlsx";
Application app = new Application();
Workbook wb = app.Workbooks.Open(fileName,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
Worksheet sheet = wb.Sheets[1]; //Change to the sheet you care about (1 based index)
var cell = sheet.Cells[1, 1]; //Change to the cell you care about (1 based index)
string cellNumberFormat = cell.NumberFormat; //Number format of cell to compare against known values
Setup for using the interop library found here.