Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+
Row

Worksheet.DefaultColumnWidthInPixels Property

Gets or sets the default column width in pixels.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v19.1.Core.dll

Declaration

int DefaultColumnWidthInPixels { get; set; }

Property Value

Type Description
Int32

An integer value that is a column width in pixels.

Remarks

Use the DefaultColumnWidthInPixels, Worksheet.DefaultColumnWidthInCharacters or Worksheet.DefaultColumnWidth property to set the width of worksheet columns whose width is not specified explicitly. If you need to set the width of all columns on the worksheet to the same value and override all previously applied column width settings, use the Range.ColumnWidth property of the Row object corresponding to any row on a worksheet.

For information on how to change the height of worksheet rows, see the How to: Specify Row Height or Column Width example.

Example

This example demonstrates how to control the column width on a worksheet.

  • Set the Width for Individual Columns

    To specify a column width in characters of the default font specified by the built-in Normal style, use the column’s Column.WidthInCharacters property, or the Range.ColumnWidthInCharacters property of the cell or cell range object.

    To specify a column width in pixels, use the column’s Column.WidthInPixels property.

    To set a column width in other measurement units, first set the IWorkbook.Unit property to the DocumentUnit enumeration member that corresponds to the desired units, then use the column’s Column.Width property, or the Range.ColumnWidth property of the cell or cell range object.

    Note

    If a column width is set to 0, the column is hidden. You can also use the Column.Visible property to hide a column or display the hidden column again (see the How to: Show or Hide a Row or Column document).

  • AutoFit Column Width

    To automatically change the column width to fit the contents, use the columns’s Column.AutoFit method. To quickly autofit several columns on a worksheet, use the ColumnCollection.AutoFit method.

  • Match the Width of Two Columns

    To match one column width to another, you can use the Column.Width property or Range.CopyFrom method of the column object.

  • Set the Default Column Width

    To set the default width for worksheet columns, use the Worksheet.DefaultColumnWidthInCharacters, Worksheet.DefaultColumnWidthInPixels or Worksheet.DefaultColumnWidth property. These properties do not affect columns with an explicitly specified width.

  • Set the Width for All Columns on a Worksheet

    To change the width of all columns on a worksheet, use the Range.ColumnWidthInCharacters or Range.ColumnWidth property of the Row object corresponding to any row on a worksheet. This sets the width of all columns to the same value, overriding all previously applied column width settings.

// Set the "B" column width to 30 characters of the default font that is specified by the Normal style.
worksheet.Columns["B"].WidthInCharacters = 30;

// Set the "C" column width to 15 millimeters.
workbook.Unit = DevExpress.Office.DocumentUnit.Millimeter;
worksheet.Columns["C"].Width = 15;

// Set the width of the column that contains the "E15" cell to 100 points.
workbook.Unit = DevExpress.Office.DocumentUnit.Point;
worksheet.Cells["E15"].ColumnWidth = 100;

// Set the width of all columns that contain the "F4:H7" cell range (the "F", "G" and "H" columns) to 70 points.
worksheet.Range["F4:H7"].ColumnWidth = 70;

// Set the "J" column width to the "B" column width value.
worksheet.Columns["J"].Width = worksheet.Columns["B"].Width;

// Copy the "C" column width value and assign it to the "K" column width.
worksheet.Columns["K"].CopyFrom(worksheet.Columns["C"], PasteSpecial.ColumnWidths);

// Set the default column width to 40 pixels.
worksheet.DefaultColumnWidthInPixels = 40;
See Also