예제 #1
0
 /// <summary>
 /// Reads the document.
 /// </summary>
 /// <param name="columnCount">Number of columns to read.</param>
 /// /// <param name="ignoreRowCount">Number of rows to ignore</param>
 /// <param name="result">The result as table.</param>
 /// <returns>True if succes</returns>
 public bool ReadDocument(int ignoreRowCount, ref DataTable result)
 {
     var dataResult = new DataResult(DataResult.DataResultType.DataTableType);
     if (!ExecuteReadDocument(ignoreRowCount, ref dataResult)) return false;
     result = dataResult.GetDataTable();
     return true;
 }
예제 #2
0
 /// <summary>
 /// Reads all rows in document.
 /// </summary>
 /// <param name="columnCount">Number of columns to read.</param>
 /// <param name="ignoreRowCount">Number of rows to ignore</param>
 /// <param name="result">The result data.</param>
 /// <returns>True is succes</returns>
 private bool ExecuteReadDocument(int ignoreRowCount, ref DataResult result)
 {
     if (CurrentSheet == null) throw new Exception("No sheet selected");
     var stringTableList = GetSharedStringPart().SharedStringTable.ChildElements.ToList();
     var lastRow = CurrentSheet.Worksheet.Descendants<Row>().LastOrDefault();
     var firstRow = CurrentSheet.Worksheet.Descendants<Row>().FirstOrDefault();
     Int32 columnCount = firstRow.Descendants<Cell>().Count();
     if (lastRow == null) return false;
     var allRows = CurrentSheet.Worksheet.Descendants<Row>().ToList();
     for (var rowIndex = (1 + ignoreRowCount); rowIndex <= lastRow.RowIndex; rowIndex++)
     {
         var cellList = new List<string>();
         var cellValues = (from c in
                               (from rows in allRows
                                where rows.RowIndex.Value == rowIndex
                                select rows).FirstOrDefault().Descendants<Cell>()
                           select c).ToList();
         for (var cellIndex = 0; cellIndex <= columnCount - 1; cellIndex++)
         {
             var colName = GetColumnName(cellIndex);
             var cell = (from c in cellValues
                         where c.CellReference.Value.Equals(colName + rowIndex, StringComparison.CurrentCultureIgnoreCase)
                         select c).FirstOrDefault();
             cellList.Add(GetCellValue(cell, stringTableList));
         }
         result.AddRow(cellList.ToArray());
     }
     return true;
 }
예제 #3
0
 /// <summary>
 /// Reads the document.
 /// </summary>
 /// <param name="columnCount">Number of columns to read.</param>
 /// /// <param name="ignoreRowCount">Number of rows to ignore</param>
 /// <param name="result">The result list.</param>
 /// <returns>True if succes</returns>
 public bool ReadDocument(int ignoreRowCount, ref List<string[]> result)
 {
     var dataResult = new DataResult(DataResult.DataResultType.ListType);
     if (!ExecuteReadDocument(ignoreRowCount, ref dataResult)) return false;
     result = dataResult.GetList();
     return true;
 }