Export VB.NET Charting.Chart in Excel.Chart











up vote
9
down vote

favorite












Suppose I have a Charting.Chart:



Chart with some properties



that I would like to export to an Excel.Workbook.Worksheet so that I can "play" with the data later (for example drag-and-dropping more data on the Excel chart etc.):



Don't mind the differences of the curves



Please do not mind the differences in the second chart, something as close as possible to the first one would be the optimal solution



Is there any easy way to export the first chart retaining all its properties or at least the ones accepted by Excel, or do I have to go through every single property? E.g.:



myCht.Title = myUserFormChart.Titles(0).Text
mySeries = myCht.Chart.SeriesCollection.NewSeries()
mySeries.Name = myUserFormChart.Series(0).Name
[...]









share|improve this question






















  • To my knowledge there's no interface between the .NET Chart object and Excel's Chart object. You would either have to implement your own mapping, or simply change your .NET Chart to use Excel tables for a data source.
    – DoloMike
    Feb 14 at 20:18












  • Ok, but how do I do that?
    – Noldor130884
    Feb 15 at 11:08










  • You might start here stackoverflow.com/questions/18528196/…
    – DoloMike
    Feb 15 at 13:51










  • I already saw that one, but still I don't understand. How am I supposed to provide Excel a connection to data that is not stored anywhere in files? That question and answer pose the exact opposite problem to mine, which has IMHO not the same opposite solution.
    – Noldor130884
    Feb 16 at 6:34






  • 1




    I might be misunderstanding, but from what I gather you have a System.Windows.Forms.DataVisualization.Charting.Chart that you want to convert to an Excel Chart Object so that you can easily manipulate and play with the data to see how it affects the chart. I think you're better off keeping the .NET chart and changing it's data source to Excel. Add a refresh function so that you can see the chart update when you manipulate the excel table.
    – DoloMike
    Feb 16 at 15:26















up vote
9
down vote

favorite












Suppose I have a Charting.Chart:



Chart with some properties



that I would like to export to an Excel.Workbook.Worksheet so that I can "play" with the data later (for example drag-and-dropping more data on the Excel chart etc.):



Don't mind the differences of the curves



Please do not mind the differences in the second chart, something as close as possible to the first one would be the optimal solution



Is there any easy way to export the first chart retaining all its properties or at least the ones accepted by Excel, or do I have to go through every single property? E.g.:



myCht.Title = myUserFormChart.Titles(0).Text
mySeries = myCht.Chart.SeriesCollection.NewSeries()
mySeries.Name = myUserFormChart.Series(0).Name
[...]









share|improve this question






















  • To my knowledge there's no interface between the .NET Chart object and Excel's Chart object. You would either have to implement your own mapping, or simply change your .NET Chart to use Excel tables for a data source.
    – DoloMike
    Feb 14 at 20:18












  • Ok, but how do I do that?
    – Noldor130884
    Feb 15 at 11:08










  • You might start here stackoverflow.com/questions/18528196/…
    – DoloMike
    Feb 15 at 13:51










  • I already saw that one, but still I don't understand. How am I supposed to provide Excel a connection to data that is not stored anywhere in files? That question and answer pose the exact opposite problem to mine, which has IMHO not the same opposite solution.
    – Noldor130884
    Feb 16 at 6:34






  • 1




    I might be misunderstanding, but from what I gather you have a System.Windows.Forms.DataVisualization.Charting.Chart that you want to convert to an Excel Chart Object so that you can easily manipulate and play with the data to see how it affects the chart. I think you're better off keeping the .NET chart and changing it's data source to Excel. Add a refresh function so that you can see the chart update when you manipulate the excel table.
    – DoloMike
    Feb 16 at 15:26













up vote
9
down vote

favorite









up vote
9
down vote

favorite











Suppose I have a Charting.Chart:



Chart with some properties



that I would like to export to an Excel.Workbook.Worksheet so that I can "play" with the data later (for example drag-and-dropping more data on the Excel chart etc.):



Don't mind the differences of the curves



Please do not mind the differences in the second chart, something as close as possible to the first one would be the optimal solution



Is there any easy way to export the first chart retaining all its properties or at least the ones accepted by Excel, or do I have to go through every single property? E.g.:



