Author Topic: Open excel file  (Read 10318 times)

0 Members and 1 Guest are viewing this topic.

Atwist

  • Guest
Open excel file
« on: June 09, 2011, 05:03:36 AM »
Hello,

How to open a excel file in AutoCad

SOFITO_SOFT

  • Guest
Re: Open excel file
« Reply #1 on: June 09, 2011, 05:27:17 AM »
hello:
I use a DLL that is not divine, but it works very well with A2008, excel 2003 on XP 32.

Code for open the sheet "Ayuda_Sofito_Soft" of file "Sofito_Soft.xls" in folder "H:\\aa_sofito\\"

Code: [Select]
( setq arma_3d_path "H:\\aa_sofito\\")
( if ( not Excel_Release )
    ( command "netload"  (  strcat arma_3d_path  "ExcelLisp.dll" ) )
  )
( setq excel-libro (  strcat arma_3d_path  "Sofito_Soft.xls" ) )
( Excel_Conecta T  excel-libro  "Ayuda_Sofito_Soft")

Now you can read, write, make new sheets , change cell formats, save book, etc ...
Attacheds, the DLL and little help of use.

I hope you can use.

Greetings from Madrid :-) :-)

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Open excel file
« Reply #2 on: June 09, 2011, 07:05:33 AM »
Hi,

Look at this 'not so old' thread.
Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Open excel file
« Reply #3 on: June 09, 2011, 07:52:04 AM »
This will 'open' any file, but if you actually meant to interface with the Excel file, refer to the link suggested by gile.

HofCAD

  • Guest
Re: Open excel file
« Reply #4 on: June 09, 2011, 09:19:53 AM »
Hello,
How to open a excel file in AutoCad
See in http://www.theswamp.org/index.php?topic=38526.0 DDE-OpenAll.xls

Regards HofCAD CSI.

Atwist

  • Guest
Re: Open excel file
« Reply #5 on: June 10, 2011, 05:38:38 AM »
Hello all

Thanks for your answer

@ Lee

I have use your lisp "open" and have dish chance but it don't works
Watt is wrong.

Code: [Select]
(defun LM:excel ( target / Shell result ) (vl-load-com)
(LM:excel "T:\\excel bestanden\\layerlijst.xls")

 
  (setq Shell (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application"))

  (setq result
    (and (or (eq 'INT (type target)) (setq target (findfile target)))
      (not
        (vl-catch-all-error-p
          (vl-catch-all-apply 'vlax-invoke (list Shell 'Open target))
        )
      )
    )
  )
  (vlax-release-object Shell)
  result
)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Open excel file
« Reply #6 on: June 10, 2011, 05:50:37 AM »
You are not calling the function correctly since you call the function within its own definition.

This is better:

Code: [Select]
;;------------------------=={ Open }==------------------------;;
;;                                                            ;;
;;  Uses the 'Open' method of the Shell Object to open the    ;;
;;  specified file or folder.                                 ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  target - filename, directory or                           ;;
;;           ShellSpecialFolderConstants Enumeration to open  ;;
;;------------------------------------------------------------;;
;;  Returns:  T if opened successfully, else nil              ;;
;;------------------------------------------------------------;;

(defun LM:Open ( target / Shell result ) (vl-load-com)
 
  (setq Shell (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application"))
  (setq result
    (and (or (eq 'INT (type target)) (setq target (findfile target)))
      (not
        (vl-catch-all-error-p
          (vl-catch-all-apply 'vlax-invoke (list Shell 'Open target))
        )
      )
    )
  )
  (vlax-release-object Shell)
  result
)

(LM:Open "T:\\excel bestanden\\layerlijst.xls")


Atwist

  • Guest
Re: Open excel file
« Reply #7 on: June 10, 2011, 05:56:40 AM »
Thanks Lee

It works

SOFITO_SOFT

  • Guest
Re: Open excel file
« Reply #8 on: June 10, 2011, 08:01:01 AM »
Hello people swampy:
A question a little more difficult with Excel.
2 programs LSP want to use a spreadsheet. Each opens, write and close the spreadsheet.
Do any method for each program know if the sheet is already open and available to write?
Thus saving the time to open and close. The 2 programs could know if the other has opened the spreadsheet ?.
Thanks in advance.
Greetings :)

PS.:  I know I could use a flag switch (is open / is closed)
but look for something more sophisticated ...
« Last Edit: June 10, 2011, 08:30:02 AM by SOFITO_SOFT »

VVA

  • Newt
  • Posts: 166
Re: Open excel file
« Reply #9 on: June 10, 2011, 10:49:12 AM »

johnson

  • Guest
Re: Open excel file
« Reply #10 on: June 13, 2011, 11:31:38 AM »
You are not calling the function correctly since you call the function within its own definition.

This is better:

Code: [Select]
;;------------------------=={ Open }==------------------------;;
;;                                                            ;;
;;  Uses the 'Open' method of the Shell Object to open the    ;;
;;  specified file or folder.                                 ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  target - filename, directory or                           ;;
;;           ShellSpecialFolderConstants Enumeration to open  ;;
;;------------------------------------------------------------;;
;;  Returns:  T if opened successfully, else nil              ;;
;;------------------------------------------------------------;;

(defun LM:Open ( target / Shell result ) (vl-load-com)
 
  (setq Shell (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application"))
  (setq result
    (and (or (eq 'INT (type target)) (setq target (findfile target)))
      (not
        (vl-catch-all-error-p
          (vl-catch-all-apply 'vlax-invoke (list Shell 'Open target))
        )
      )
    )
  )
  (vlax-release-object Shell)
  result
)

(LM:Open "T:\\excel bestanden\\layerlijst.xls")




Lee after loading xls is opened.without comman.after command i want open that xls

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Open excel file
« Reply #11 on: June 13, 2011, 12:26:42 PM »
Lee after loading xls is opened.without comman.after command i want open that xls

Yes, because the function is called outside of any function definition and so is evaluated on loading:

Code: [Select]
(LM:Open "T:\\excel bestanden\\layerlijst.xls")
You can call it from inside a function definition instead:

Code: [Select]
(defun c:test ( / )
  (LM:Open "T:\\excel bestanden\\layerlijst.xls")
  (princ)
)

johnson

  • Guest
Re: Open excel file
« Reply #12 on: June 13, 2011, 08:55:12 PM »
Error is coming

Command: ; error: no function definition: LM:OPEN

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Open excel file
« Reply #13 on: June 13, 2011, 08:55:48 PM »
Error is coming

Command: ; error: no function definition: LM:OPEN

You will need to have the LM:Open function definition loaded in order to call it.

cadman6735

  • Guest
Re: Open excel file
« Reply #14 on: October 13, 2011, 10:10:49 AM »
Hi Lee

I just found this post and love this macro.  I am studying your code but have some questions if you don't mind.

Code: [Select]
(setq Shell (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application"))Is "Shell.Application" sort of a catch all?

I am finding I can open all the files I have tried so far but if I follow the example for (vla-getIntrfaceObject) and put in for example instead of "Shell.Application" I use "Excel.Application" I get "error problem in loading application"  I am guessing this is because your code is using "target" as a check to see what the file type is to be fed to the shell for loading?

I have a couple of more questions to follow but will pause here

Thanks lee