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

  • SEARCH
  • Home
  • 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 9211709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:21:30+00:00 2026-06-18T01:21:30+00:00

I have code written that works fine.The code involves transferring images as well as

  • 0

I have code written that works fine.The code involves transferring images as well as text to excel cell and works fine on one of clients computer her get the error:

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Office.Interop.Excel, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.Office.Interop.Excel, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'

CODE TO EXPORT DATATABLE TO EXCEL:

   string ImageFolderPath = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\Images\\";

        SaveFileDialog saveFileDialog1=new SaveFileDialog();
        saveFileDialog1.Filter = "Excel (*.xls)|*.xls";
       // saveFileDialog1.Title = "Select Empty Excel Sheet";
        if (saveFileDialog1.ShowDialog() == DialogResult.OK)
        {
            if (!saveFileDialog1.FileName.Equals(String.Empty))
            {
                FileInfo f = new FileInfo(saveFileDialog1.FileName);
                if (f.Extension.Equals(".xls") || f.Extension.Equals(".xlsx"))
                {
                    Microsoft.Office.Interop.Excel.Application xlApp;
                    Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
                    Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
                    object misValue = System.Reflection.Missing.Value;

                    xlApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
                    xlWorkBook = xlApp.Workbooks.Add(misValue);
                    xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
                    int i = 0;
                    int j = 0;

                    xlWorkSheet.Cells[3, 1] = "SKU";
                    xlWorkSheet.Cells[3, 2] = "EAN IPC";
                    xlWorkSheet.Cells[3, 3] = "ASIN";
                    xlWorkSheet.Cells[3, 4] = "CONDITION";
                    xlWorkSheet.Cells[3, 5] = "PRICE";
                    xlWorkSheet.Cells[3, 6] = "PRODUCT TITLE";
                    xlWorkSheet.Cells[3, 7] = "STATUS";
                    xlWorkSheet.Cells[3, 8] = "PRODUCT IMAGE";
                    xlWorkSheet.Cells[3, 9] = "PRODUCT URL";
                    xlWorkSheet.Cells[3, 10] = "IMAGE NAME";


                    xlWorkSheet.Cells[2, 1] = "Accept Value :";
                    xlWorkSheet.Cells[2, 2] = textBox1.Text;

                    xlWorkSheet.Cells[2, 4] = "Location :";
                    xlWorkSheet.Cells[2, 5] = "Amazon.co.uk";

                    for (i = 0; i <= resultSheet.Rows.Count - 1; i++)
                    {
                        for (j = 0; j <= resultSheet.Columns.Count - 1; j++)
                        {

                            if (j == 7)
                            {
                                string imagString = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\Images\\";
                                imagString = imagString + resultSheet.Rows[i][j+2].ToString();
                                Microsoft.Office.Interop.Excel.Range oRange = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[i + 5, j + 1];
                                float Left = (float)((double)oRange.Left);
                                float Top = (float)((double)oRange.Top);
                                const float ImageSize = 32;
                                xlWorkSheet.Shapes.AddPicture(imagString, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, Left, Top, ImageSize, ImageSize);
                                oRange.RowHeight = ImageSize + 2;

                            }
                            else
                            {
                                xlWorkSheet.Cells[i + 5, j + 1] = resultSheet.Rows[i][j].ToString();

                            }
                        }
                    }

                    xlWorkBook.SaveAs(saveFileDialog1.FileName, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
                    xlWorkBook.Close(true, misValue, misValue);
                    xlApp.Quit();

                    Marshal.ReleaseComObject(xlWorkSheet);
                    Marshal.ReleaseComObject(xlWorkBook);
                    Marshal.ReleaseComObject(xlApp);
                    MessageBox.Show("Excel file created , you can find the file " + saveFileDialog1.FileName);
                }
                else
                {
                    MessageBox.Show("Invalid file type");
                }
            }
            else
            {
                MessageBox.Show("You did pick a location " +
                                "to save file to");
            }
        }

The client is using excel 2002, so not sure what to do!

  • 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-18T01:21:32+00:00Added an answer on June 18, 2026 at 1:21 am

    Here is a quick example on how to latebind with Excel. This post also covers the following

    1. Add a New worksheet (As per your request)
    2. Rename the newly added worksheet
    3. Write to a cell

    I have commented the code so you shouldn’t have any problem understanding it 🙂

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Reflection;
    
    namespace WindowsFormsApplication6
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                object xlApp;
                object xlWbCol;
                object xlWb;
                object xlSheet;
                object xlRange;
                object xlWsCol;
    
                //~~> create new Excel instance
                Type tp;
                tp = Type.GetTypeFromProgID("Excel.Application");
                xlApp = Activator.CreateInstance(tp);
    
                object[] parameter = new object[1];
                parameter[0] = true;
                xlApp.GetType().InvokeMember("Visible", BindingFlags.SetProperty, null, xlApp, parameter);
                xlApp.GetType().InvokeMember("UserControl", BindingFlags.SetProperty, null, xlApp, parameter);
    
                //~~> Get the xlWb collection
                xlWbCol = xlApp.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, null, xlApp, null);
    
                //~~> Create a new xlWb
                xlWb = xlWbCol.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, xlWbCol, null);
    
                //~~> Get the worksheet collection
                xlWsCol = xlWb.GetType().InvokeMember("WorkSheets", BindingFlags.GetProperty, null, xlApp, null);
    
                //~~> Create a new workxlSheet
                xlSheet = xlWb.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, xlWsCol, null);
    
                //~~> Rename the workxlSheet to your SO Handle
                xlSheet.GetType().InvokeMember("Name", BindingFlags.SetProperty, null, xlSheet, new object[] { "confusedMind" });
    
                //~~> Assign cell D10 to xlRange object
                xlRange = xlSheet.GetType().InvokeMember("Range", BindingFlags.GetProperty, null, xlSheet, new object[] { "D10" });
    
                //~~> Write to cell D10
                xlRange.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, xlRange, new object[] { "Blah Blah" });
    
                //~~> Release the object
                System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);
            }
        }
    }
    

    SCREENSHOT

    enter image description here

    FOLLOWUP

    To add an image use this. Change as applicable

    object xlShape;
    xlShape = xlSheet.GetType().InvokeMember("Shapes", BindingFlags.GetProperty, null, xlSheet,null);
    String imagString = @"C:\Image.jpg";
    xlSheet.GetType().InvokeMember("AddPicture", BindingFlags.InvokeMethod, null, xlShape,
    new object[] {imagString, false, true, 10, 10, 200, 200 });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a piece of code written using VS 2005 that works fine in
I have written some code for some nested for loops that works just fine.
I have an application written in C# that invokes some C code as well.
I have written a code for joining two wave files.It works fine when i
I have a custom jQuery script that works fine in all bowsers but one
I have this set of Javascript code that works fine in IE (any version),
I have written a code in C which works fine for int but when
I have written some code that works great, but I don't understand why it
I currently have code for posting data to a login page that works fine.
I have written a win application that works on a network. In one of

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.