如何获取 Excel 对象以用作 C#4 动态互操作方法调用参数?
我在与 excel 交互操作中度过了一段愉快的时光。这很容易……直到我撞到了一堵砖墙。
这就像一个魅力。
dynamic excel = System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
它允许像这样的东西
var headercell = excel.Cells(RowNumber,ColumnNumber);
headercell.Value = moddef.Name;
headercell.Orientation = -60;
headercell.Font.Color = 0x00AA00;
headercell.Interior.Color =0xCCCCCC;
headercell.Font.Size = 20;
headercell.ClearComments();
headercell.Data = "Here we are LIVE with excel";
这一切都很好,因为到目前为止我只使用简单的类型与 Excel 交互。但是,我想在桌子周围画一个边框。
var bottomright = headercell.Offset(height,width);
var wholeSection = excel.Range(headercell,bottomright);
wholeSection.BorderAround(/*what goes in here??*/);
在 msdn 文章 Range 对象成员 中 BorderAround 方法显示一些要传入的参数。到目前为止,我还没有引用 Excel 互操作程序集。我是否必须引用它才能创建 BorderAround 参数,或者是否还有其他一般技巧来指导我如何调用需要 Excel 类型参数的方法?
I have a great time interop'ing with excel. It's a breeze... until I hit a brick wall.
This works like a charm.
dynamic excel = System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
which allows stuff like
var headercell = excel.Cells(RowNumber,ColumnNumber);
headercell.Value = moddef.Name;
headercell.Orientation = -60;
headercell.Font.Color = 0x00AA00;
headercell.Interior.Color =0xCCCCCC;
headercell.Font.Size = 20;
headercell.ClearComments();
headercell.Data = "Here we are LIVE with excel";
This is all nice and well because I thus far am only using simple types interacting with excel. However, I want to draw a border around a table.
var bottomright = headercell.Offset(height,width);
var wholeSection = excel.Range(headercell,bottomright);
wholeSection.BorderAround(/*what goes in here??*/);
in the msdn article Range object members the BorderAround method displays some arguments to be passed in. Thus far, I have not had to reference the Excel interop assemblies. Do I have to reference it in order to create the BorderAround arguments or is there another general trick to how I should approach invoking methods requiring Excel type arguments?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论