myCht.Title = myUserFormChart.Titles(0).Text
mySeries = myCht.Chart.SeriesCollection.NewSeries()
mySeries.Name = myUserFormChart.Series(0).Name
[...]









share|improve this question













Suppose I have a Charting.Chart:



Chart with some properties



that I would like to export to an Excel.Workbook.Worksheet so that I can "play" with the data later (for example drag-and-dropping more data on the Excel chart etc.):



Don't mind the differences of the curves



Please do not mind the differences in the second chart, something as close as possible to the first one would be the optimal solution



Is there any easy way to export the first chart retaining all its properties or at least the ones accepted by Excel, or do I have to go through every single property? E.g.:



myCht.Title = myUserFormChart.Titles(0).Text
mySeries = myCht.Chart.SeriesCollection.NewSeries()
mySeries.Name = myUserFormChart.Series(0).Name
[...]






vb.net charts interop export-to-excel






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 30 at 10:08









Noldor130884

55621030




55621030












  • To my knowledge there's no interface between the .NET Chart object and Excel's Chart object. You would either have to implement your own mapping, or simply change your .NET Chart to use Excel tables for a data source.
    – DoloMike
    Feb 14 at 20:18












  • Ok, but how do I do that?
    – Noldor130884
    Feb 15 at 11:08










  • You might start here stackoverflow.com/questions/18528196/…
    – DoloMike
    Feb 15 at 13:51










  • I already saw that one, but still I don't understand. How am I supposed to provide Excel a connection to data that is not stored anywhere in files? That question and answer pose the exact opposite problem to mine, which has IMHO not the same opposite solution.
    – Noldor130884
    Feb 16 at 6:34






  • 1




    I might be misunderstanding, but from what I gather you have a System.Windows.Forms.DataVisualization.Charting.Chart that you want to convert to an Excel Chart Object so that you can easily manipulate and play with the data to see how it affects the chart. I think you're better off keeping the .NET chart and changing it's data source to Excel. Add a refresh function so that you can see the chart update when you manipulate the excel table.
    – DoloMike
    Feb 16 at 15:26


















  • To my knowledge there's no interface between the .NET Chart object and Excel's Chart object. You would either have to implement your own mapping, or simply change your .NET Chart to use Excel tables for a data source.
    – DoloMike
    Feb 14 at 20:18












  • Ok, but how do I do that?
    – Noldor130884
    Feb 15 at 11:08










  • You might start here stackoverflow.com/questions/18528196/…
    – DoloMike
    Feb 15 at 13:51










  • I already saw that one, but still I don't understand. How am I supposed to provide Excel a connection to data that is not stored anywhere in files? That question and answer pose the exact opposite problem to mine, which has IMHO not the same opposite solution.
    – Noldor130884
    Feb 16 at 6:34






  • 1




    I might be misunderstanding, but from what I gather you have a System.Windows.Forms.DataVisualization.Charting.Chart that you want to convert to an Excel Chart Object so that you can easily manipulate and play with the data to see how it affects the chart. I think you're better off keeping the .NET chart and changing it's data source to Excel. Add a refresh function so that you can see the chart update when you manipulate the excel table.
    – DoloMike
    Feb 16 at 15:26
















To my knowledge there's no interface between the .NET Chart object and Excel's Chart object. You would either have to implement your own mapping, or simply change your .NET Chart to use Excel tables for a data source.
– DoloMike
Feb 14 at 20:18






To my knowledge there's no interface between the .NET Chart object and Excel's Chart object. You would either have to implement your own mapping, or simply change your .NET Chart to use Excel tables for a data source.
– DoloMike
Feb 14 at 20:18














Ok, but how do I do that?
– Noldor130884
Feb 15 at 11:08




Ok, but how do I do that?
– Noldor130884
Feb 15 at 11:08












You might start here stackoverflow.com/questions/18528196/…
– DoloMike
Feb 15 at 13:51




You might start here stackoverflow.com/questions/18528196/…
– DoloMike
Feb 15 at 13:51












I already saw that one, but still I don't understand. How am I supposed to provide Excel a connection to data that is not stored anywhere in files? That question and answer pose the exact opposite problem to mine, which has IMHO not the same opposite solution.
– Noldor130884
Feb 16 at 6:34




