Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="xls"></param>
        /// <param name="sheet">Start from 1</param>
        /// <returns></returns>
        public static SheetData GetSheetData(XlsFile xls, int sheet)
        {
            xls.ActiveSheet = sheet;
            SheetData sheetData = new SheetData();
            int       colCount  = xls.GetColCount(sheet);
            int       rowCount  = xls.GetRowCount(sheet);
            int       row       = 1;

            for (int col = 1; col <= colCount; col++)
            {
                string val = Convert.ToString(xls.GetCellValue(row, col));
                if (string.IsNullOrEmpty(val))
                {
                    break;
                }
                sheetData.Columns.Add(val.Trim());
            }
            colCount = sheetData.Columns.Count();

            row++;
            while (row <= rowCount)
            {
                object[] recordRow = new object[colCount];
                for (int col = 1; col <= colCount; col++)
                {
                    recordRow[col - 1] = xls.GetCellValue(row, col);
                }
                sheetData.Records.Add(recordRow);
                row++;
            }

            return(sheetData);
        }
Пример #2
0
 public static ToaDo getPositionTableFlexExcel(XlsFile Result, string TextFil, int Sheet = 1)
 {
     Result.ActiveSheet = Sheet;//we'll read sheet1. We could loop over the existing sheets by using xls.SheetCount and xls.ActiveSheet
     for (int row = 1; row <= Result.RowCount; row++)
     {
         for (int colIndex = 1; colIndex <= Result.GetColCount(Sheet, false); colIndex++) //Don't use xls.ColCount as it is slow: See Performance.Pdf
         {
             try
             {
                 var valueCell = Result.GetCellValue(row, colIndex);
                 if (valueCell != null)
                 {
                     var dataString = valueCell.ToString();
                     if (!string.IsNullOrEmpty(dataString))
                     {
                         if (dataString.ToUpper().IndexOf(TextFil.ToUpper()) >= 0)//bat key ton tai table vidu: <#ChiTiet.TENDICHVU>
                         {
                             return(new ToaDo()
                             {
                                 X = row, Y = colIndex
                             });
                         }
                     }
                 }
             }
             catch (Exception)
             {
             }
         }
     }
     return(new ToaDo()
     {
         X = 0, Y = 0
     });
 }