1 使用插件名称Epplus,多个Sheet页数据应用,Demo为柱状图(Epplus支持多种图表)

2 Epplus 的安装和引用

新建一个工程文件或控制台应用程序 打开 Vs2017 Tools 的Nuget 包管理器,使用命令 install-package Epplus

3 开始在创建的工程中编写代码,实现功能

4 具体实现流程代码如下:

 using OfficeOpenXml;
using OfficeOpenXml.Drawing;
using OfficeOpenXml.Drawing.Chart;
using OfficeOpenXml.Style;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace EpplusTest
{
public class Program
{
static void Main(string[] args)
{
FileInfo newFile = new FileInfo(@"d:\test.xlsx");
if (newFile.Exists)
{
newFile.Delete();
newFile = new FileInfo(@"d:\test.xlsx");
} using (ExcelPackage package = new ExcelPackage(newFile))
{
#region 创建多个Sheet页
for (int i = ; i < ; i++)
{
package.Workbook.Worksheets.Add("Demo" + i);
}
ExcelWorksheet worksheet = package.Workbook.Worksheets["Demo0"];
ExcelWorksheet worksheet1 = package.Workbook.Worksheets["Demo1"]; #endregion #region 1 模拟填充数据
worksheet1.Cells[, ].Value = "名称";
worksheet1.Cells[, ].Value = "价格";
worksheet1.Cells[, ].Value = "销量"; worksheet1.Cells[, ].Value = "苹果";
worksheet1.Cells[, ].Value = ;
worksheet1.Cells[, ].Value = ; worksheet1.Cells[, ].Value = "华为";
worksheet1.Cells[, ].Value = ;
worksheet1.Cells[, ].Value = ; worksheet1.Cells[, ].Value = "小米";
worksheet1.Cells[, ].Value = ;
worksheet1.Cells[, ].Value = ; worksheet1.Cells[, ].Value = "OPPO";
worksheet1.Cells[, ].Value = ;
worksheet1.Cells[, ].Value = ;
#endregion #region 2 构造图表
worksheet.Cells.Style.WrapText = true;
worksheet.View.ShowGridLines = false;//去掉sheet的网格线
using (ExcelRange range = worksheet.Cells[, , , ])
{
range.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
range.Style.VerticalAlignment = ExcelVerticalAlignment.Center;
} using (ExcelRange range = worksheet.Cells[, , , ])
{
range.Style.Font.Bold = true;
range.Style.Font.Color.SetColor(Color.White);
range.Style.Font.Name = "微软雅黑";
range.Style.Font.Size = ;
range.Style.Fill.PatternType = ExcelFillStyle.Solid;
range.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(, , ));
} worksheet1.Cells[, ].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(, , ));
worksheet1.Cells[, ].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(, , ));
worksheet1.Cells[, ].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(, , )); worksheet1.Cells[, ].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(, , ));
worksheet1.Cells[, ].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(, , ));
worksheet1.Cells[, ].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(, , )); worksheet1.Cells[, ].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(, , ));
worksheet1.Cells[, ].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(, , ));
worksheet1.Cells[, ].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(, , )); worksheet1.Cells[, ].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(, , ));
worksheet1.Cells[, ].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(, , ));
worksheet1.Cells[, ].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(, , )); worksheet1.Cells[, ].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(, , ));
worksheet1.Cells[, ].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(, , ));
worksheet1.Cells[, ].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(, , )); ExcelChart chart = worksheet.Drawings.AddChart("chart", eChartType.ColumnClustered);
ExcelChartSerie serie = chart.Series.Add(worksheet1.Cells[, , , ], worksheet1.Cells[, , , ]);//引用worksheet1的数据填充图表的X轴和Y轴
serie.HeaderAddress = worksheet1.Cells[, ];
#endregion #region 3 设置图表的样式
chart.SetPosition(, );
chart.SetSize(, );
chart.Title.Text = "销量走势";
chart.Title.Font.Color = Color.FromArgb(, , );
chart.Title.Font.Size = ;
chart.Title.Font.Bold = true;
chart.Style = eChartStyle.Style15;
chart.Legend.Border.LineStyle = eLineStyle.SystemDash;
chart.Legend.Border.Fill.Color = Color.FromArgb(, , );
#endregion
package.Save();
}
}
}
}

5 效果展示:

6 Demo源码GitHub下载地址:https://github.com/HJ520134/.NetDemo.git

