C#Excel左右边框 [英] C# Excel Border Left and Right

查看:288
本文介绍了C#Excel左右边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在单元格上创建边框,然后在左右边框上创建边框。

I want to create border on a cell and then a left and right border.

我尝试过此代码,但无法工作:(

I tried this code but it doesnt work:(

objSheet.get_Range("F19").Borders[Excel.XlBordersIndex.xlEdgeLeft].LineStyle = true;
objSheet.get_Range("F19").Borders.Color = Color.Black;

我得到你在这里看到的第二个。边界四周)
http://i.imgur.com/EUgmJNB.png

I get the second one you see here. (A border all around) http://i.imgur.com/EUgmJNB.png

如何获得这个工作?或者是一个单元格的左边和右边的边框不可能从C#到Excel?

How can I get this working? Or is a border at the left and right side of a cell not possible from C# to Excel?

推荐答案

尝试:

var range = objSheet.get_Range("F19");
System.Drawing.Color color = System.Drawing.Color.Black;
range.Borders[XlBordersIndex.xlEdgeRight].Color = color;
range.Borders[XlBordersIndex.xlEdgeLeft].Color = color;

编辑:如果您担心清理Excel对象,并且希望避免使用两个点(参见此处的讨论 a>),你可以保持引用你使用的边框,像这样:

If you're worried about cleaning up your Excel objects and you want to avoid using two dots (see discussion here), you can keep a reference the the borders that you use like so:

var right = range.Borders[XlBordersIndex.xlEdgeRight];
var left = range.Borders[XlBordersIndex.xlEdgeLeft];
right.Color = color;
left.Color = color;

我认为我的原始版本间接使用两个点。

I think my original version indirectly uses two dots.

这篇关于C#Excel左右边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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