Beispiel #1
0
    private static ss.Cell GetSpreadsheetCell(ss.Worksheet worksheet, string columnName, uint rowIndex)
    {
        IEnumerable<ss.Row> rows = worksheet.GetFirstChild<ss.SheetData>().Elements<ss.Row>().Where(r => r.RowIndex == rowIndex);
        if (rows.Count() == 0)
        {
            // A cell does not exist at the specified row.
            return null;
        }

        IEnumerable<ss.Cell> cells = rows.First().Elements<ss.Cell>().Where(c => string.Compare(c.CellReference.Value, columnName + rowIndex, true) == 0);
        if (cells.Count() == 0)
        {
            // A cell does not exist at the specified column, in the specified row.
            return null;
        }

        return cells.First();
    }
        // Get the value of a cell, given a file name, sheet name, and address name.
        string XLGetCellValue(Excel.Cell c, WorkbookPart wbPart)
        {
            string value = null;
            // If the cell does not exist, return an empty string.
            if (c != null)
            {
                value = c.InnerText;

                // If the cell represents an integer number, you are finished.
                // For dates, this code returns the serialized value that
                // represents the date. The code handles strings and Boolean values
                // individually. For shared strings, the code looks up the corresponding
                // value in the shared string table. For Boolean values, the code converts
                // the value into the words TRUE or FALSE.
                if (c.DataType != null)
                {
                    switch (c.DataType.Value)
                    {
                        case Excel.CellValues.SharedString:
                            // For shared strings, look up the value in the shared strings table.
                            var stringTable = wbPart.GetPartsOfType<SharedStringTablePart>().FirstOrDefault();
                            // If the shared string table is missing, something is wrong.
                            // Just return the index that you found in the cell.
                            // Otherwise, look up the correct text in the table.
                            if (stringTable != null)
                            {
                                value = stringTable.SharedStringTable.ElementAt(int.Parse(value)).InnerText;
                            }
                            break;
                        case Excel.CellValues.Boolean:
                            switch (value)
                            {
                                case "0":
                                    value = "FALSE";
                                    break;
                                default:
                                    value = "TRUE";
                                    break;
                            }
                            break;
                    }
                }
            }

            return value;
        }
Beispiel #3
0
 public Cell(Worksheet sheet, Spreadsheet.Cell xml)
 {
     Sheet = sheet;
     Xml = xml;
 }