Exemple #1
0
        public DataTable AsDataTable(int[] rowNumbers, bool smartHyperlinks = true)
        {
            var result = new DataTable();

            var rows = Rows.Where(r => rowNumbers.Contains(Rows.IndexOf(r))).ToArray();

            List <int> hyperLinkColumns = new List <int>();

            foreach (ExelRow row in rows)
            {
                for (int i = 0; i < row.Cells.Count; i++)
                {
                    if (!string.IsNullOrWhiteSpace(row.Cells[i].HyperLink))
                    {
                        if (!hyperLinkColumns.Contains(i))
                        {
                            hyperLinkColumns.Add(i);
                        }
                    }
                }
            }

            var maxCoulumnsCount = Rows.Max(r => r.Cells.Count) + ((smartHyperlinks) ? hyperLinkColumns.Count : 0);

            for (var i = 0; i < maxCoulumnsCount; i++)
            {
                result.Columns.Add();
            }

            foreach (ExelRow row in rows)
            {
                var stringRow = new List <string>();
                for (int n = 0; n < row.Cells.Count; n++)
                {
                    ExelCell cell      = row.Cells[n];
                    string   cellValue = string.Empty;

                    cellValue = (!string.IsNullOrWhiteSpace(cell.HyperLink) && !smartHyperlinks) || (smartHyperlinks && string.IsNullOrWhiteSpace(cell.Value)) ? cell.HyperLink : cell.Value;
                    if (smartHyperlinks)
                    {
                        if (hyperLinkColumns.Contains(n))
                        {
                            cellValue = cell.Value;
                            stringRow.Add(cellValue);
                            cellValue = cell.HyperLink;
                        }
                    }
                    stringRow.Add(cellValue);
                }


                result.Rows.Add(stringRow.ToArray());
            }
            return(result);
        }
Exemple #2
0
 private static ExelCell[] GetNotEqualElementsCells(ExelCell[] cells)
 {
     List<ExelCell> result = new List<ExelCell>();
     foreach (ExelCell cell in cells)
         if (!result.AsParallel().Any(resItem => resItem.Value.Trim().ToLower() == cell.Value.Trim().ToLower()))
             result.Add(cell);
     return result.ToArray();
 }