您的位置:首页 > 编程语言 > ASP

C#------Aspose.cells使用方法

2017-08-06 21:09 429 查看
转载:

http://www.cnblogs.com/muer/p/yaxle.html


代码:

public ActionResult ImportData(HttpPostedFileBase file)
{
  Workbook workbook = new Workbook();
  Worksheet sheet = workbook.Worksheets[0];

  Cells cells = sheet.Cells;
  cells[0, 1].PutValue("Income");
  cells[0, 2].PutValue("Expense");
  cells[1, 0].PutValue("Company A");
  cells[2, 0].PutValue("Company B");
  cells[3, 0].PutValue("Company C");
  cells[1, 1].PutValue(10000);
  cells[2, 1].PutValue(20000);
  cells[3, 1].PutValue(30000);
  cells[1, 2].PutValue(8000);
  cells[2, 2].PutValue(15000);
  cells[3, 2].PutValue(28000);

  int chartIndex = sheet.Charts.Add(ChartType.Column, 6, 6, 21, 15);

  Aspose.Cells.Charts.Chart chart = sheet.Charts[chartIndex];

  //第一条柱子
  chart.NSeries.Add("B2:B4", true);
  chart.NSeries.CategoryData = "A2:A4";
  Series aSeries1 = chart.NSeries[0];
  aSeries1.Name = "=B1";
  chart.NSeries.IsColorVaried = true;
  //第二条柱子
  chart.NSeries.Add("C2:C4", true);
  chart.NSeries.CategoryData = "A2:A4";
  Series aSeries2 = chart.NSeries[1];
  aSeries2.Name = "=C1";
  //修改柱子颜色
  aSeries2.Area.ForegroundColor = System.Drawing.Color.Green;

  //修改柱形图背景色
  chart.PlotArea.Area.ForegroundColor = System.Drawing.Color.FromArgb(1, 152, 186, 180);
  //修改区域背景色
  chart.ChartArea.Area.ForegroundColor = System.Drawing.Color.White;
  //显示数据表
  chart.ShowDataTable = true;
  //显示分类条
  chart.ShowLegend = true;
  chart.Title.Text = "Income Analysis";
  workbook.Save(path);
  return null;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: