//--- What is the height of row 1?
RowProperties rowProps = worksheet.GetRowProperties(0);
//--- How wide will the data be?
double requiredWidth =
wb.GetTextWidth(longTextString,
rowProps.Style.Font,
rowProps.Height);
//--- Will we need multiple columns to display all of the data?
//--- Can not exceed 255 character units in width per column.
int numCols = (int) Math.round((requiredWidth / 255) + 0.5);
//--- Evenly distribute the required width between all of the columns.
worksheet.Cells[0, 3].Value = longTextString;
a = worksheet.createArea(0, 3, 1, numCols);
a.MergeCells();
a.AllColumnWidthsInChars = (requiredWidth / numCols);
|