vb 导出excel生成图表统计
Private Sub btnExprot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExprot.Click
If Not T Is Nothing Then
If T.ThreadState = ThreadState.Running Then Exit Sub
End If
T = New Thread(AddressOf Export)
T.Start()
End Sub Private Sub Export()
Dim xApp = New Excel.Application
Dim xBook As Excel.Workbook
Dim xSheet As New Excel.Worksheet
Dim charts As Object
Me.Cursor = Cursors.WaitCursor
Try
xBook = xApp.Workbooks.Add(Application.StartupPath & "\Templets\Monthly Short Ship Analysis Report.xlt")
'one plant site one sheet
For i As Integer = To ds.Tables.Count -
xSheet = xBook.Worksheets(i)
xSheet.Name = ds.Tables(i).TableName
xSheet.Activate()
xSheet.Application.WindowState = Excel.XlWindowState.xlMaximized
xSheet.Cells.NumberFormatLocal = "@" '數值型轉字符串,防止出現6.54655E+11
xApp.DisplayAlerts = False 'data
'------------------------------------------------------------------------------------
Dim data(ds.Tables(i).Rows.Count + , ) As Object
Dim j As Integer
Dim qty As Integer =
For j = To ds.Tables(i).Rows.Count -
xSheet.Range("A3").Resize(, ).Insert(Shift:=Excel.XlDirection.xlDown)
data(j, ) = ds.Tables(i).Rows(j).Item("reason")
data(j, ) = ds.Tables(i).Rows(j).Item("qty")
data(j, ) = ds.Tables(i).Rows(j).Item("percentage")
qty += ds.Tables(i).Rows(j).Item("qty")
Next
data(j, ) = "Total:"
data(j, ) = qty
data(j, ) = IIf(qty > , "100.00%", "0.00%")
xSheet.Range("A3").Resize(, ).Delete()
xSheet.Range("A2").Resize(ds.Tables(i).Rows.Count + , ).Value = data
'------------------------------------------------------------------------------------ 'charts
'------------------------------------------------------------------------------------
Dim height As Integer = xSheet.Range("A1").Resize( + ds.Tables(i).Rows.Count, ).Height
charts = xSheet.ChartObjects.Add(, height, , ).Chart
charts.SetSourceData(Source:=xSheet.Range("A2").Resize(ds.Tables(i).Rows.Count, ))
With charts
.HasTitle = True
.ChartTitle.Characters.Text = ds.Tables(i).TableName + "廠按原因縮數情況表"
With .ChartTitle.Font
.Name = "新細明體"
.Size =
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = Excel.XlUnderlineStyle.xlUnderlineStyleNone
.ColorIndex =
.Background = Excel.Constants.xlAutomatic
End With
.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary).HasTitle = False
.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary).HasTitle = False
.HasLegend = False
'show the data value
.ApplyDataLabels(AutoText:=True, LegendKey:=False, HasLeaderLines:=False, ShowSeriesName:=False, ShowCategoryName:=False, ShowValue:=True, ShowPercentage:=False, ShowBubbleSize:=False)
'X Coordinate
.Axes(Excel.XlAxisType.xlCategory).TickLabels.AutoScaleFont = True
With .Axes(Excel.XlAxisType.xlCategory).TickLabels.Font
.Name = "Arial"
.FontStyle = "標準"
.Size =
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = Excel.XlUnderlineStyle.xlUnderlineStyleNone
.ColorIndex = Excel.Constants.xlAutomatic
.Background = Excel.Constants.xlAutomatic
End With
End With
'------------------------------------------------------------------------------------
Next xApp.Range("A1").Select()
xApp.Visible = True
xApp.Caption = "Bogart Report"
xApp.ActiveWindow.Caption = "Monthly Short Ship Analysis Report"
Catch ex As Exception
MessageBox.Show(ex.ToString)
Finally
xBook = Nothing
xApp = Nothing
Me.Cursor = Cursors.Default
End Try
End Sub


