?
Solved

how refresh excel sheet without open the file.

Posted on 2007-08-02
12
Medium Priority
?
970 Views
Last Modified: 2013-11-07
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();
         //=============================================
0
Comment
Question by:arunbh
  • 5
  • 4
10 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 19622722
Where do you have a problem ?

            EXL = new Excel.Application();
EXL.Visible = false;
            EXL.DisplayFullScreen = false;
0
 

Author Comment

by:arunbh
ID: 19623260
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
 
LVL 53

Expert Comment

by:Dhaest
ID: 19623283
Do you close your excel-application in your code or not ?
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:arunbh
ID: 19623422
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
 
LVL 53

Expert Comment

by:Dhaest
ID: 19623434
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
 

Author Comment

by:arunbh
ID: 19636499
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
 
LVL 53

Accepted Solution

by:
Dhaest earned 2000 total points
ID: 19643444
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
 

Author Comment

by:arunbh
ID: 19643719
Hi
Dhaest  
Thanks more to support me. I will try this code.  If any problems then i will contact to you.
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 19789434
Can you give some feedback if one of the answers was sufficient or do you still have any problems ?
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20520470
Forced accept.

Computer101
EE Admin
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question