.Net Excel 导出图表Demo(柱状图,多标签页)的更多相关文章

  1. .Net Excel 导出图表Demo(柱状图,多标签页) .net工具类 分享一个简单的随机分红包的实现方式

    .Net Excel 导出图表Demo(柱状图,多标签页) 1 使用插件名称Epplus,多个Sheet页数据应用,Demo为柱状图(Epplus支持多种图表) 2 Epplus 的安装和引用 新建一 ...

  2. 标签页QTabWidget

    样式: import sys from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import QApplication, QWidget, QTab ...

  3. 二十六、【开源框架】EFW框架Winform前端开发之Grid++Report报表、条形码、Excel导出、图表控件

    回<[开源]EFW框架系列文章索引>        EFW框架源代码下载V1.2:http://pan.baidu.com/s/1hcnuA EFW框架实例源代码下载:http://pan ...

  4. 在excel图表上添加数据标签

    在excel图表上添加数据标签 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 https://zhidao.baidu.com/question/47838665 方法与步骤 在E ...

  5. Excel催化剂图表系列之品味IBCS瀑布图观察企业利润构成

    IBCS图表,每个细节都值得反复琢磨参悟,此篇给大家送上详尽的瀑布图方式下的利润数据观察.请不要拿Excel2016版提供的瀑布图与IBCS版的瀑布图作对比,那完全不是一个级别的,可以类比为拿一辆经济 ...

  6. Java利用Apache poi导出图表

    jar compile('org.apache.poi:poi:4.0.1') compile('org.apache.poi:poi-scratchpad:4.0.1') compile('org. ...

  7. 基于springboot跟poi封装的最便捷的excel导出

    发布时间:2018-11-15   技术:springboot1.5.6 + maven3.0.5 + jdk1.8   概述 Springboot最便捷的Excel导出,只需要一个配置文件即可搞定 ...

  8. js插件---在线类似excel生成图表插件解决方案

    js插件---在线类似excel生成图表插件解决方案 一.总结 一句话总结:google比百度好用多了,多用google google js editable table jquery 双向绑定 这种 ...

  9. Excel催化剂图表系列之一键完成IBCS国际商业标准图表

    在数据分析领域,最后一公里的图表输出,是一片十分广阔的领域.一直以来,笔者深知不是这一方面的能手,学习上也仅仅是浅尝而止.没有往其深入研究并有所产出.很幸运地在数据圈子能够结识到其他的志同道合的伙伴, ...

随机推荐

  1. 4.再来看看逆向——OD的简介

    目录 1.前言 2.一些设置和配置 3.开始了解OD 代码窗口 数据窗口 小端序问题 前言 前3节主要写了恶意代码用到的手段,接下来先写一下关于逆向调试的一些内容.毕竟逆向比较难理解一点. 一些配置和 ...

  2. 菜鸡谈OO 第一单元总结

    “OOP永远是我的好朋友爸爸!” ——来自某无能狂怒的菜鸡 身处在OO的第一个摸鱼黄金周中的我,感觉到了巨大的满足感.如果写博客这种充满意义的事情可以代替我们亲爱的作业,那么我提议每周来两个:)下面开 ...

  3. Linux神奇命令之---tar

    在生产中会常常用到压缩,解压缩,打包,解包等,这时候tar这个万能的小老弟就是是必不可少的了.linux中最流行的tar是麻雀虽小,五脏俱全,功能强大. tar命令可以为linux的文件和目录创建档案 ...

  4. 干掉safedog命令

    sc delete safedogguardcenter    shutdown -r -t 00 两条命令搞定

  5. Windows下搭建Redis集群

    Redis集群: 如果部署到多台电脑,就跟普通的集群一样:因为Redis是单线程处理的,多核CPU也只能使用一个核, 所以部署在同一台电脑上,通过运行多个Redis实例组成集群,然后能提高CPU的利用 ...

  6. Unity进阶----AssetBundle_03(2018/11/07)

    1. 为啥有AB包? 因为资源需要更新, 避免更新一次打包一次 动态修改. 2. AB包注意啥? 依赖关系 找依赖关系应该找到对应的平台!!! 3. 打包策略是分场景打包 若文件被文件夹包含打包出来的 ...

  7. NeuChar 平台使用及开发教程(一):开始使用 NeuChar

    如果您还不知道什么是 NeuChar,或者我们为什么要做 NeuChar,请看这里. 角色 NeuChar 打通了从开发者到终端用户的完整的上下游链路,了解 NeuChar 之前,先要明确两个角色身份 ...

  8. iOS URL Schemes与漏洞的碰撞组合

    iOS URL Schemes与漏洞的碰撞组合 前言 iOS URL Schemes,这个单词对于大多数人来说可能有些陌生,但是类似下面这张图的提示大部分人应该都经常看见: 今天要探究的就是:了解iO ...

  9. [Swift]LeetCode972.相等的有理数 | Equal Rational Numbers

    Given two strings S and T, each of which represents a non-negative rational number, return True if a ...

  10. OpenOCD的概念,安装和使用

    概念: OpenOCD是一个运行于PC上的开源调试软件,它可以控制包括Wiggler之内的很多JTAG硬件:我们可以将它理解为一种GDB服务程序.OpenOCD的源码只能通过SVN下载,地址是:svn ...