Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8576205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:52:30+00:00 2026-06-11T19:52:30+00:00

I am trying to insert a picture into Excel Spread Sheet using my C#

  • 0

I am trying to insert a picture into Excel Spread Sheet using my C# application.

I have used the following as my source. http://csharp.net-informations.com/excel/csharp-insert-picture-excel.htm

This whole line is underlined in blue.

 xlWorkSheet.Shapes.AddPicture("C:\\pic.JPG", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, 50, 50, 300, 45); 

My Code:

private void btnWriteSpreedSheet_Click(object sender, EventArgs e)
{
    Excel.Application xlApp;
    Excel.Workbook xlWorkBook;
    Excel.Worksheet xlWorkSheet;
    object misValue = System.Reflection.Missing.Value;

    xlApp = new Excel.ApplicationClass();
    xlWorkBook = xlApp.Workbooks.Add(misValue);
    xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

    //xlWorkSheet.SetBackgroundPicture("C:/Users/Shaun/Documents/Visual Studio 2010/Projects/TestXMLToEXCEL/TestXMLToEXCEL/bin/Debugpic.JPG"); //

    //add some text 
    xlWorkSheet.Cells[1, 1] = "http://csharp.net-informations.com";
    xlWorkSheet.Cells[2, 1] = "Adding picture in Excel File";

    xlWorkSheet.Shapes.AddPicture("C:\\pic.JPG", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, 50, 50, 300, 45); //C:\\csharp-xl-picture.JPG

     xlWorkBook.SaveAs("csharp.net-informations.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
    xlWorkBook.Close(true, misValue, misValue);
    xlApp.Quit();

    releaseObject(xlApp);
    releaseObject(xlWorkBook);
    releaseObject(xlWorkSheet);

    MessageBox.Show ("File created !");
}

private void releaseObject(object obj)
{
    try
    {
        System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
        obj = null;
    }
    catch (Exception ex)
    {
        obj = null;
        MessageBox.Show("Unable to release the Object " + ex.ToString());
    }
    finally
    {
        GC.Collect();
    }
}

Error messages:

The best overloaded method match for
‘Microsoft.Office.Interop.Excel.Shapes.AddPicture(string,
Microsoft.Office.Core.MsoTriState, Microsoft.Office.Core.MsoTriState,
float, float, float, float)’ has some invalid arguments

The type ‘Microsoft.Office.Core.MsoTriState’ is defined in an assembly
that is not referenced. You must add a reference to assembly ‘office,
Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’.

Argument 2: cannot convert from ‘Microsoft.Office.Core.MsoTriState
[c:\users\shaun\documents\visual studio
2010\Projects\TestXMLToEXCEL\TestXMLToEXCEL\CreateSpreadSheet.cs]’ to
‘Microsoft.Office.Core.MsoTriState’

Argument 3: cannot convert from ‘Microsoft.Office.Core.MsoTriState
[c:\users\shaun\documents\visual studio
2010\Projects\TestXMLToEXCEL\TestXMLToEXCEL\CreateSpreadSheet.cs]’ to
‘Microsoft.Office.Core.MsoTriState’


My References:

using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.Office.Core;
using Microsoft.Office;
using System.Xml;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:52:31+00:00Added an answer on June 11, 2026 at 7:52 pm

    Add the following references:

    • Microsoft.Office.Interop.Excel from the .Net tab
    • Microsoft Office 14.0 Object Library from the COM tab

    Add the following using statements:

    using Microsoft.Office.Core;
    using Excel = Microsoft.Office.Interop.Excel;
    using System.Runtime.InteropServices;
    

    And then here is your method (slightly altered):

    private void BtnWriteSpreedSheetClick(object sender, EventArgs e)
    {
        var xlApp = new Excel.Application();
        Excel.Workbook xlWorkBook = xlApp.Workbooks.Add();
        Excel.Worksheet xlWorkSheet = xlWorkBook.Sheets[1];
    
        xlWorkSheet.Cells[1, 1] = "http://csharp.net-informations.com";
        xlWorkSheet.Cells[2, 1] = "Adding picture in Excel File";
    
        xlWorkSheet.Shapes.AddPicture(@"C:\pic.JPG", MsoTriState.msoFalse, MsoTriState.msoCTrue, 50, 50, 300, 45);
    
        xlWorkBook.SaveAs("csharp.net-informations.xls", Excel.XlFileFormat.xlWorkbookNormal);
        xlWorkBook.Close(true);
        xlApp.Quit();
    
        Marshal.ReleaseComObject(xlApp);
    
        MessageBox.Show("File created !");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am trying to insert XML into XML Column.. getting following error: . Msg 6819,
Im trying to insert literal strings into c++ files using a c# tool, and
Trying to insert 315K Gif files into an Oracle 10g database. Everytime I get
im trying to insert this query with mysql_query INSERT INTO um_group_rights (`um_group_id`,`cms_usecase_id`,`um_right_id`) VALUES (2,1,1)
While trying to insert data to my SQl db i get the following error
I'm trying to insert into an array at a certain point: $hi = test;
I'm trying to insert a new meta tag within the Head, I'm using a
I am trying to insert an image into a table cell based off a
This is the query I am trying: INSERT INTO Product (ProductName, Description, Brand, Size,
Trying to insert a large audio file into an Oracle 10g database and keep

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.