AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Can u get range of cells from a xls without opening it

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
vahju



Joined: 17 Feb 2008
Posts: 296

PostPosted: Fri Jan 15, 2010 3:16 am    Post subject: Can u get range of cells from a xls without opening it Reply with quote

Total newb at COM and MS Office Automation Functions.

Searching through the forums I got the feeling that the excel file has to be open (visible or hidden) in order to get the data.

I need to pull a range of cells in the same column into a variable. This contains a list of last names. Once I have the list of names in a variable then I am good to go manipulating it.

This data is going to be pulled daily by 25 people so trying to avoid having all of them open the xls file each time the list of names are searched.
Back to top
View user's profile Send private message
Leef_me



Joined: 08 Apr 2009
Posts: 5336
Location: San Diego, California

PostPosted: Fri Jan 15, 2010 7:29 am    Post subject: Reply with quote

I foun this, perhaps it will be helpful.
http://www.autohotkey.com/forum/topic29429.html

Some say you can get datafrom a file without opening it through DDE, but I have the (untested) idea that "without opening it" is a semantic term.

If you want the data available in a simpler form for the people, why not save it as CSV (comma separated values) format?

AHK can read this format easily.
Back to top
View user's profile Send private message
kdoske



Joined: 17 Dec 2008
Posts: 80

PostPosted: Fri Jan 15, 2010 7:46 am    Post subject: Reply with quote

I had a similar problem and I just saved the excel file to a .xml within excel.

Then i just used the xml function found on this website to pull out the data i needed from the file.

If its a company file you may not be able to change the file type for various reasons but if you can it really makes it easy. You could also alternately convert it to a .csv file.
Back to top
View user's profile Send private message
hd0202



Joined: 13 Aug 2006
Posts: 265
Location: Germany

PostPosted: Fri Jan 15, 2010 10:42 am    Post subject: Reply with quote

I save the excel file as a csv-file and extract then the data from the csv-file:
Code:
xls_file = <input filename>
csv_file = <output filename>
sheet_nr = 1

COM_Init()
app := COM_CreateObject("Excel.Application")
wb := com_invoke(com_invoke(app,"Workbooks"),"open",xls_file)
ws := COM_Invoke(COM_Invoke(wb, "Worksheets"), "Item", sheet_nr)
com_invoke(ws, "Saveas", csv_file, 6) ;6 = saves as a csv
COM_Invoke(app, "Quit")
COM_Term()

Hubert
Back to top
View user's profile Send private message
vahju



Joined: 17 Feb 2008
Posts: 296

PostPosted: Fri Jan 15, 2010 12:24 pm    Post subject: Reply with quote

Thanks everyone for you quick responses. Seems the general consensus is convert to CSV. hd0202 thanks for the code. I will play around this weekend and post my result.

Original file was not created by me otherwise I would have just started with CSV.

Thanks again.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group