I already saw that one, but still I don't understand. How am I supposed to provide Excel a connection to data that is not stored anywhere in files? That question and answer pose the exact opposite problem to mine, which has IMHO not the same opposite solution.
– Noldor130884
Feb 16 at 6:34




1




1




I might be misunderstanding, but from what I gather you have a System.Windows.Forms.DataVisualization.Charting.Chart that you want to convert to an Excel Chart Object so that you can easily manipulate and play with the data to see how it affects the chart. I think you're better off keeping the .NET chart and changing it's data source to Excel. Add a refresh function so that you can see the chart update when you manipulate the excel table.
– DoloMike
Feb 16 at 15:26




I might be misunderstanding, but from what I gather you have a System.Windows.Forms.DataVisualization.Charting.Chart that you want to convert to an Excel Chart Object so that you can easily manipulate and play with the data to see how it affects the chart. I think you're better off keeping the .NET chart and changing it's data source to Excel. Add a refresh function so that you can see the chart update when you manipulate the excel table.
– DoloMike
Feb 16 at 15:26












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Basically you need to some kind of an export function. You want to export your application's chart to an excel worksheet. And you need an easy way to do that. According to System.Windows.Forms.DataVisualization.Charting.Chart class documentation and excel chart object's documentation there isn't an easy way to do the conversion, they have some similarities but you have to go through every single property.



However, if I was you I would use an external 3rd party open-source library like EPPlus which supports many excel features (charts included) in order to create a solid "export to excel" functionality in my application.



