我想使用Microsoft.Office.Interop
旋转 Excel 文件中的标题。为了实现这一点,我使用以下代码:
worksheet.Range["A1:" + worksheet.UsedRange.Columns.Count + "1"].Style.Orientation
= Excel.XlOrientation.xlUpwards;
结果看起来像这样:
正如你所看到的,每个单元格被旋转,虽然我只指定第一行。
我甚至尝试了for
循环的每一列:
for (int counter = 1; counter <= worksheet.UsedRange.Columns.Count; counter++)
worksheet.Range[GetExcelColumnName(counter) + "1"].Style.Orientation
= Excel.XlOrientation.xlUpwards;
但是我得到相同的结果。我应该怎么做才能改变标题的方向?
(MethodGetExcelColumnName
)
只需转换整个行 1。
worksheet.Range["1:1"].Style.Orientation = Excel.XlOrientation.xlUpwards;
worksheet.Rows["1"].Style.Orientation = Excel.XlOrientation.xlUpwards;
fwiw,在 VBA 中,最好使用 application.intersect of rows(1)和.usedrange 来处理。从你的代码看起来像这样,
Excel.Intersect(worksheet.Range["1:1"], worksheet.UsedRange).Style.Orientation = Excel.XlOrientation.xlUpwards;
/* just the cells, not the style */
Excel.Intersect(worksheet.Range["1:1"], worksheet.UsedRange).Cells.Orientation = Excel.XlOrientation.xlUpwards;

对我有用的是:
ws.SelectedRange[1, 1, 1, 15].Style.TextRotation = 180;
垂直文本的 TextRotation:90 或 180(向上,向下)
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(66条)