I'd like to rotate headers in an Excel file using Microsoft.Office.Interop
. To achieve this, I'm using the following code:
worksheet.Range["A1:" + worksheet.UsedRange.Columns.Count + "1"].Style.Orientation
= Excel.XlOrientation.xlUpwards;
The result looks like this:
As you can see, every cell gets rotated although I'm only specifying the first row. However, I just want the headers to be rotated:
I even tried it with a for
loop for every column:
for (int counter = 1; counter <= worksheet.UsedRange.Columns.Count; counter++)
worksheet.Range[GetExcelColumnName(counter) + "1"].Style.Orientation
= Excel.XlOrientation.xlUpwards;
But I get the same result. What should I do to only change the orientation of the headers?