예제 #1
0
 private void SetColumnHeaders()
 {
     for (int i = 0; i < mainDataGrid.ColumnCount; i++)
     {
         mainDataGrid.Columns[i].HeaderText = CellIndexConverter.NumberToLetter(i);
     }
 }
예제 #2
0
        private static SpreadsheetCell ConvertIndexToCell(string index)
        {
            string letter = Regex.Match(index, @"^[^0-9]*").Value;
            int    col    = CellIndexConverter.LetterToNumber(letter) - 1;
            int    row    = Convert.ToInt32(Regex.Match(index, @"\d+").Value) - 1;

            return(dataGrid.Rows[row].Cells[col] as SpreadsheetCell);
        }
예제 #3
0
        private static string UnravelGroupOfCells(string text)
        {
            var groups = Regex.Matches(text, @"[a-zA-Z]+[0-9]+[:][a-zA-Z]+[0-9]+");

            foreach (Match group in groups)
            {
                string groupStr    = group.Value;
                string replacement = "";
                // ISUSE SREDI OVO
                ///////////////////
                string[] cells = groupStr.Split(':');
                string   cell1 = cells[0];
                string   cell2 = cells[1];
                int      col1  = CellIndexConverter.LetterToNumber(Regex.Match(cell1, @"^[^0-9]*").Value) - 1;
                int      row1  = Convert.ToInt32(Regex.Match(cell1, @"\d+").Value);
                int      col2  = CellIndexConverter.LetterToNumber(Regex.Match(cell2, @"^[^0-9]*").Value) - 1;
                int      row2  = Convert.ToInt32(Regex.Match(cell2, @"\d+").Value);
                if (row1 == row2)
                {
                    for (int i = col1; i <= col2; i++)
                    {
                        replacement += CellIndexConverter.NumberToLetter(i) + Convert.ToString(row1) + ",";
                    }
                }
                else if (col1 == col2)
                {
                    for (int i = row1; i <= row2; i++)
                    {
                        replacement += CellIndexConverter.NumberToLetter(col1) + Convert.ToString(i) + ",";
                    }
                }
                replacement = replacement.TrimEnd(',');
                text        = text.Replace(groupStr, replacement);
                ///////////////////
            }
            return(text);
        }