Click here to Skip to main content
15,889,992 members
Home / Discussions / C#
   

C#

 
GeneralRe: Visual studio 2015 - Visual c# 2015 Pin
Roberto64_Ge2-Feb-17 22:42
Roberto64_Ge2-Feb-17 22:42 
Questionhow to load signature pad in c# Pin
janairie1-Feb-17 13:10
janairie1-Feb-17 13:10 
AnswerRe: how to load signature pad in c# Pin
Dave Kreskowiak1-Feb-17 13:20
mveDave Kreskowiak1-Feb-17 13:20 
AnswerRe: how to load signature pad in c# Pin
OriginalGriff1-Feb-17 21:35
mveOriginalGriff1-Feb-17 21:35 
GeneralRe: how to load signature pad in c# Pin
Daniel Pfeffer1-Feb-17 22:13
professionalDaniel Pfeffer1-Feb-17 22:13 
AnswerRe: how to load signature pad in c# Pin
Richard Deeming2-Feb-17 2:31
mveRichard Deeming2-Feb-17 2:31 
AnswerRe: how to load signature pad in c# Pin
Eddy Vluggen2-Feb-17 2:46
professionalEddy Vluggen2-Feb-17 2:46 
QuestionC#: How to copy excel cell range and chart data to power point slides Pin
Tridip Bhattacharjee31-Jan-17 2:18
professionalTridip Bhattacharjee31-Jan-17 2:18 
i have data and chart in excel work sheet which i need to copy at run time from excel to power point slides.

i have a code which is working fine but the code only can copy chart data to excel sheet not range data.

please see the scree shot of my excel. so anyone can get idea how data is there in my work sheet which i need to copy to power point slide programmatically. enter image description here

screen shot url....please see it. [screen shot url]

