中间对齐excel文件中每行的文本 [英] Middle align the text in each row in excel file
本文介绍了中间对齐excel文件中每行的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在excel文件的每一行中间对齐文本。但在我尝试过的所有代码之后,似乎都没有。以下是我的代码:
Hi, i want to middle align the text in each row of excel file. But after all the codes that i have tried, none seems to work. Below are my codes:
workSheet.get_Range("A", "AV").Rows.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
它给我以下错误:
COMExceltion被捕获
来自HRESULT的异常:0x800A03EC
it give me the following error:
COMExceltion was caught
Exception from HRESULT: 0x800A03EC
推荐答案
尝试以下
try below
Excel.Range last = workSheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing);
Excel.Range range = sheet.get_Range("A1", last);
range.Style.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
Excel.Range last = workSheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing);
Excel.Range range = workSheet.get_Range("A2", last);
range.WrapText = false;
感谢DamithSL ,我已根据要求修改了他的解决方案。
thanks to DamithSL, i have modify his solutions as according to the requirement.
这篇关于中间对齐excel文件中每行的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文