Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-15-2012, 02:11 AM
krishnaraj.l krishnaraj.l is offline Export into excel hangs all application/keyboard inaccessible/halts the system Windows 7 64bit Export into excel hangs all application/keyboard inaccessible/halts the system Office 2007
Novice
Export into excel hangs all application/keyboard inaccessible/halts the system
 
Join Date: Jun 2012
Posts: 1
krishnaraj.l is on a distinguished road
Default Export into excel hangs all application/keyboard inaccessible/halts the system

Hi,



Our Project using Export functionality from .net 2.0 windows forms application. And it was working great in all OS and in MS Office versions except MS Office 2007 (Windows 7 OS, 64 bit).

When export excel event is fired from our application and after the report opened in MS Excel, that movement onwards none of the application can be editable.

Enclosed Complete source code here...
Code:
    public partial class ExportExcelIssue : Form
    {
        public static int Counter=0;
        public String strPath = "";

        public void CreateExcel()
        {
            Counter = Counter + 1;

            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.Cells[1, 1] = "TEST";

            string strTempPath = System.Environment.GetEnvironmentVariable("TEMP");
            DirectoryInfo objInfo = new DirectoryInfo(strTempPath);

            strPath = strTempPath + "\\Excel" + Counter + ".xls";

            xlWorkBook.SaveAs(strPath, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
            xlWorkBook.Close(true, misValue, misValue);
            xlApp.Quit();

            object Delete;
            Delete = xlApp;           

            if (!WithoutCom.Checked)
            {
                 ReleaseComObject(ref Delete);
            }

            if (!WithoutGC.Checked)
            {
                GC.Collect();
            }

            if ((GCWithWFPF.Checked & WithoutGC.Checked) || (GCWithWFPF.Checked & !WithoutGC.Checked))
            {

                GC.WaitForPendingFinalizers();
            }        

            try
            {
                System.Diagnostics.Process.Start(strPath);
            }

            catch (Exception ex)
            { MessageBox.Show(ex.Message); }

          }

         private void ReleaseComObject(ref Object o)
         {
            int releaseObject = 1;
            while (releaseObject > 0)
            {
                releaseObject = System.Runtime.InteropServices.Marshal.ReleaseComObject(o);
            };
         }

        private void button1_Click(object sender, EventArgs e)
        {
            CreateExcel();
        }


        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (GCWithWFPF.Checked)
            {
                WithoutGC.Checked = false;
                WithoutGC.Enabled = false;
            }

            else {

                WithoutGC.Enabled = true;
            }
        }

        private void WithoutGC_CheckedChanged(object sender, EventArgs e)
        {
            if (WithoutGC.Checked)
            {
                GCWithWFPF.Checked = false;
                GCWithWFPF.Enabled = false;
            }

            else
            {

                GCWithWFPF.Enabled = true;
            }

        }
  }
Reply With Quote
  #2  
Old 06-15-2012, 06:16 AM
macropod's Avatar
macropod macropod is offline Export into excel hangs all application/keyboard inaccessible/halts the system Windows 7 64bit Export into excel hangs all application/keyboard inaccessible/halts the system Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Have you confirmed that the NET framework is working correctly on the target PC? See the discussion at: http://answers.microsoft.com/en-us/w...7-ad574ee25cbd
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-17-2012, 04:00 AM
Colin Legg's Avatar
Colin Legg Colin Legg is offline Export into excel hangs all application/keyboard inaccessible/halts the system Windows 7 32bit Export into excel hangs all application/keyboard inaccessible/halts the system Office 2010 32bit
Expert
 
Join Date: Jan 2011
Location: UK
Posts: 369
Colin Legg will become famous soon enough
Default

I started a new forms project, added a button to the form and added a reference to Excel 2007 COM library and then put this simplified version of your code in my project. It ran without issue and no hanging when test report was opened. Do you have any problems when running this code?
Code:
using System;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
using System.IO;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public static int Counter = 0;
        public String strPath = "";
        public void CreateExcel()
        {
            Counter = Counter + 1;
            Excel.Application xlApp;
            Excel.Workbook xlWorkBook;
            Excel.Worksheet xlWorkSheet;
            object misValue = System.Reflection.Missing.Value;
            xlApp = new Excel.Application();
            xlWorkBook = xlApp.Workbooks.Add(misValue);
            xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
            xlWorkSheet.Cells.get_Item(1, 1).Value2 = "TEST";
            string strTempPath = System.Environment.GetEnvironmentVariable("TEMP");
            DirectoryInfo objInfo = new DirectoryInfo(strTempPath);
            strPath = strTempPath + "\\Excel" + Counter + ".xls";
            xlWorkBook.SaveAs(strPath, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
            GC.Collect();
            GC.WaitForPendingFinalizers();
            Marshal.FinalReleaseComObject(xlWorkSheet);
            xlWorkBook.Close(true, misValue, misValue);
            Marshal.FinalReleaseComObject(xlWorkBook);
            xlApp.Quit();
            Marshal.FinalReleaseComObject(xlApp);
            
        }
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            CreateExcel();
        }
    }
}
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel's Export png file judicial85 Excel 0 06-22-2011 07:22 PM
Excel hangs up when opened from outlook wewaw Office 0 05-20-2011 05:43 AM
Export into excel hangs all application/keyboard inaccessible/halts the system Export to Excel with Attachment winseelan Outlook 2 10-27-2010 01:35 AM
Error: general mail failure. Quit excel restart mail system MitchellDM Outlook 1 12-19-2008 02:05 AM
Excel 2003 will not terminate with application.quit Peter Schellenbach Excel 12 03-14-2006 05:28 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:04 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft