Hirdetés

Új hozzászólás Aktív témák

  • cigam

    titán

    Újra kellene egy kis iránymutatás:

    public void GetCellValues(string fileName, string sheetName)
            {
                string addressName = null;
                string data = null;
                // Open the spreadsheet document for read-only access.
                using (SpreadsheetDocument document =
                    SpreadsheetDocument.Open(fileName, false))
                {
                    // Retrieve a reference to the workbook part.
                    WorkbookPart wbPart = document.WorkbookPart;

                    // Find the sheet with the supplied name, and then use that 
                    // Sheet object to retrieve a reference to the first worksheet.
                    Sheet theSheet = wbPart.Workbook.Descendants<Sheet>().
                      Where(s => s.Name == sheetName).FirstOrDefault();

                    // Throw an exception if there is no sheet.
                    if (theSheet == null)
                    {
                        throw new ArgumentException("sheetName");
                    }

                    // Retrieve a reference to the worksheet part.
                    WorksheetPart wsPart = (WorksheetPart)(wbPart.GetPartById(theSheet.Id));

                    // Éjjel
                    addressName = "B4";
                    Cell theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                    // If the cell does not exist, return an empty string.
                    if (theCell != null)
                    {
                        data = theCell.InnerText;
                        if (data != "")
                        {
                            nightMinimum = int.Parse(data);
                            label_nightMinimum_ertek.Content = nightMinimum;
                        }
                        else
                        {
                            label_nightMinimum_ertek.Content = "-";
                            error = true;
                        }
                    }

    Megnyitok egy .xls fájlt, és a cellák adatait beolvasom. Működik is egészen addig, amíg számokat írok be. De ha véletlen egy "a" betű szerepel a táblázatban, kap egy 12-es értéket, mintha "12" lenne a cellába írva. Hogyan tudom megvizsgálni, hogy 1 és 50 közötti szám szerepel az adott cellában?

Új hozzászólás Aktív témák