UltraChart导出到Excel 2024-08-06 09:37:28 阅读次数:17
microsoft
Here is a simple example of exporting the UltraChart to an Excel spreadsheet. It uses Office Interop so you need to include a reference to the Microsoft Office 11 Object Library in your project. 1: Public Class Export 2: 3: Private Sub ChartToExcel(ByVal chart As Infragistics.Win.UltraWinChart.UltraChart) 4: Try 5: 6: Dim xl As New Excel.Application 7: Dim wb As Excel.Workbook = xl.Workbooks.Add 8: Dim sheet As Excel.Worksheet = wb.Worksheets(1) 9: sheet.Visible = Excel.XlSheetVisibility.xlSheetVisible 10: 11: 12: sheet.Range("A1" ).Value = chart.TitleTop.Text 13: sheet.Range("A1" ).Font.Bold = True 14: sheet.Range("A1" ).Font.Size = 14 15: 16: Dim dt As DataTable = CType (chart.DataSource, DataSet).Tables("Data" ) 17: 18: 19: Dim intCol As Integer = 1 20: For Each col As DataColumn In dt.Columns 21: sheet.Cells(2, intCol) = col.ColumnName 22: intCol += 1 23: Next 24: 25: 26: sheet.Range("A2:" & Chr(64 + intCol) & "2" ).Font.Bold = True 27: sheet.Range("A2:" & Chr(64 + intCol) & "2" ).Font.Size = 12 28: 29: 30: Dim intRow As Integer = 3 31: For Each row As DataRow In dt.Rows 32: intCol = 1 33: For Each col As DataColumn In dt.Columns 34: sheet.Cells(intRow, intCol) = row.Item(col.ColumnName) 35: intCol += 1 36: Next 37: intRow += 1 38: Next 39: 40: wb.Application.Visible = True 41: 42: Dim oChart As Excel.Chart 43: Dim xlsAxisCategory, xlsAxisValue As Excel.Axes 44: Dim charts As Excel.ChartObjects = sheet.ChartObjects(Type.Missing) 45: 46: 47: Dim chartObj As Excel.ChartObject = charts.Add(0, 0, 400, 300) 48: oChart = chartObj.Chart 49: 50: Dim xlsSerie As Excel.SeriesCollection = oChart.SeriesCollection 51: oChart.ChartType = Excel.XlChartType.xlLine 52: 53: 54: Dim chartRange As Excel.Range = sheet.Range("A1" , Chr((intCol - 1) + 64) & intRow) 55: oChart.SetSourceData(chartRange, Type.Missing) 56: 57: wb.Application.Visible = True 58: 59: Catch ex As Exception 60: Console.WriteLine("Doh!" ) 61: End Try 62: 63: End Sub 64: End Class
版权声明:本文内容来自第三方投稿或授权转载,原文地址:https://blog.csdn.net/lee576/article/details/3131375,作者:lee576,版权归原作者所有。本网站转在其作品的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如因作品内容、版权等问题需要同本网站联系,请发邮件至ctyunbbs@chinatelecom.cn沟通。
上一篇:treeview得到鼠标右键点击的节点
下一篇:SAP UI5 货币金额显示的格式化逻辑