我们如何从C#设置Excel图表的位置? [英] How do we set the position of an Excel chart from C#?

查看:345
本文介绍了我们如何从C#设置Excel图表的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从C#生成一个Excel图表。图表生成只是发现,但它总是出现在屏幕的中心。如何设置图表的位置?

I am trying to generate an Excel chart from C#. Chart is generated just find but it allways appears at the center of the screen. How can I set the position of the chart?

感谢。

我的代码看起来像这样: p>

My code looks like this:

Microsoft.Office.Interop.Excel._Workbook ebook = (Microsoft.Office.Interop.Excel._Workbook)etablo.Workbooks.Add(true);

Microsoft.Office.Interop.Excel._Worksheet esheet = (Microsoft.Office.Interop.Excel._Worksheet)ebook.ActiveSheet;

_Chart grafik1 = (Chart)ebook.Charts.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing);

/* Add Data From Cells here */
/* Then */
grafik1.Location(XlChartLocation.xlLocationAsObject, esheet.Name);


推荐答案

形状对象:

例如:

esheet.Shapes.Item("Chart 1").Top = 100;
esheet.Shapes.Item("Chart 1").Left = 250;


// or you can handle shape by index - indexes start from 1 so esheet.Shapes.Item(1).Top

我想,您想要设置正确的相关单元格的位置,例如:

i think, you would like to set position right the relevating cells, for example:

esheet.Shapes.Item("Chart 1").Top = (float)(double)esheet.get_Range("A5","A6").Top;

所以...我希望这将有助于:)

so ...i hope this will help :)

Luboss

这篇关于我们如何从C#设置Excel图表的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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