Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
Can any tel me how find the window handles in WPF , C#.
I've opened two excel's , now I have to get the handle to those excel files so that I can read the excel's content.

Thanks & Regards,
Ramana
Posted

Use WindowInteropHelper from namespace System.Windows.Interop.
WindowInteropHelper wih = new WindowInteropHelper(myDialog);
IntPtr Handle = wih.Handle;


Hope it will help you!!! :)
 
Share this answer
 
v3
Comments
Ramana Bellary 15-Apr-11 1:53am    
Hi,
from that handle how can I read the content present in the excel file ?
Sergey Alexandrovich Kryukov 15-Apr-11 2:48am    
You cannot. Pure absurdity.
--SA
Tarun.K.S 15-Apr-11 2:52am    
Lol right!
Tarun.K.S 15-Apr-11 2:28am    
Good answer about that handling stuff.
Sergey Alexandrovich Kryukov 15-Apr-11 2:48am    
Agree, a 5.
--SA
About the window handles thing, Bharat Kumar has answered it as I don't have much information about it.

However to read the Excel content, you need to use the Interop.Excel, you may also need to use Add-in.

Add this namespace :

C#
Using xl = Microsoft.Office.Interop.Excel;

private xl.Application xlApp;

//Do this in your Ribbon_Load event :
xlApp = Globals.ThisAddin.Application;

xl.WorkBook workbook = xlApp.ActiveWorkbook;  //Get the active workbook object
xl.WorkSheet worksheet = workbook.ActiveSheet;  //Get the active worksheet object
xl.Range usedRange = worksheet.UsedRange;  //This will return the whole range where you data is used in it

String value;

// Loop through the range to get data of each cell
foreach(xl.Range rng in usedRange.Cells) 
{
 value = rng.Value;
}


Let me know if you have any questions.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900