Column.ApplyStyle

Column.ApplyStyle method

Applies formats for a whole column.

public void ApplyStyle(Style style, StyleFlag flag)
ParameterTypeDescription
styleStyleThe style object which will be applied.
flagStyleFlagFlags which indicates applied formatting properties.

Examples

using System;
using Aspose.Cells;

namespace AsposeCellsExamples
{
    public class ColumnMethodApplyStyleWithStyleStyleFlagDemo
    {
        public static void Run()
        {
            Workbook workbook = new Workbook();
            Worksheet sheet = workbook.Worksheets[0];

            // Set multi-line text in column 2
            sheet.Cells[0, 1].Value = "Line1\nLine2";
            sheet.Cells[1, 1].Value = "Text with\nmultiple lines";
            sheet.Cells[2, 1].Value = "Another\nmulti-line\ntext";

            // Create style with wrap text enabled
            Style style = workbook.CreateStyle();
            style.IsTextWrapped = true;

            // Apply style only to wrap text property of column 2
            sheet.Cells.Columns[1].ApplyStyle(style, new StyleFlag() { WrapText = true });

            // Save the workbook
            workbook.Save("output.xlsx");
        }
    }
}

See Also