Excel的互操作 - 绘制所有边框的范围 [英] Excel Interop - Draw All Borders in a Range

查看:186
本文介绍了Excel的互操作 - 绘制所有边框的范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从微软的文档看,我可以访问使用xlBordersIndex的财产和例如设置边框样式单元格的左边缘细胞的特定的边框边缘:

  range.Borders [Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeLeft] .LineStyle = Excel.XlLineStyle.xlContinuous; 



但如果我只是想提请所有边界?我曾尝试

  range.BorderAround2(); 



但只是周围绘制的范围本身就是一个盒子,里面我明白了。于是我试着

  range.Cells.BorderAround2(); 



以为这样就可以通过每个小区的范围内,并且将每个细胞周围的所有边界。这不是发生。因此,为了让周围的所有单元格所有边界的范围内,我必须手动访问四个边境指数?


解决方案

 私人无效AllBorders(Excel.Borders _borders)
{
_borders [Excel.XlBordersIndex.xlEdgeLeft] .LineStyle = Excel.XlLineStyle.xlContinuous;
_borders [Excel.XlBordersIndex.xlEdgeRight] .LineStyle = Excel.XlLineStyle.xlContinuous;
_borders [Excel.XlBordersIndex.xlEdgeTop] .LineStyle = Excel.XlLineStyle.xlContinuous;
_borders [Excel.XlBordersIndex.xlEdgeBottom] .LineStyle = Excel.XlLineStyle.xlContinuous;
_borders.Color = Color.Black;
}


I see from Microsoft's documentation that I can access the particular border edges of a cell using the 'xlBordersIndex' property and for example set the border style for the left edge of a cell:

range.Borders[Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeLeft].LineStyle =     Excel.XlLineStyle.xlContinuous;

But what if I just want to draw all borders? I have tried

range.BorderAround2();

but that just draws a box around the range itself, which I understand. So then I tried

range.Cells.BorderAround2();

thinking that it would go through each of the cells within the range and place all borders around each cell. This is not what occurred. So in order to get all borders around all cells in a range, must I manually access each of the four border indices?

解决方案

private void AllBorders(Excel.Borders _borders)
    {
        _borders[Excel.XlBordersIndex.xlEdgeLeft].LineStyle = Excel.XlLineStyle.xlContinuous;
        _borders[Excel.XlBordersIndex.xlEdgeRight].LineStyle = Excel.XlLineStyle.xlContinuous;
        _borders[Excel.XlBordersIndex.xlEdgeTop].LineStyle = Excel.XlLineStyle.xlContinuous;
        _borders[Excel.XlBordersIndex.xlEdgeBottom].LineStyle = Excel.XlLineStyle.xlContinuous;
        _borders.Color = Color.Black;
    }

这篇关于Excel的互操作 - 绘制所有边框的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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