Devin Rader's Blog
I write the code...

Exporting the Infragistics UltraChart to Excel

Thursday, January 05, 2006 7:11 AM
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:              'add the top title to the sheet as the header
  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:              'output the headers.
  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:              'Bold the headers.
  26:              sheet.Range("A2:" & Chr(64 + intCol) & "2").Font.Bold = True
  27:              sheet.Range("A2:" & Chr(64 + intCol) & "2").Font.Size = 12
  28:   
  29:              'start our data on row 3 of the worksheet.
  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:              ' Adds a chart at x = 0, y = 0, 500 points wide and 300 tall.
  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:              'add 64 to intCol since ASCII A is 65 and then take the Chr() of it.BR>
  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


  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Feedback

# re: Exporting the Infragistics UltraChart to Excel

ur code is hard to understand and its not working
also 1/24/2008 9:39 PM | Kamal

# re: Exporting the Infragistics UltraChart to Excel

which namespace you used for Excel.Application
1/27/2008 8:39 PM | Ranjan

# re: Exporting the Infragistics UltraChart to Excel

chart is not displaying.
what are the use of:
Dim xlsAxisCategory, xlsAxisValue As Excel.Axes
Dim xlsSerie As Excel.SeriesCollection = oChart.SeriesCollection
6/24/2008 8:19 PM | Alok Roy

# re: Exporting the Infragistics UltraChart to Excel

You have c# version for this code 3/3/2009 11:25 PM | Abu Mathew

# re: Exporting the Infragistics UltraChart to Excel

Anybodz have C# code for this export? 4/1/2009 8:03 PM | Abu Mathew

# re: Exporting the Infragistics UltraChart to Excel

if you test for the properties to be MBT M.Walk 3/9/2010 2:30 AM | MBT Chapa

# re: Exporting the Infragistics UltraChart to Excel


Rinaldi was talking with the other nurse. They were laughing. "What an odd thing--to be in the Italian army."
"It's not really the army. It's only the ambulance." MBT Wingu 4/25/2010 9:31 PM | cheap uggs outlet

# re: Exporting the Infragistics UltraChart to Excel

Good post!As i was passing by here and i read your post.
It's quite interesting.I will look around for more such post.Thanks for sharing. 5/7/2010 9:54 PM | ED Hardy outlet

# re: Exporting the Infragistics UltraChart to Excel

Although Christianity Louboutin high-heel shoes brand Christian Louboutin Outlet, the customer is endless, now.Christian Louboutin bay Now, you can find a Christian Louboutin bay online everywhere.Cheap Christian Louboutin Shoes Sale The red shoes charm is obvious. 5/13/2010 4:22 AM | christian louboutin online

# re: Exporting the Infragistics UltraChart to Excel

Our company sells all kinds of Timberland shoes, and buy timberland shoes you will get many discount. These New timberland shoes can be shipped to the USA, the UK, Canada, and other European countries, and are still growing. Because of our nice service and good quality of the products, we have attracted a large number of customers, and established long-term cooperation with some of them. We are now enjoying the trust of our customers from many countries. Start your way of buying a Nike shoes now! Mikzeran_b 11/22/2010 9:55 PM | BUY TIMBERLAND SHOES

# re: Exporting the Infragistics UltraChart to Excel

I wasn't keen when people first started wearing UGG Australia but they have grown on me, I have recently been and brought some and I absolutely love ugg outlet, I can’t believe I hadn't got any sooner. I now want some in another color. There the most comfortable and warmest ugg boots canada I have ever owned. They also go great with skinny jeans and leggings which I always wear. mikzeran_b 11/22/2010 9:58 PM | discounted ugg boots

# re: Exporting the Infragistics UltraChart to Excel

Thank you good post very good ....I like This site! 1/27/2011 4:04 AM | cheap electronics

Post a comment