Results 1 to 2 of 2

Thread: Use of Autocad Electrical API to create an excel table

  1. #1
    Member
    Join Date
    2018-06
    Posts
    5
    Login to Give a bone
    0

    Default Use of Autocad Electrical API to create an excel table

    Hello all,
    This is my first post in AUGI.
    The Autocad Electrical API gets quite fuzzy when I get to Section K - XLS and MDB tools
    I can make a blank XLS file.
    Also I have figured out how to Add records to an existing XLS file with a table called COMP (or any table for that matter) with the appropriate information in the first row.
    The problem is the step between creating the XLS file and adding records. I cannot find a way to create a table called COMP (non critical, I can just use Sheet1). Also I cannot find a way to add information to the first row of a table via autolisp (critical information).

    Code:
    ; This section of code can create the xls file with Sheet1, Sheet2, Sheet3 as empty tables
    
    (if (not fnam)
    		(setq fnam	(getfiled "Export xls" (strcat "C:/Users/" (getvar "loginname") "/Desktop/links/ExportSpreadsheet") "xls" 1))	; xls filename 
    )
    (setq hdl (wd_mdb_GetHandle 2))
    (wd_dbase_CreateDatabase hdl fnam 2)
    (wd_mdb_close hdl)
    
    ; Missing section of code below
    
    
    
    
    ; this section of code can add records to an XLS file Provided that it has COMP for a sheet, and the Appropriate information in the first row.
    
    (if (not fnam)
    		(setq fnam	(getfiled "Export xls" (strcat "C:/Users/" (getvar "loginname") "/Desktop/links/ExportSpreadsheet") "xls" 1))	; xls filename 
    )
    (setq hdl (wd_mdb_GetHandle 2)) ; 2 - for xls files
    (wd_mdb_Open hdl fnam "Excel 5.0;HDR=YES")
    (setq testData (list	(list 	        (list "TAGNAME" 		"Test3")   ; TAGNAME is in Cell A1 
    						(list "DESC1" 			"Test3")   ; DESC is in Cell B1
    						(list "DESC2" 			"Test3")
    						(list "DESC3" 			"Test3")
    						(list "MFG"			 	"Test3")
    						(list "CAT" 			"Test3")							
    						(list "INST" 			"Test3")
    						(list "LOC" 			"Test3")
    						(list "RATING1" 		        "Test3")
    						(list "RATING2"  		"Test3")	
    						(list "RATING3" 	        	"Test3")
    						(list "PAR1_CHLD2"		"Test3")
    						(list "HDL"				"Test3")
    						(list "DWGIX"			"Test3")
    						(list "RECNUM"			"1"	)
    				)
    			)
    )
    (wd_mdb_AddRecs hdl "COMP$" testData)

  2. #2
    Member
    Join Date
    2018-06
    Posts
    5
    Login to Give a bone
    0

    Default Re: Use of Autocad Electrical API to create an excel table

    Hello, welcome to AUGI.
    I apologize for the late response.

    You need to create the sheet, then the table, then add records. The following is sample code that works.

    Code:
    (setq fnam "C:\\Users\\Anonymous\\Documents\\wddemo_10.XLS" ) ; <- modify fnam as needed
    (setq support "c:\\program files\\autodesk\\autocad 2018\\acade\\support\\en-us\\")
    (if (setq hdl (wd_mdb_GetHandle 4)) ; <- autocad documentation doesn't cover this secret option
      (progn
    	(if (wd_mdb_Create hdl fnam 1 support)
    	  (progn
    		(wd_mdb_CreateTable 
    			hdl ; 1
    			"Sheet1$" 
    			'(("WIRENO" "S" 24) ("(HDL)" "S" 18) ("W01USER" "S" 255) ("W02USER" "S" 255) ("W03USER" "S" 255) ("W04USER" "S" 255) ("W05USER" "S" 255) ("W06USER" "S" 255) ("W07USER" "S" 255) ("W08USER" "S" 255) ("W09USER" "S" 255) ("W10USER" "S" 255) ("(FILENAME)" "S" 255))
    			1 
    			support
    		)
    	  )
    	)
    	(wd_mdb_Close hdl)
      )
    )
    (if (setq hdl (wd_mdb_GetHandle 2))
      (progn
    	(if
    	  (wd_mdb_Open 
    		hdl 
    		fnam
    		"Excel 5.0;HDR=YES"
    	  )
    	  (progn
    		(wd_mdb_AddRecs 
    			hdl 
    			"Sheet1$" 
    			'((("(FILENAME)" "DEMO07.DWG") ("(HDL)" "h=EB5") ("WIRENO" "324")))
    		)
    	  )
    	)
    	(wd_mdb_Close hdl)
      )
    )
    (wd_mdb_closeall)

Similar Threads

  1. Replies: 11
    Last Post: 2022-11-30, 03:18 PM
  2. Excel Table to AutoCAD Table.
    By Spenner in forum AutoCAD Tables
    Replies: 23
    Last Post: 2017-08-14, 07:17 AM
  3. Trouble with Excel Information to AutoCAD Table
    By CADdancer in forum AutoCAD Tables
    Replies: 2
    Last Post: 2010-09-08, 08:21 PM
  4. How to import excel table to autocad
    By mandy in forum AutoCAD General
    Replies: 5
    Last Post: 2008-10-31, 06:32 PM
  5. Need Help, Trying to use excel formulas in AutoCAD Table
    By ReachAndre in forum AutoCAD General
    Replies: 2
    Last Post: 2008-08-04, 02:45 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •