在页面里显示Excel的图表
2007-06-21 08:53
225 查看
后台代码:
private DateTime beforeTime; //Excel启动之前时间
private DateTime afterTime; //Excel启动之后时间
protected void Page_Load(object sender, EventArgs e)
public void KillExcelProcess()
<asp:Image ID="Image1" runat="server" ImageUrl = />
生成柱状图:
public static bool CreateChart(string chartName, Microsoft.Office.Interop.Excel._Workbook m_objBook, Microsoft.Office.Interop.Excel._Worksheet m_objSheet, string Title, string categoryTitle, string valueTile)
{
try
{
//生成一个统计图对象:
Microsoft.Office.Interop.Excel.Chart xlChart = (Microsoft.Office.Interop.Excel.Chart)m_objBook.Charts.Add(Type.Missing, m_objSheet, Type.Missing, Type.Missing);
//设定数据来源:
Microsoft.Office.Interop.Excel.Range cellRange = (Microsoft.Office.Interop.Excel.Range)m_objSheet.Cells[1, 1];
//通过向导生成Chart:
xlChart.ChartWizard(cellRange.CurrentRegion, Microsoft.Office.Interop.Excel.XlChartType.xl3DColumn, Type.Missing, Microsoft.Office.Interop.Excel.XlRowCol.xlColumns, 1, 0, true, Title, categoryTitle, valueTile, "");
//设置Chart得名称:
xlChart.Name = chartName;
//设置颜色:
Microsoft.Office.Interop.Excel.ChartGroup grp = (Microsoft.Office.Interop.Excel.ChartGroup)xlChart.ChartGroups(1);
grp.GapWidth = 20;
grp.VaryByCategories = true;
//设置圆柱形,并给它们显示加上数据标签:
Microsoft.Office.Interop.Excel.Series s = (Microsoft.Office.Interop.Excel.Series)grp.SeriesCollection(1);
s.BarShape = Microsoft.Office.Interop.Excel.XlBarShape.xlCylinder;
s.HasDataLabels = true;
//设置统计图的标题和图例的显示:
xlChart.Legend.Position = Microsoft.Office.Interop.Excel.XlLegendPosition.xlLegendPositionTop;
xlChart.ChartTitle.Font.Size = 24;
xlChart.ChartTitle.Shadow = true;
xlChart.ChartTitle.Border.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
//设置两个轴的属性,Excel.XlAxisType.xlValue对应的是Y轴,Excel.XlAxisType.xlCategory对应的是X轴:
Microsoft.Office.Interop.Excel.Axis valueAxis = (Microsoft.Office.Interop.Excel.Axis)xlChart.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlValue, Microsoft.Office.Interop.Excel.XlAxisGroup.xlPrimary);
valueAxis.AxisTitle.Orientation = -90;
Microsoft.Office.Interop.Excel.Axis categoryAxis = (Microsoft.Office.Interop.Excel.Axis)xlChart.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlCategory, Microsoft.Office.Interop.Excel.XlAxisGroup.xlPrimary);
//categoryAxis.AxisTitle.Font.Name = "MS UI Gothic";
return true;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
return false;
}
return false;
}
private DateTime beforeTime; //Excel启动之前时间
private DateTime afterTime; //Excel启动之后时间
protected void Page_Load(object sender, EventArgs e)
public void KillExcelProcess()
<asp:Image ID="Image1" runat="server" ImageUrl = />
生成柱状图:
public static bool CreateChart(string chartName, Microsoft.Office.Interop.Excel._Workbook m_objBook, Microsoft.Office.Interop.Excel._Worksheet m_objSheet, string Title, string categoryTitle, string valueTile)
{
try
{
//生成一个统计图对象:
Microsoft.Office.Interop.Excel.Chart xlChart = (Microsoft.Office.Interop.Excel.Chart)m_objBook.Charts.Add(Type.Missing, m_objSheet, Type.Missing, Type.Missing);
//设定数据来源:
Microsoft.Office.Interop.Excel.Range cellRange = (Microsoft.Office.Interop.Excel.Range)m_objSheet.Cells[1, 1];
//通过向导生成Chart:
xlChart.ChartWizard(cellRange.CurrentRegion, Microsoft.Office.Interop.Excel.XlChartType.xl3DColumn, Type.Missing, Microsoft.Office.Interop.Excel.XlRowCol.xlColumns, 1, 0, true, Title, categoryTitle, valueTile, "");
//设置Chart得名称:
xlChart.Name = chartName;
//设置颜色:
Microsoft.Office.Interop.Excel.ChartGroup grp = (Microsoft.Office.Interop.Excel.ChartGroup)xlChart.ChartGroups(1);
grp.GapWidth = 20;
grp.VaryByCategories = true;
//设置圆柱形,并给它们显示加上数据标签:
Microsoft.Office.Interop.Excel.Series s = (Microsoft.Office.Interop.Excel.Series)grp.SeriesCollection(1);
s.BarShape = Microsoft.Office.Interop.Excel.XlBarShape.xlCylinder;
s.HasDataLabels = true;
//设置统计图的标题和图例的显示:
xlChart.Legend.Position = Microsoft.Office.Interop.Excel.XlLegendPosition.xlLegendPositionTop;
xlChart.ChartTitle.Font.Size = 24;
xlChart.ChartTitle.Shadow = true;
xlChart.ChartTitle.Border.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
//设置两个轴的属性,Excel.XlAxisType.xlValue对应的是Y轴,Excel.XlAxisType.xlCategory对应的是X轴:
Microsoft.Office.Interop.Excel.Axis valueAxis = (Microsoft.Office.Interop.Excel.Axis)xlChart.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlValue, Microsoft.Office.Interop.Excel.XlAxisGroup.xlPrimary);
valueAxis.AxisTitle.Orientation = -90;
Microsoft.Office.Interop.Excel.Axis categoryAxis = (Microsoft.Office.Interop.Excel.Axis)xlChart.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlCategory, Microsoft.Office.Interop.Excel.XlAxisGroup.xlPrimary);
//categoryAxis.AxisTitle.Font.Name = "MS UI Gothic";
return true;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
return false;
}
return false;
}
相关文章推荐
- jsp页面中显示word/excel格式的文档的方法
- 在jsp页面中显示word,excel
- js import excel显示数据在页面
- 【Vegas原创】页面(图表+table+GridVie 4000 w)导出为excel(07-12-5更新版)
- 读取Excel后在JSP页面显示
- php生成图表,并和页面内容能够一起显示
- Web页面的数据导出excel时的格式问题(长数字显示为科学计数法格式等)
- java读取excel、txt 文件内容,传到、显示到另一个页面的文本框里面。
- 利用owc生成excel并且显示在页面
- JSP页面实现图片、PDF字节流的显示,Word、Excel、Zip字节流的下载功能的实现
- ThinkPHP读取excel中的图片并以blob类型存入mysql,以及从mysql读取二进制流在页面显示图片
- 在OAF页面中集成ECharts以及highcharts用于显示图表
- 关于JSP显示Excel图表的JFreeChart使用(参考网络资料)
- 如何将EXCEL显示在页面上
- 在同一页面显示多个JavaScript统计图表
- jsp页面显示数据导出到excel表中
- jsp页面显示数据导出到excel表中
- FH_1Excel报表导入,显示在JSP页面.人为判断后,不正确的数据生成PDF文档
- 页面(图表+table+GridView)导出为excel