Aspose.Cells - 为范围设置边框 [英] Aspose.Cells - Set Border For Range

查看:1250
本文介绍了Aspose.Cells - 为范围设置边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Aspose.Cells。我基本上已经设法做我需要做的事情,但是仍然存在一个问题。我看不到一个简单的方法来将边框应用于定义的范围。我可以为一个单元格,但是当将样式应用到范围中时,范围中的所有单元格都将被格式化。

我可以看到的唯一方法是编写一个方法枚举范围内的所有单元格以确定正确的边框属性。这似乎是一个稍微可怕的方式来实现我所看到的一个简单的任务,所以希望有一个更好的办法!

是否有?

解决方案

好吧,让我们开始吧。
假设我们想添加边界到从A2单元格到H6单元格区域的范围。
请记住Aspose中的单元格索引是基于零的。
所以A2单元格的行1和列0的索引。

定义范围

Dim range = current_worksheet.Cells.CreateRange(1,0,5,8)



设置边框 p>

  range.SetOutlineBorder(Aspose.Cells.BorderType.TopBorder,Aspose.Cells.CellBorderType.Thick,Drawing.Color.Blue)
range.SetOutlineBorder(Aspose.Cells.BorderType.BottomBorder,Aspose.Cells.CellBorderType.Thick,Drawing.Color.Blue)
range.SetOutlineBorder(Aspose.Cells.BorderType.LeftBorder,Aspose.Cells.CellBorderType。 Thick,Drawing.Color.Blue)
range.SetOutlineBorder(Aspose.Cells.BorderType.RightBorder,Aspose.Cells.CellBorderType.Thick,Drawing.Color.Blue)

就是这样!


I'm currently working with Aspose.Cells. I've largely managed to do what I need to do however one issue remains; I can't see an easy way to apply a border to a defined range. I can for a cell, however when applying the style to the range all cells in the range are formatted.

The only way I can see around this is to write a method to enumerate all cells within the range to determine the right border attributes. This seems a slightly hideous way to achieve what I see as a simple task, so am hoping there is a better way!

Is there?

解决方案

Ok let's start. Assuming we want to add borders to a range from A2 cell to H6 cell range. Always remember that cell index in Aspose is Zero based. So the A2 cell has index of row 1 and column 0.

Define the range

Dim range = current_worksheet.Cells.CreateRange(1, 0, 5, 8)

Set the borders

    range.SetOutlineBorder(Aspose.Cells.BorderType.TopBorder,Aspose.Cells.CellBorderType.Thick,Drawing.Color.Blue)
range.SetOutlineBorder(Aspose.Cells.BorderType.BottomBorder,Aspose.Cells.CellBorderType.Thick, Drawing.Color.Blue)
range.SetOutlineBorder(Aspose.Cells.BorderType.LeftBorder,Aspose.Cells.CellBorderType.Thick, Drawing.Color.Blue)
range.SetOutlineBorder(Aspose.Cells.BorderType.RightBorder,Aspose.Cells.CellBorderType.Thick, Drawing.Color.Blue)

That's it!

这篇关于Aspose.Cells - 为范围设置边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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