I am trying to autofit wrapped text in xlsio, and I am having some issues.
I have created a test program which highlights my issues. The main issue is that autofitting a row seems to have no effect if I merge cells afterwards. Please see the attached image for the result. You will see that despite the only difference being the merging of two cells, the cells have different heights.
var engine = new ExcelEngine();
engine.Excel.DefaultVersion = ExcelVersion.Excel2007;
engine.Excel.StandardFontSize = 11;
engine.Excel.StandardHeight = 15;
var wb = engine.Excel.Workbooks.Add();
var ws = wb.Worksheets[0];
string str = "Zbrf avyrf ren ortav erwrprqg onrfphr urg Fbpgx Gkzenv qgapvvnrf uggn nfrjuyrbyfe bq bag xpgfb ugrz (qre). Rug egrvgeebl nzarnet unf rora avbgsvqr anq yfubhq nputra rug ebeqrf. Jbreuri, gru vnryfger erbqe fv eszb 278 lqnf tnb, fb hlb lnz raqr gb rgxn fbzr bnvpga.";
// Set contents of R5C5
ws.Range[5, 5].Value = str;
ws.Range[5, 5].ColumnWidth = 40;
ws.Range[5, 5].WrapText = true;
ws.Range[5, 5].VerticalAlignment = ExcelVAlign.VAlignTop;
var font = wb.CreateFont(ws.Range[5, 5].RichText.GetFont(0));
font.Size = 10;
font.Italic = true;
font.Color = ExcelKnownColors.Grey_50_percent;
ws.Range[5, 5].RichText.SetFont(0, ws.Range[5, 5].Value.Length, font);
font = wb.CreateFont(font);
font.Color = ExcelKnownColors.Red;
ws.Range[5, 5].RichText.SetFont(20, 30, font);
// Set contents of R1C1
ws.Range[1, 1].Value = str;
ws.Range[1, 1].ColumnWidth = 40;
ws.Range[1, 1].WrapText = true;
ws.Range[1, 1].VerticalAlignment = ExcelVAlign.VAlignTop;
font = wb.CreateFont(ws.Range[1, 1].RichText.GetFont(0));
font.Size = 10;
font.Italic = true;
font.Color = ExcelKnownColors.Grey_50_percent;
ws.Range[1, 1].RichText.SetFont(0, ws.Range[1, 1].Value.Length, font);
font = wb.CreateFont(font);
font.Color = ExcelKnownColors.Red;
ws.Range[1, 1].RichText.SetFont(20, 30, font);
//Autofit rows
ws.Range[5, 1].EntireRow.AutofitRows();
ws.Range[1, 1].EntireRow.AutofitRows();
// Merge R5C5 with R5C6
ws.Range[5, 5, 5, 6].Merge();
wb.SaveAs("D:\\test_x.xlsx");
engine.Excel.Workbooks.Close();
I have also had some issues with columns not autofitting properly, and not the autofit not including filter buttons. I haven't produced any test code for this yet though.