简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM