Mini Kabibi Habibi

Current Path : C:/Users/Public/Documents/DXperience 13.1 Demos/Data/CodeExamples/
Upload File :
Current File : C:/Users/Public/Documents/DXperience 13.1 Demos/Data/CodeExamples/RowAndColumnActions.cs

using System;
using DevExpress.Spreadsheet;
using System.Drawing;

namespace SpreadsheetExamples {
    public static class RowAndColumnActions {
        static void InsertRows(IWorkbook workbook) {
            #region #InsertRows
            Worksheet worksheet = workbook.Worksheets[0];

            // Populate cells with data.
            for (int i = 0; i < 10; i++) {
                worksheet.Cells[i, 0].Value = i + 1;
                worksheet.Cells[0, i].Value = i + 1;
            }

            // Insert a new row into the worksheet at the 3rd position.
            worksheet.Rows.Insert(2);

            // Insert five rows into the worksheet at the 8th position.
            worksheet.Rows.Insert(7, 5);
            #endregion #InsertRows
        }
        static void InsertColumns(IWorkbook workbook) {
            #region #InsertColumns
            Worksheet worksheet = workbook.Worksheets[0];

            // Populate cells with data.
            for (int i = 0; i < 10; i++) {
                worksheet.Cells[i, 0].Value = i + 1;
                worksheet.Cells[0, i].Value = i + 1;
            }
            // Insert a new column into the worksheet at the 5th position.
            worksheet.Columns.Insert(4);

            // Insert three columns into the worksheet at the 7th position.
            worksheet.Columns.Insert(6, 3);
            #endregion #InsertColumns
        }

        static void DeleteRowsColumns(IWorkbook workbook) {
            #region #DeleteRows
            Worksheet worksheet = workbook.Worksheets["Sheet1"];

            // Fill cells with data.
            for (int i = 0; i < 15; i++) {
                worksheet.Cells[i, 0].Value = i + 1;
                worksheet.Cells[0, i].Value = i + 1;
            }

            // Delete the 2nd row from the worksheet.
            worksheet.Rows.Remove(1);

            // Delete the 3rd row from the worksheet.
            worksheet.Rows[2].Delete();

            // Delete three rows from the worksheet starting from the 10th row.
            workbook.Worksheets[0].Rows.Remove(9, 3);
            #endregion #DeleteRows

            #region #DeleteColumns
            Worksheet worksheet1 = workbook.Worksheets["Sheet1"];

            // Fill cells with data.
            for (int i = 0; i < 15; i++) {
                worksheet1.Cells[i, 0].Value = i + 1;
                worksheet1.Cells[0, i].Value = i + 1;
            }
            // Delete the 2nd column from the worksheet.
            worksheet1.Columns.Remove(1);

            // Delete the 3rd column from the worksheet.
            worksheet1.Columns[2].Delete();

            // Delete three columns from the worksheet starting from the 10th column.
            workbook.Worksheets[0].Columns.Remove(9, 3);
            #endregion #DeleteColumns
        }

        static void CopyRowsColumns(IWorkbook workbook) {
            #region CopyRows

            #endregion CopyRows

            #region CopyColumns

            #endregion CopyColumns
        }

        static void ShowHideRowsColumns(IWorkbook workbook) {
            #region ShowHideRowsColumns
            Worksheet worksheet = workbook.Worksheets[0];

            // Hide the 8th row of the worksheet.
            worksheet.Rows[7].Visible = false;

            // Hide the 4th column of the worksheet.
            worksheet.Columns[3].Visible = false;

            // Populate cells with data.
            for (int i = 0; i < 10; i++) {
                worksheet.Cells[i, 0].Value = i + 1;
                worksheet.Cells[0, i].Value = i + 1;
            }
            #endregion ShowHideRowsColumns
        }

        static void SpecifyRowsHeightColumnsWidth(IWorkbook workbook) {
            #region #RowHeight
            Worksheet worksheet = workbook.Worksheets[0];

            // Set the 3rd row height to 200 layout units.
            workbook.Worksheets[0].Rows[2].Height = 200;

            // Populate cells with data.
            for (int i = 0; i < 10; i++) {
                worksheet.Cells[i, 0].Value = i + 1;
                worksheet.Cells[0, i].Value = i + 1;
            }
            #endregion #RowHeight

            #region #ColumnWidth
            Worksheet sheet = workbook.Worksheets[0];
            // Set the "C" column width to 15 characters of the font specified by the Normal style.
            sheet.Columns["C"].WidthInCharacters = 15;

            sheet.Cells["C1"].Value = 10000000000000;
            #endregion #ColumnWidth
        }
    }
}