here is code which i am using to copy range data and chart data to power point dynamically.
C#
private void Form1_Load(object sender, EventArgs e)
{
    pptNS.ApplicationClass powerpointApplication = null;
    pptNS.Presentation pptPresentation = null;
    pptNS.Slide pptSlide = null;
    pptNS.ShapeRange shapeRange = null;

    xlNS.ApplicationClass excelApplication = null;
    xlNS.Workbook excelWorkBook = null;
    xlNS.Worksheet targetSheet = null;
    xlNS.ChartObjects chartObjects = null;
    xlNS.ChartObject existingChartObject = null;
    xlNS.Range destRange = null;

    string paramPresentationPath = @"D:\test\Chart Slide.pptx";
    string paramWorkbookPath = @"D:\test\MyExcelData.xlsx";
    object paramMissing = Type.Missing;


    try
    {
        // Create an instance of PowerPoint.
        powerpointApplication = new pptNS.ApplicationClass();

        // Create an instance Excel.          
        excelApplication = new xlNS.ApplicationClass();

        // Open the Excel workbook containing the worksheet with the chart
        // data.
        excelWorkBook = excelApplication.Workbooks.Open(paramWorkbookPath,
                        paramMissing, paramMissing, paramMissing,
                        paramMissing, paramMissing, paramMissing,
                        paramMissing, paramMissing, paramMissing,
                        paramMissing, paramMissing, paramMissing,
                        paramMissing, paramMissing);

        // Get the worksheet that contains the chart.
        targetSheet =
            (xlNS.Worksheet)(excelWorkBook.Worksheets["Spain"]);

        // Get the ChartObjects collection for the sheet.
        chartObjects =
            (xlNS.ChartObjects)(targetSheet.ChartObjects(paramMissing));



        // Create a PowerPoint presentation.
        pptPresentation = powerpointApplication.Presentations.Add(
                            Microsoft.Office.Core.MsoTriState.msoTrue);

        // Add a blank slide to the presentation.
        pptSlide =
            pptPresentation.Slides.Add(1, pptNS.PpSlideLayout.ppLayoutBlank);

        // capture range
        //var writeRange = targetSheet.Range["A1:B15"];
        destRange = targetSheet.get_Range("A1:B15");
        //copy range
        destRange.Copy();

        // Paste the chart into the PowerPoint presentation.
        shapeRange = pptSlide.Shapes.Paste();


        // Position the chart on the slide.
        shapeRange.Left = 60;
        shapeRange.Top = 100;

        // Get or capture the chart to copy.
        existingChartObject =(xlNS.ChartObject)(chartObjects.Item(1));


        // Copy the chart from the Excel worksheet to the clipboard.
        existingChartObject.Copy();

        // Paste the chart into the PowerPoint presentation.
        shapeRange = pptSlide.Shapes.Paste();
        //Position the chart on the slide.
        shapeRange.Left = 90;
        @shapeRange.Top = 100;

        // Save the presentation.
        pptPresentation.SaveAs(paramPresentationPath,
                        pptNS.PpSaveAsFileType.ppSaveAsOpenXMLPresentation,
                        Microsoft.Office.Core.MsoTriState.msoTrue);
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
    finally
    {
        // Release the PowerPoint slide object.
        shapeRange = null;
        pptSlide = null;

        // Close and release the Presentation object.
        if (pptPresentation != null)
        {
            pptPresentation.Close();
            pptPresentation = null;
        }

        // Quit PowerPoint and release the ApplicationClass object.
        if (powerpointApplication != null)
        {
            powerpointApplication.Quit();
            powerpointApplication = null;
        }

        // Release the Excel objects.
        targetSheet = null;
        chartObjects = null;
        existingChartObject = null;

        // Close and release the Excel Workbook object.
        if (excelWorkBook != null)
        {
            excelWorkBook.Close(false, paramMissing, paramMissing);
            excelWorkBook = null;
        }

        // Quit Excel and release the ApplicationClass object.
        if (excelApplication != null)
        {
            excelApplication.Quit();
            excelApplication = null;
        }

        GC.Collect();
        GC.WaitForPendingFinalizers();

    }
}


please see my code and tell me what to rectify in my code as a result cell range and chart both i can copy to power point slides.

thanks
tbhattacharjee

AnswerRe: C#: How to copy excel cell range and chart data to power point slides Pin
#realJSOP1-Feb-17 7:05
mve#realJSOP1-Feb-17 7:05 
QuestionHow to convert total database columns datetime to date in the format of dd-mm-yyyy Pin
TarunKumarSusarapu29-Jan-17 23:35
professionalTarunKumarSusarapu29-Jan-17 23:35 
AnswerRe: How to convert total database columns datetime to date in the format of dd-mm-yyyy Pin
OriginalGriff30-Jan-17 0:05
mveOriginalGriff30-Jan-17 0:05 
GeneralRe: How to convert total database columns datetime to date in the format of dd-mm-yyyy Pin
TarunKumarSusarapu30-Jan-17 0:33
professionalTarunKumarSusarapu30-Jan-17 0:33 
GeneralRe: How to convert total database columns datetime to date in the format of dd-mm-yyyy Pin
OriginalGriff30-Jan-17 0:45
mveOriginalGriff30-Jan-17 0:45 
AnswerRe: How to convert total database columns datetime to date in the format of dd-mm-yyyy Pin
CHill6030-Jan-17 1:44
mveCHill6030-Jan-17 1:44 
GeneralRe: How to convert total database columns datetime to date in the format of dd-mm-yyyy Pin
Richard Deeming30-Jan-17 2:09
mveRichard Deeming30-Jan-17 2:09 
GeneralRe: How to convert total database columns datetime to date in the format of dd-mm-yyyy Pin
TarunKumarSusarapu30-Jan-17 19:28
professionalTarunKumarSusarapu30-Jan-17 19:28 
GeneralRe: How to convert total database columns datetime to date in the format of dd-mm-yyyy Pin
Pete O'Hanlon30-Jan-17 19:43
mvePete O'Hanlon30-Jan-17 19:43 
GeneralRe: How to convert total database columns datetime to date in the format of dd-mm-yyyy Pin
TarunKumarSusarapu30-Jan-17 19:47
professionalTarunKumarSusarapu30-Jan-17 19:47 
Question.net Reading and Saving Very Large Images Pin
JBHowl26-Jan-17 3:27
JBHowl26-Jan-17 3:27 
AnswerRe: .net Reading and Saving Very Large Images Pin
Jochen Arndt26-Jan-17 3:55
professionalJochen Arndt26-Jan-17 3:55 
GeneralRe: .net Reading and Saving Very Large Images Pin
JBHowl26-Jan-17 4:25
JBHowl26-Jan-17 4:25 
GeneralRe: .net Reading and Saving Very Large Images Pin
Jochen Arndt26-Jan-17 6:08
professionalJochen Arndt26-Jan-17 6:08 
AnswerRe: .net Reading and Saving Very Large Images Pin
OriginalGriff26-Jan-17 4:31
mveOriginalGriff26-Jan-17 4:31 
AnswerRe: .net Reading and Saving Very Large Images Pin
Eddy Vluggen26-Jan-17 4:49
professionalEddy Vluggen26-Jan-17 4:49 
QuestionNeed help creating a META file (*.meta) editor Pin
KrazyMonkey Modding25-Jan-17 18:45
KrazyMonkey Modding25-Jan-17 18:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.