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. selenium webdriver定位不到元素的五种原因及解决办法

    1.动态id定位不到元素 for example:        //WebElement xiexin_element = driver.findElement(By.id("_mail_ ...

  2. 将字符串XX,SS以“,”符号进行区分并分别存储在数组中

    public static void main(String[] args) { String str = "EAN_13,1534651"; String strs[] = st ...

  3. SSIS - 5.优先约束

      一.优先约束和执行逻辑 任务和容器是SSIS中的可执行文件,一个优先约束连接着两个可执行文件:优先的可执行文件和约束的可执行文件,如下图. 它的执行逻辑如下图: 1)先执行优先可执行文件 2)判断 ...

  4. 分布式、服务化的ERP系统架构设计

    ERP之痛 曾几何时,我混迹于电商.珠宝行业4年多,为这两个行业开发过两套大型业务系统(ERP).作为一个ERP系统,系统主要功能模块无非是订单管理.商品管理.生产采购.仓库管理.物流管理.财务管理等 ...

  5. 【安富莱二代示波器教程】第19章 附件E---参考资料

    第19章      附件E---参考资料 DSP教程 http://forum.armfly.com/forum.php?mod=viewthread&tid=3886 . FreeRTOS教 ...

  6. 动态规划----最长递增子序列问题(LIS)

    题目: 输出最长递增子序列的长度,如输入 4 2 3 1 5 6,输出 4 (因为 2 3 5 6组成了最长递增子序列). 暴力破解法:这种方法很简单,两层for循环搞定,时间复杂度是O(N2). 动 ...

  7. [Swift]LeetCode171. Excel表列序号 | Excel Sheet Column Number

    Given a column title as appear in an Excel sheet, return its corresponding column number. For exampl ...

  8. [Swift]LeetCode775. 全局倒置与局部倒置 | Global and Local Inversions

    We have some permutation Aof [0, 1, ..., N - 1], where N is the length of A. The number of (global) ...

  9. 《关于长沙.NET技术社区未来发展规划》问卷调查结果公布

    那些开发者们对于社区的美好期待 2月,长沙.net 技术社区自从把群拉起来开始,做了一次比较正式.题目为<关于长沙.NET技术社区未来发展规划>的问卷调查,在问卷调查中,溪源写道: 随着互 ...

  10. SpringBoot 集成Mybatis 连接Mysql数据库

    记录SpringBoot 集成Mybatis 连接数据库 防止后面忘记 1.添加Mybatis和Mysql依赖 <dependency> <groupId>org.mybati ...