vb 导出excel生成图表统计的更多相关文章
- [转] C#操作EXCEL,生成图表的全面应用
gailzhao 原文 关于C#操作EXCEL,生成图表的全面应用 近来我在开发一个运用C#生成EXCEL文档的程序,其中要根据数据生成相应的图表,该图表对颜色和格式都有严格的要求,在百度和谷歌中搜索 ...
- js插件---在线类似excel生成图表插件解决方案
js插件---在线类似excel生成图表插件解决方案 一.总结 一句话总结:google比百度好用多了,多用google google js editable table jquery 双向绑定 这种 ...
- EasyOffice-.NetCore一行代码导入导出Excel,生成Word
简介 Excel和Word操作在开发过程中经常需要使用,这类工作不涉及到核心业务,但又往往不可缺少.以往的开发方式在业务代码中直接引入NPOI.Aspose或者其他第三方库,工作繁琐,耗时多,扩展性差 ...
- NPOI导出Excel生成多个sheet
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- poi 导出excel 生成等比例图片
poi 导出的带等比例图片方法 /** * * <p>Description: 将一物一码列表导出到excel</p> * @param response * @param l ...
- 生成统计数据并导出Excel
需求:看如下表格的统计需求 生产调度中心部门需要从IT技术部门得到这些统计数据 步骤: (1)获取所有的子公司列表 (2)遍历所有的子公司,获取每个子公司的库存信息 (3)遍历所有的库存信息,并对库存 ...
- NPOI根据模板生成chart图表导出Excel
导入NPOI的全部dll. 因为NPOI的API里面还没有对于Chart图表方面的操作,所以只能根据提示做好的图表作为模板,修改数据源的方法来改变图表. 注意:NPOI要用2003版以下的excel才 ...
- BootStrap母版页布局.子页面布局.BootstrapTable.模态框.警告框.html导出tabl生成Excel.HTML生成柱图.饼图.时间控件中文版
如上就是很多后台管理系统的母版页布局. 左边一列模板.上面一列系统标识. 空白处充填子页面 以ASP.NET MVC为基础 引入bootstrap.js.bootstrap.css body: < ...
- 导出Excel之Epplus使用教程3(图表设置)
导出Excel之Epplus使用教程1(基本介绍) 导出Excel之Epplus使用教程2(样式设置) 导出Excel之Epplus使用教程3(图表设置) 导出Excel之Epplus使用教程4(其他 ...
随机推荐
- Android Mokoid Open Source Project hacking
/***************************************************************************** * Android Mokoid Open ...
- Unity3D-常用小功能详解,例子(得分变动效果、倒计时)
Unity3D-Demo多个功能方法 本文提供全流程,中文翻译.Chinar坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) 1 Score Ind ...
- 简单介绍Spring的ContextLoaderListener
在开发Spring的Web项目中,通常我们都会在web.xml中配置一个Spring的核心监听器,就是把Spring的IOC容器纳入Servlet容器中,配置如下: <listener> ...
- 51Nod 1066:Bash游戏 (巴什博弈)
1066 Bash游戏 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 有一堆石子共有N个.A B两个人轮流拿,A先拿.每次最少拿1颗,最多拿K颗,拿到 ...
- sublime text 3 实用的快捷键
Ctrl+Shift+P:打开命令面板Ctrl+P:搜索项目中的文件Ctrl+G:跳转到第几行Ctrl+W:关闭当前打开文件Ctrl+Shift+W:关闭所有打开文件Ctrl+Shift+V:粘贴并格 ...
- Ordering Tasks 拓扑排序
John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...
- CTF-练习平台-Misc之 听首音乐
十九.听首音乐 用软件audacity打开后发现如下 上面那一行是可以看做摩斯电码,翻译过来是: ..... -... -.-. ----. ..--- ..... -.... ....- ----. ...
- python 获取中文文件名的输出
#coding:utf8 if __name__ == '__main__': srcfile = u"D:/测试路径/测试文件.txt" f = open(srcfile.enc ...
- Ribbon Status Bar
https://documentation.devexpress.com/#WindowsForms/CustomDocument2498 官方文档说明 A Ribbon Status Bar (Ri ...
- Codelf 变量取名
Codelf 变量取名 可以看到别的变量是怎么命名的,站在巨人的肩膀上.