Esempio n. 1
0
        private string GetExcelCellValue(DocumentFormat.OpenXml.Spreadsheet.Cell cell, DocumentFormat.OpenXml.Packaging.WorkbookPart wbpart)
        {
            string retVal = string.Empty;

            if (cell.DataType != null)
            {
                if (cell.DataType == DocumentFormat.OpenXml.Spreadsheet.CellValues.SharedString)
                {
                    int id = -1;
                    if (Int32.TryParse(cell.InnerText, out id))
                    {
                        DocumentFormat.OpenXml.Spreadsheet.SharedStringItem item = GetSharedStringItemById(wbpart, id);

                        if (item.Text != null)
                        {
                            retVal = item.Text.Text;
                        }
                        else if (item.InnerText != null)
                        {
                            retVal = item.InnerText;
                        }
                        else if (item.InnerXml != null)
                        {
                            retVal = item.InnerXml;
                        }
                    }
                }
                else
                {
                    retVal = cell.InnerText;
                }
            }
            return(retVal);
        }
Esempio n. 2
0
        private string GetCurrentCellAsString()
        {
            DocumentFormat.OpenXml.Spreadsheet.Cell c = currentCell;

            if (c.DataType != null && c.DataType == DocumentFormat.OpenXml.Spreadsheet.CellValues.SharedString)
            {
                // Shared string (stored in separate table)
                DocumentFormat.OpenXml.Spreadsheet.SharedStringItem ssi = spreadsheetDocument.WorkbookPart.SharedStringTablePart.SharedStringTable.Elements <DocumentFormat.OpenXml.Spreadsheet.SharedStringItem>()
                                                                          .ElementAt(int.Parse(c.CellValue.InnerText));

                return(ssi.InnerText);
            }

            if (c.DataType != null && c.DataType == DocumentFormat.OpenXml.Spreadsheet.CellValues.InlineString)
            {
                // Inline string (stored as child node)
                return(c.FirstChild.InnerText);
            }

            return(null);
        }