仅在特定 Excel行中旋转文本

我想使用Microsoft.Office.Interop旋转 Excel 文件中的标题。为了实现这一点,我使用以下代码:

我想使用Microsoft.Office.Interop旋转 Excel 文件中的标题。为了实现这一点,我使用以下代码:

worksheet.Range["A1:" + worksheet.UsedRange.Columns.Count + "1"].Style.Orientation
    = Excel.XlOrientation.xlUpwards;

结果看起来像这样:

Rotated cells

正如你所看到的,每个单元格被旋转,虽然我只指定第一行。

Rotated headers

我甚至尝试了for循环的每一列:

for (int counter = 1; counter <= worksheet.UsedRange.Columns.Count; counter++)
    worksheet.Range[GetExcelColumnName(counter) + "1"].Style.Orientation
        = Excel.XlOrientation.xlUpwards;

但是我得到相同的结果。我应该怎么做才能改变标题的方向?

(MethodGetExcelColumnName)
4

只需转换整个行 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;
0

对我有用的是:

ws.SelectedRange[1, 1, 1, 15].Style.TextRotation = 180;

垂直文本的 TextRotation:90 或 180(向上,向下)

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(574)
如何总结列直到当前行 (how to sum column in excel)
上一篇
如何将Excel表格保存为多个页面中的Word文档
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(66条)