how refresh excel sheet without open the file.

how i can refresh excel sheet without opening the file by using the asp.net c# code..
this is my code but their have problume .


///=============================================

    string EFile = "BExcel.xls";
            string ESFile = @System.Windows.Forms.Application.StartupPath + "\\ExcelFile\\" + EFile;
            EXL = new Excel.Application();
            EXL.DisplayFullScreen = false;
            try
            {
                EXL.WindowState = Excel.XlWindowState.xlMaximized;
                 
         
            }
            catch
            {
                MessageBox.Show("Please resize your Excel window size");
            }
            System.Windows.Forms.Application.DoEvents();
            //Workbook book =EXL.Workbooks.Add(ESFile);
            Workbook book = EXL.Workbooks.Add(ESFile);
            System.Windows.Forms.Application.DoEvents();
         
            book.RefreshAll();            
            System.Windows.Forms.Application.DoEvents();
            System.Windows.Forms.Application.DoEvents();
         
            Worksheet sheet = (Worksheet)book.ActiveSheet;            
            System.Windows.Forms.Application.DoEvents();
            System.Windows.Forms.Application.DoEvents();
         //=============================================
arunbhAsked:
Who is Participating?
 
DhaestConnect With a Mentor Commented:
You can prevent Excel hanging around by explicitly cleaning up any Excel
objects you instantiated with Marshal.ReleaseComObject and then invoking the
..NET garbage collecter before exiting.

Something like:

While (Marshal.ReleaseComObject(m_excelObj) <> 0) ' Repeat until no
more COM references
End While
m_excelObj = nothing
..... repeat for any other Excel objects allocated

' Invoke garbage collector before termination
GC.Collect()
GC.WaitForPendingFinalizers()

See: http://www.codeguru.com/forum/archive/index.php/t-228975.html


Office application does not quit after automation from Visual Studio .NET client
http://support.microsoft.com/default.aspx?scid=kb;en-us;317109
0
 
DhaestCommented:
Where do you have a problem ?

            EXL = new Excel.Application();
EXL.Visible = false;
            EXL.DisplayFullScreen = false;
0
 
arunbhAuthor Commented:
this code help open an Excel Sheet then system create temp excel sheet in refresh mood but that excel sheet have without (.xls). If i try more time then error produce.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
DhaestCommented:
Do you close your excel-application in your code or not ?
0
 
arunbhAuthor Commented:
when more time active an excel sheet then this error produce:---{ Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))}.
 task Manager Processes there have more EXCEL.EXE is running.
I use process that help kill the process after some time produce same Error.
I Use BExcel.xls file there have data relation between MS Access table
If I change in database then change the Excel File Data.
0
 
DhaestCommented:
Worksheet sheet = (Worksheet)book.ActiveSheet;            
            System.Windows.Forms.Application.DoEvents();
            System.Windows.Forms.Application.DoEvents();

....

at the end of your procedure:
EXL.close
set book = nothing
set sheet = nothing
set EXL = nothing
0
 
arunbhAuthor Commented:
Hi
Dhaest :
I am also doing same but thats not sutisfy me
this is my code please give me any code for this solution
this very urgent me please give any solution

 private void RFExcel()
        {
         
            System.Diagnostics.Process[] ExcelPro = System.Diagnostics.Process.GetProcesses();
            foreach (System.Diagnostics.Process ProParent in ExcelPro)
            {              
                System.Diagnostics.Process[] ProName = System.Diagnostics.Process.GetProcessesByName(ProParent.ProcessName);
                foreach (System.Diagnostics.Process ProChild in ProName)
                {
                    try
                    {
                        DPValue = ProChild.ProcessName.ToString();        
                        if (DPValue.Equals("EXCEL"))
                        {
                            ProChild.Kill();
                            ProChild.Close();
                            ProChild.Dispose();
                        }
                    }
                    catch (Exception EX)
                    {
                        label1.Text = "Error!..." + EX.Message.ToString();
                    }
                }
            }
            StartExcelRefresh();
        }
        private void StartExcelRefresh()
        {
            string EFile = "BExcel.xls";
            string ESFile = @System.Windows.Forms.Application.StartupPath + "\\ExcelFile\\" + EFile;
            EXL = new Excel.Application();
            EXL.DisplayFullScreen = false;
            try
            {
                EXL.WindowState = Excel.XlWindowState.xlMaximized;
                //EXL.WindowState = Excel.XlWindowState.xlNormal;
                //EXL.Left = 0; EXL.Width = 770;
                //EXL.Top = 49.5; EXL.Height = 494;              
            }
            catch
            {
                MessageBox.Show("Please resize your Excel window size");
            }
            System.Windows.Forms.Application.DoEvents();
            Workbook book = EXL.Workbooks.Add(ESFile);
            System.Windows.Forms.Application.DoEvents();
            book.RefreshAll();            
            System.Windows.Forms.Application.DoEvents();
            System.Windows.Forms.Application.DoEvents();
            Worksheet sheet = (Worksheet)book.ActiveSheet;            
            System.Windows.Forms.Application.DoEvents();
            System.Windows.Forms.Application.DoEvents();            
            disposeExisObj();              
        }
        private void disposeExisObj()
        {
            try
            {
                if (EXL != null)
                {                    
                    //----------------
                    EXL.Visible = false;
                    EXL.DisplayAlerts = false;
                    EXL.Quit();
                    EXL = null;
                   EXL = Close();
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                   
                }            
            }
            catch
            {
           
            }
        }
0
 
arunbhAuthor Commented:
Hi
Dhaest  
Thanks more to support me. I will try this code.  If any problems then i will contact to you.
0
 
DhaestCommented:
Can you give some feedback if one of the answers was sufficient or do you still have any problems ?
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.