It is not as hard as it seems and it can be relative easy to adapt it in various chart types and / or data. An example code is as follows (don't forget to install EPPlus nuget package):



Private Sub ExportToExcel_Click(sender As Object, e As EventArgs) Handles Button5.Click
Using theExcel As OfficeOpenXml.ExcelPackage = New OfficeOpenXml.ExcelPackage
Dim theDataWorkSheet As OfficeOpenXml.ExcelWorksheet = theExcel.Workbook.Worksheets.Add("Data")

With theDataWorkSheet
'Create the data cells here...
'You can get the data from your in program arrays or directly from your chart class...
.Cells("A1").Value = 10
.Cells("A2").Value = 20
.Cells("A3").Value = 30

.Cells("B1").Value = 1
.Cells("B2").Value = 2
.Cells("B3").Value = 3
End With

Dim theChartWorkSheet As OfficeOpenXml.ExcelWorksheet = theExcel.Workbook.Worksheets.Add("Chart")
Dim theChart As OfficeOpenXml.Drawing.Chart.ExcelRadarChart = theChartWorkSheet.Drawings.AddChart("Chart", OfficeOpenXml.Drawing.Chart.eChartType.Radar)

With theChart
'Manipulate the excel chart here...

.SetPosition(1, 0, 2, 0)
.SetSize(400, 400)
.Series.Add(theDataWorkSheet.Cells(1, 1, 3, 1), theDataWorkSheet.Cells(1, 2, 3, 2))
.Title.Text = "Chart title"

'all the other required excel chart properties...
End With

'Finally save the excel file...
theExcel.SaveAs(New IO.FileInfo("c:test.xlsx"))
End Using
End Sub


Refer to EPPlus documentation for more information.




  1. Getting started

  2. Shapes, Pictures and Charts


Hope this helps.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48518743%2fexport-vb-net-charting-chart-in-excel-chart%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Basically you need to some kind of an export function. You want to export your application's chart to an excel worksheet. And you need an easy way to do that. According to System.Windows.Forms.DataVisualization.Charting.Chart class documentation and excel chart object's documentation there isn't an easy way to do the conversion, they have some similarities but you have to go through every single property.



    However, if I was you I would use an external 3rd party open-source library like EPPlus which supports many excel features (charts included) in order to create a solid "export to excel" functionality in my application.



    It is not as hard as it seems and it can be relative easy to adapt it in various chart types and / or data. An example code is as follows (don't forget to install EPPlus nuget package):



    Private Sub ExportToExcel_Click(sender As Object, e As EventArgs) Handles Button5.Click
    Using theExcel As OfficeOpenXml.ExcelPackage = New OfficeOpenXml.ExcelPackage
    Dim theDataWorkSheet As OfficeOpenXml.ExcelWorksheet = theExcel.Workbook.Worksheets.Add("Data")

    With theDataWorkSheet
    'Create the data cells here...
    'You can get the data from your in program arrays or directly from your chart class...
    .Cells("A1").Value = 10
    .Cells("A2").Value = 20
    .Cells("A3").Value = 30

    .Cells("B1").Value = 1
    .Cells("B2").Value = 2
    .Cells("B3").Value = 3
    End With

    Dim theChartWorkSheet As OfficeOpenXml.ExcelWorksheet = theExcel.Workbook.Worksheets.Add("Chart")
    Dim theChart As OfficeOpenXml.Drawing.Chart.ExcelRadarChart = theChartWorkSheet.Drawings.AddChart("Chart", OfficeOpenXml.Drawing.Chart.eChartType.Radar)

    With theChart
    'Manipulate the excel chart here...

    .SetPosition(1, 0, 2, 0)
    .SetSize(400, 400)
    .Series.Add(theDataWorkSheet.Cells(1, 1, 3, 1), theDataWorkSheet.Cells(1, 2, 3, 2))
    .Title.Text = "Chart title"

    'all the other required excel chart properties...
    End With

    'Finally save the excel file...
    theExcel.SaveAs(New IO.FileInfo("c:test.xlsx"))
    End Using
    End Sub


    Refer to EPPlus documentation for more information.




    1. Getting started

    2. Shapes, Pictures and Charts


    Hope this helps.






    share|improve this answer

























      up vote
      0
      down vote













      Basically you need to some kind of an export function. You want to export your application's chart to an excel worksheet. And you need an easy way to do that. According to System.Windows.Forms.DataVisualization.Charting.Chart class documentation and excel chart object's documentation there isn't an easy way to do the conversion, they have some similarities but you have to go through every single property.



      However, if I was you I would use an external 3rd party open-source library like EPPlus which supports many excel features (charts included) in order to create a solid "export to excel" functionality in my application.



      It is not as hard as it seems and it can be relative easy to adapt it in various chart types and / or data. An example code is as follows (don't forget to install EPPlus nuget package):



      Private Sub ExportToExcel_Click(sender As Object, e As EventArgs) Handles Button5.Click
      Using theExcel As OfficeOpenXml.ExcelPackage = New OfficeOpenXml.ExcelPackage
      Dim theDataWorkSheet As OfficeOpenXml.ExcelWorksheet = theExcel.Workbook.Worksheets.Add("Data")

      With theDataWorkSheet
      'Create the data cells here...
      'You can get the data from your in program arrays or directly from your chart class...
      .Cells("A1").Value = 10
      .Cells("A2").Value = 20
      .Cells("A3").Value = 30

      .Cells("B1").Value = 1
      .Cells("B2").Value = 2
      .Cells("B3").Value = 3
      End With

      Dim theChartWorkSheet As OfficeOpenXml.ExcelWorksheet = theExcel.Workbook.Worksheets.Add("Chart")
      Dim theChart As OfficeOpenXml.Drawing.Chart.ExcelRadarChart = theChartWorkSheet.Drawings.AddChart("Chart", OfficeOpenXml.Drawing.Chart.eChartType.Radar)

      With theChart
      'Manipulate the excel chart here...

      .SetPosition(1, 0, 2, 0)
      .SetSize(400, 400)
      .Series.Add(theDataWorkSheet.Cells(1, 1, 3, 1), theDataWorkSheet.Cells(1, 2, 3, 2))
      .Title.Text = "Chart title"

      'all the other required excel chart properties...
      End With

      'Finally save the excel file...
      theExcel.SaveAs(New IO.FileInfo("c:test.xlsx"))
      End Using
      End Sub


      Refer to EPPlus documentation for more information.




      1. Getting started

      2. Shapes, Pictures and Charts


      Hope this helps.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Basically you need to some kind of an export function. You want to export your application's chart to an excel worksheet. And you need an easy way to do that. According to System.Windows.Forms.DataVisualization.Charting.Chart class documentation and excel chart object's documentation there isn't an easy way to do the conversion, they have some similarities but you have to go through every single property.



        However, if I was you I would use an external 3rd party open-source library like EPPlus which supports many excel features (charts included) in order to create a solid "export to excel" functionality in my application.



        It is not as hard as it seems and it can be relative easy to adapt it in various chart types and / or data. An example code is as follows (don't forget to install EPPlus nuget package):



        Private Sub ExportToExcel_Click(sender As Object, e As EventArgs) Handles Button5.Click
        Using theExcel As OfficeOpenXml.ExcelPackage = New OfficeOpenXml.ExcelPackage
        Dim theDataWorkSheet As OfficeOpenXml.ExcelWorksheet = theExcel.Workbook.Worksheets.Add("Data")

        With theDataWorkSheet
        'Create the data cells here...
        'You can get the data from your in program arrays or directly from your chart class...
        .Cells("A1").Value = 10
        .Cells("A2").Value = 20
        .Cells("A3").Value = 30

        .Cells("B1").Value = 1
        .Cells("B2").Value = 2
        .Cells("B3").Value = 3
        End With

        Dim theChartWorkSheet As OfficeOpenXml.ExcelWorksheet = theExcel.Workbook.Worksheets.Add("Chart")
        Dim theChart As OfficeOpenXml.Drawing.Chart.ExcelRadarChart = theChartWorkSheet.Drawings.AddChart("Chart", OfficeOpenXml.Drawing.Chart.eChartType.Radar)

        With theChart
        'Manipulate the excel chart here...

        .SetPosition(1, 0, 2, 0)
        .SetSize(400, 400)
        .Series.Add(theDataWorkSheet.Cells(1, 1, 3, 1), theDataWorkSheet.Cells(1, 2, 3, 2))
        .Title.Text = "Chart title"

        'all the other required excel chart properties...
        End With

        'Finally save the excel file...
        theExcel.SaveAs(New IO.FileInfo("c:test.xlsx"))
        End Using
        End Sub


        Refer to EPPlus documentation for more information.




        1. Getting started

        2. Shapes, Pictures and Charts


        Hope this helps.






        share|improve this answer












        Basically you need to some kind of an export function. You want to export your application's chart to an excel worksheet. And you need an easy way to do that. According to System.Windows.Forms.DataVisualization.Charting.Chart class documentation and excel chart object's documentation there isn't an easy way to do the conversion, they have some similarities but you have to go through every single property.



        However, if I was you I would use an external 3rd party open-source library like EPPlus which supports many excel features (charts included) in order to create a solid "export to excel" functionality in my application.



        It is not as hard as it seems and it can be relative easy to adapt it in various chart types and / or data. An example code is as follows (don't forget to install EPPlus nuget package):



        Private Sub ExportToExcel_Click(sender As Object, e As EventArgs) Handles Button5.Click
        Using theExcel As OfficeOpenXml.ExcelPackage = New OfficeOpenXml.ExcelPackage
        Dim theDataWorkSheet As OfficeOpenXml.ExcelWorksheet = theExcel.Workbook.Worksheets.Add("Data")

        With theDataWorkSheet
        'Create the data cells here...
        'You can get the data from your in program arrays or directly from your chart class...
        .Cells("A1").Value = 10
        .Cells("A2").Value = 20
        .Cells("A3").Value = 30

        .Cells("B1").Value = 1
        .Cells("B2").Value = 2
        .Cells("B3").Value = 3
        End With

        Dim theChartWorkSheet As OfficeOpenXml.ExcelWorksheet = theExcel.Workbook.Worksheets.Add("Chart")
        Dim theChart As OfficeOpenXml.Drawing.Chart.ExcelRadarChart = theChartWorkSheet.Drawings.AddChart("Chart", OfficeOpenXml.Drawing.Chart.eChartType.Radar)

        With theChart
        'Manipulate the excel chart here...

        .SetPosition(1, 0, 2, 0)
        .SetSize(400, 400)
        .Series.Add(theDataWorkSheet.Cells(1, 1, 3, 1), theDataWorkSheet.Cells(1, 2, 3, 2))
        .Title.Text = "Chart title"

        'all the other required excel chart properties...
        End With

        'Finally save the excel file...
        theExcel.SaveAs(New IO.FileInfo("c:test.xlsx"))
        End Using
        End Sub


        Refer to EPPlus documentation for more information.




        1. Getting started

        2. Shapes, Pictures and Charts


        Hope this helps.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 23:43









        Christos

        2,27131830




        2,27131830






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48518743%2fexport-vb-net-charting-chart-in-excel-chart%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Full-time equivalent

            さくらももこ

            13 indicted, 8 arrested in Calif. drug cartel investigation