Results 1 to 1 of 1

How to export chart from excel to image using C#

Threaded View

  1. #1
    Registered User
    Join Date
    04-05-2012
    Location
    Karnataka,Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    1

    How to export chart from excel to image using C#

    Hi,

    Am a new user. If am posting in a wrong forum am sorry and please suggest me where I can get my problem solved.
    The problem am facing is,
    Am having 6 charts in an excel worksheet and am trying to export all the charts from excel to some jpeg file.
    Only two charts getting exported and remaining charts after I export as Image, its empty (0 kb). I can see only empty jpeg file.
    Am using C# and Asp.Net. The code what am using is,

    using X1 = Microsoft.Office.Interop.Excel;                  
    
    X1.Application x1App;
    X1.Workbook x1WorkBook;
    X1.Worksheet x1WorkSheet;
    X1.Worksheet x1WorkSheet1;
    object misValue = System.Reflection.Missing.Value;
    x1App = new X1.ApplicationClass();
    x1WorkBook = x1App.Workbooks.Open(@"C:\Temp\FlexPurchasing\XYZ.xls", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
    x1WorkSheet = (X1.Worksheet)x1WorkBook.Worksheets.get_Item(2);
    X1.ChartObjects x1Charts = (X1.ChartObjects)x1WorkSheet.ChartObjects(Type.Missing);
    X1.ChartObject myChart = (X1.ChartObject)x1Charts.Item(3);                           
    X1.Chart chartPage = myChart.Chart;
    chartPage.Export("D:\\VPR_Image.jpeg", "JPEG",true);
    x1App.Workbooks.Close();
    x1App.Quit();
    
    ReleaseObject(x1WorkSheet);
    ReleaseObject(x1WorkBook);
    ReleaseObject(x1App);

    Please give me some suggestion to export all the 6 charts from excel.
    I searched in most of the forum but I didnt get the required answer.
    Please help me out in sorting the issue.
    Urgent Please.
    Last edited by Paul; 04-05-2012 at 06:21 PM. Reason: Added CODE tags for new user. Please do so yourself in the future.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1