Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Excel Exception from HRESULT: 0x800AC472

Excel Exception from HRESULT: 0x800AC472

Scheduled Pinned Locked Moved C#
helpcsharp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KaurGurpreet
    wrote on last edited by
    #1

    Excel Exception from HRESULT: 0x800AC472 I am exporting data to excel thru C# code. while export is in progress, if I open any excel file (not necessariliy the one being created), I get the above error. Earlier I was exporting on a background thread, but after reading various comments on google, I removed the background thread but the problem still exists.

    Gurpreet

    L 1 Reply Last reply
    0
    • K KaurGurpreet

      Excel Exception from HRESULT: 0x800AC472 I am exporting data to excel thru C# code. while export is in progress, if I open any excel file (not necessariliy the one being created), I get the above error. Earlier I was exporting on a background thread, but after reading various comments on google, I removed the background thread but the problem still exists.

      Gurpreet

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      this probably can help you: http://social.msdn.microsoft.com/forums/en-US/vsto/thread/9168f9f2-e5bc-4535-8d7d-4e374ab8ff09/[^]

      K 1 Reply Last reply
      0
      • L Lost User

        this probably can help you: http://social.msdn.microsoft.com/forums/en-US/vsto/thread/9168f9f2-e5bc-4535-8d7d-4e374ab8ff09/[^]

        K Offline
        K Offline
        KaurGurpreet
        wrote on last edited by
        #3

        I have created a simple application to show the problem:

        namespace WindowsFormsApplication1
        {
        public partial class Form1 : Form
        {

        Microsoft.Office.Interop.Excel.Application \_objAppln;
        Workbook \_objWorkBook;
        Workbooks \_objWorkBooks;
        Worksheet \_objWorkSheet;
        
        
        public Form1()
        {
          InitializeComponent();
          InitializeExcelObjectModel();
        }
        
        ~Form1()
        {
          DisposeExcelObjects();
        }
        
        void SaveExcel()
        {
        
          \_objAppln.DisplayAlerts = false;//Since, we are using SaveFileDialog's overwrite prompt(control is on view). 
          
          \_objWorkBook.SaveAs("C:\\\\tmp.xls",
            XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, false, Type.Missing, XlSaveAsAccessMode.xlNoChange,
            Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
          \_objWorkBook.Close(true, "C:\\\\tmp.xls", false);
          \_objAppln.DisplayAlerts = true;//restore back for other display alerts 
        }
        
        private void InitializeExcelObjectModel()
        {
        
          \_objAppln = new Microsoft.Office.Interop.Excel.Application(); // To initialize excel file   
          //\_objAppln.Visible = true; 
          if (\_objAppln != null)
          {
            \_objWorkBooks = \_objAppln.Workbooks;
            \_objWorkBook = \_objWorkBooks.Add(Type.Missing); // To add workbook with sheets in excel file         
            \_objWorkSheet = (Worksheet)\_objAppln.ActiveSheet; // To get the current active sheet in excel file              
        
          }
        }
        
        public void DisposeExcelObjects()
        {
        
          System.Runtime.InteropServices.Marshal.ReleaseComObject(\_objWorkSheet);
          System.Runtime.InteropServices.Marshal.ReleaseComObject(\_objWorkBook);
          System.Runtime.InteropServices.Marshal.ReleaseComObject(\_objWorkBooks);
          System.Runtime.InteropServices.Marshal.ReleaseComObject(\_objAppln);
          \_objWorkSheet = null; \_objWorkBooks = null; \_objWorkBooks = null; \_objAppln = null;
        }
        
        private void button1\_Click(object sender, EventArgs e)
        {
          string cell1 = string.Empty, cell2 = string.Empty;
          string\[\] chars = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T" };
        
        
          for (int row = 1; row < 1000; row++)
          {
            for (int column = 0; column < 20; column++)
            {
              cell1 = chars\[column\] + row.ToString();
              Range objRange = \_objWorkSheet.get\_Range(cell1, cell1);
              objRange.Value2 = cell1;
              System.Runtime.Interop
        
        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups