Ejemplo n.º 1
0
        /// <summary>
        /// Create rows in the spreadsheet
        /// </summary>
        /// <param name="rowCount">Number of rows to create</param>
        private void RenderRows(int rowCount)
        {
            // We're iterating from row index 1 because we want the title of the rows
            // to be equal to the index. In addition, row 0 is the column header row
            for (int rowIndex = 1; rowIndex <= rowCount; rowIndex++)
            {
                // Create a new row in the table
                TableRowElement row = _table.InsertRow(rowIndex);

                // Create a row header cell and set its id and value to the row index
                TableCellElement cell = row.InsertCell(0);
                cell.ID          = rowIndex.ToString();
                cell.TextContent = rowIndex.ToString();

                // Create cells for each column in the spreadsheet from A to Z
                for (int cellIndex = 65; cellIndex < 91; cellIndex++)
                {
                    // Insert cells at the corresponding column index (starting from column 1)
                    cell = row.InsertCell(cellIndex - 64);

                    // Create a text input element inside the cell
                    InputElement input = (InputElement)Document.CreateElement("input");
                    input.Type = "text";

                    // Set the ID of the element to the Column Letter and Row Number like A1, B1, etc.
                    input.ID = string.FromCharCode(cellIndex) + rowIndex;

                    // Add the input element as a child of the cell
                    cell.AppendChild(input);

                    // Create and attach spreadsheet events to this input element
                    AttachEvents(input);
                }
            }
        }