1
Vote

Reading "excel" file using openxml concept

description

environment : no ms office installed.


Hi,

i tried reading the excel file in the environment by open xml concept ,where the ms office is not installed.It worked fine.


but if a cell value contains (date and time) value it returns integer value .

ex :- original file cell value contains - 11/27/2012
getiinng value as some integer -42105.

here is the code

static void ReadExcelFileDOM(string fileName)
    {
        using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(fileName, false))
        {
            WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart;
            WorksheetPart worksheetPart = workbookPart.WorksheetParts.First();
            SheetData sheetData = worksheetPart.Worksheet.Elements<SheetData>().First();
            string text;
            foreach (Row r in sheetData.Elements<Row>())
            {
                foreach (Cell c in r.Elements<Cell>())
                {
                    text = c.CellValue.Text;
                    Console.Write(text + " ");
                }
            }
            Console.WriteLine();
            Console.ReadKey();

        }

    }

comments