0

I have an excel document that is supposed to be parsed using the following block of code:

 var handler = new ExcelHandler(byteStream);


        var currentExcelDocument = handler.CurrentDocument;
        //now if the document is null
        if (currentExcelDocument == null)
            {
            throw new Exception("Excel file handle missing");
            }
        var wokrbookpart = currentExcelDocument.WorkbookPart;
        //get a list of all the sheets
        string text =  String.Empty;

        var sheets = wokrbookpart.Workbook.Descendants<Sheet>().ToList();
        foreach (var sh in sheets)
            {
            //now we have the sheets but the data must be in the first sheet
            var themainsheet = sh;
            if (themainsheet == null)
                throw new ArgumentException("sheetName");
            //now we need a reference to the worksheetpart
            var worksheetpart = (WorksheetPart)wokrbookpart.GetPartById(themainsheet.Id);

            SheetData data = worksheetpart.Worksheet.Elements<SheetData>().First();

            //now we have a reference to the cells that contain data we start passing the data

            foreach (Row r in data.Elements<Row>())
                {
                //we get the cells in the row
                var cells = r.Elements<Cell>().ToList();
                foreach (var i in cells)
                    {
                    text += i.CellValue.InnerText;
                    }
                }
            }

        return text;

the excel file is uploaded via a fileupload control in asp.net and the stream is passed into the above block of code.

All is well though but then when i display the resulting text in the label, I see that the result of reading the cell values is displayed as a sequence of numbers even though i am hindred percent sure that there are no numbers in the data

Please what could i be doing wrong??

Paul Plato
  • 1,471
  • 6
  • 28
  • 36
  • Are you sure that there are no cells in the row with numbers in? For example, there could be hidden columns, or rows far off to the right of the sheet that contain values. It might be worth you adding a debug line that checks for the presence of numeric characeters in `i.CellValue.InnerText` and writes the cell address. – dash Jan 28 '13 at 16:12
  • I am 100% sure that there are no numbers. i created the file myself. a new blank document and i type in the characters myself – Paul Plato Jan 28 '13 at 16:39
  • I think you are getting the value of a shared string address. See http://stackoverflow.com/questions/5115257/open-xml-excel-read-cell-value and http://msdn.microsoft.com/en-us/library/office/hh298534.aspx – dash Jan 28 '13 at 16:57

0 Answers0