我想使用以下命令旋转 Excel 文件中的标题Microsoft.Office.Interop
。为了实现这一目标,我使用以下代码:
worksheet.Range["A1:" + worksheet.UsedRange.Columns.Count + "1"].Style.Orientation
= Excel.XlOrientation.xlUpwards;
结果如下:
如你看到的,every尽管我只指定了第一行,但单元格会旋转。但是,我只想旋转标题:
我什至尝试过for
对每一列循环:
for (int counter = 1; counter <= worksheet.UsedRange.Columns.Count; counter++)
worksheet.Range[GetExcelColumnName(counter) + "1"].Style.Orientation
= Excel.XlOrientation.xlUpwards;
但我得到了同样的结果。我应该怎么做才能只改变标题的方向?
(Method GetExcelColumnName https://stackoverflow.com/questions/181596/how-to-convert-a-column-number-eg-127-into-an-excel-column-eg-aa)
只需转换整个第 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;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)