roopteja
roopteja

Reputation: 743

Set Row height in Excel through OpenXML

I have the code for generating an Excel sheet and I want to set the Row height there.

The code is as follows:

Columns lstColumns = sheet1.Worksheet.GetFirstChild<Columns>();

bool needToInsertColumns = false;
if (lstColumns == null)
{
    lstColumns = new Columns();
    needToInsertColumns = true;
}

lstColumns.Append(
     new Column() { Min = 1, Max = 1, Width = 120, CustomWidth = true }
);

if (needToInsertColumns)
{
    sheet1.Worksheet.InsertAt(lstColumns, 0);
}

// For rows.
Row row;
row = new Row() { RowIndex = 1 };
row.Height = 100;

sheetData.Append(row);

Through the following code I am able to set the width but not the height.

Upvotes: 5

Views: 7540

Answers (1)

Kirill Kobelev
Kirill Kobelev

Reputation: 10557

Do the following:

 Row row;
 row = new Row() { RowIndex = 1 };
 row.Height = 10.0;
 row.CustomHeight = true;

or, better:

 var row = new Row { Height = 10.0, CustomHeight = true, RowIndex = 1 };

The CustomHeight property is important here.

Upvotes: 4

Related Questions