仅在特定的Excel行中旋转文本 [英] Rotate text only in specific Excel row

查看:78
本文介绍了仅在特定的Excel行中旋转文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Microsoft.Office.Interop旋转Excel文件中的标题.为此,我使用以下代码:

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;

结果如下:

如您所见,尽管我仅指定第一行,但每个单元都会旋转.但是,我只想旋转标题:

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:

我甚至对每列都使用for循环进行了尝试:

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?

(方法GetExcelColumnName )

推荐答案

只需转换整行1.

worksheet.Range["1:1"].Style.Orientation = Excel.XlOrientation.xlUpwards;
worksheet.Rows["1"].Style.Orientation = Excel.XlOrientation.xlUpwards;

首先,在VBA中,最好使用row(1)和.usedrange的application.intersect处理.从您的代码来看,应该是这样,

fwiw, in VBA this might be best handled with application.intersect of rows(1) and the .usedrange. From your code it looks like that would be,

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;

这篇关于仅在特定的Excel行中旋转文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