AutoFitColumn and AutoFitRow methods

Hello,

I have some problems generating the excel with autofit rows and columns. I use the AutoFitColumn() and AutoFitRow() methods but i can’t get the cells autofitted. If some one could give me a code snippet showing how to do this it will be great.
Below is the code that i used:

int currentLine = 0;
int currentColumn = 0;

Excel excel = new Excel();
excel.Worksheets.Add();
Worksheet ws = excel.Worksheets[0];

currentColumn ++;
ws.Cells[currentLine, currentColumn].PutValue(“Roles”);
ws.Cells[currentLine, currentColumn].Style.Rotation = 90;
ws.Cells[currentLine, currentColumn].Style.ForegroundColor = Color.Yellow;
ws.Cells[currentLine, currentColumn].Style.BackgroundColor = Color.Yellow;
ws.Cells[currentLine, currentColumn].Style.Font.IsBold = true;
ws.AutoFitColumn(currentColumn);
ws.AutoFitRow(currentLine);

currentColumn ++;
ws.Cells[currentLine, currentColumn].PutValue(“ZZZZZZZZZZZZZZZ”);
ws.Cells[currentLine, currentColumn].Style.Rotation = 90;
ws.AutoFitColumn(currentColumn);
ws.AutoFitRow(currentLine);

currentColumn ++;
ws.Cells[currentLine, currentColumn].PutValue(“XXXXXXXXXXXXXXXXXX”);
ws.Cells[currentLine, currentColumn].Style.Rotation = 90;
ws.AutoFitColumn(currentColumn);
ws.AutoFitRow(currentLine);

currentColumn ++;
ws.Cells[currentLine, currentColumn].PutValue(“VVVVVVVVVVV”);
ws.Cells[currentLine, currentColumn].Style.Rotation = 90;
ws.AutoFitColumn(currentColumn);
ws.AutoFitRow(currentLine);

currentColumn = 0;
currentLine ++;
ws.Cells[currentLine,currentColumn].PutValue(“Courses”);
ws.Cells[currentLine, currentColumn].Style.ForegroundColor = Color.Yellow;
ws.Cells[currentLine, currentColumn].Style.BackgroundColor = Color.Yellow;
ws.Cells[currentLine, currentColumn].Style.Font.IsBold = true;
ws.AutoFitColumn(currentColumn);

currentLine ++;
ws.Cells[currentLine,currentColumn].PutValue(“Aaaaaaaaaaaaaaaaa”);
ws.AutoFitColumn(currentColumn);

currentLine ++;
//currentColumn ++;
ws.Cells[currentLine,currentColumn].PutValue(“Bbbbbbbbbbbbbbbbbbb”);
ws.AutoFitColumn(currentColumn);

currentLine ++;
//currentColumn ++;
ws.Cells[currentLine,currentColumn].PutValue(“Ccccccccccccccccc”);
ws.AutoFitColumn(currentColumn);

excel.Save(“D:\myexcel.xls”,FileFormatType.Default);

The problem is that the column with 90 orientation are not autofitted.

Thanks,

Marius

Hi Marius,

AutoFit for rotate text is not supported yet. I will make it in the next week.

Hi,

Anything new regarding the autofitrow and autofitcolumn functionality?

thanks,

All the best,
Marius

Hi Marius,

Not ready yet. Something stuck me. You will get them on next Monday. Thanks for your patience.

Please try this attached version.