Excel到Cad
嗨,朋友们如何将每个excel列放入线性阵列?
如何将每个excel原始数据放入线性阵列?
例如10行4列 VBA还是LISP?
有关LISP,请参见此处:
http://web2.airmail.net/terrycad/LISP/GetExcel.lsp
http://www.theswamp.org/index.php?topic=10101.0
李
谢谢李先生
我读了这些文件,它们非常详细,可以解决我的问题。
李先生,我可以读lisp文件,但我不是lisp程序员,
我从两周前开始使用lisp编程,但现在我可以将这些lisp文件与vba代码结合起来,或将其转换。
非常感谢,祝你玩得愉快。
隐马尔可夫模型。。。我认为它们需要重新写入VBA。。。未转换-没有简单(或快速)的任务。
另一种方式
(defun readrow (xlsheet rownum / c1 cel cels celvalue cols r1 rowdata xlrange xlrow)
(vlax-invoke-method xlsheet "Activate") ;optional
(setq xlrange (vlax-get-property xlsheet "UsedRange"))
(setq xlrow (vlax-variant-value
(vlax-get-property
(vlax-get-property
xlrange
"Rows")
"Item"
rownum)))
(setq cols (vlax-get-property
(vlax-get-property xlrange "Columns")
"Count")
)
(vlax-invoke-method xlrange "Activate") ;optional
(vlax-invoke-method xlrange "Select") ;optional
(setq cels (vlax-get-property xlsheet "Cells"))
(setq r1 rownum ; given row number
c1 1 ; initial column number in row
)
(while (<= c1 cols)
(setq cel (vlax-variant-value
(vlax-get-property
cels
"Item"
;; row number :
(vlax-make-variant r1 vlax-vblong)
;; column number :
(vlax-make-variant c1 vlax-vblong))))
(setq celvalue (vlax-variant-value (vlax-get-property cel "Value2")))
(setq rowdata (cons (vl-princ-to-string celvalue) rowdata))
(setq c1 (1+ c1 )))
(reverse rowdata)
)
(defun readcolumn (xlsheet colnum / c1 cel cels celvalue columndata r1 rows xlrange xlrow)
(vlax-invoke-method xlsheet "Activate") ;optional
(setq xlrange (vlax-get-property xlsheet "UsedRange"))
(setq xlrow (vlax-variant-value
(vlax-get-property
(vlax-get-property
xlrange
"Rows")
"Item"
colnum)))
(setq rows (vlax-get-property
(vlax-get-property xlrange "Rows")
"Count")
)
(vlax-invoke-method xlrange "Activate") ;optional
(vlax-invoke-method xlrange "Select") ;optional
(setq cels (vlax-get-property xlsheet "Cells"))
(setq r11 ; initial row number in column
c1colnum ; given column number
)
(while (<= r1 rows)
(setq cel (vlax-variant-value
(vlax-get-property
cels
"Item"
;; row number :
(vlax-make-variant r1 vlax-vblong)
;; column number :
(vlax-make-variant c1 vlax-vblong))))
(setq celvalue (vlax-variant-value (vlax-get-property cel "Value2")))
(setq columndata (cons (vl-princ-to-string celvalue) columndata))
(setq r1 (1+ r1 )))
(reverse columndata)
)
;; Usage :
(defun C:GRD(/
*error*
C1
Cel
Cels
Celvalue
Colnum
Datalist
Excelapp
Filepath
Findrang
Findrow
Lastcell
R1
Rownum
Sht
Shtnum
Wbk)
(defun *error*(msg)
;; close workbook w/o saving changes
(vl-catch-all-apply
'vlax-invoke-method
(list Wbk "Close")
)
;; quit Excel
(vl-catch-all-apply
'vlax-invoke-method
(list ExcelApp "Quit")
)
;; clean up of memory
(mapcar
(function
(lambda (x)
(vl-catch-all-apply
(function (lambda ()
(if (not (vlax-object-released-p x))
(vlax-release-object x)
)
)
))))
(list Cel LastCell Cels FindRow FindRang Sht Wbk ExcelApp)
)
(setq Cel nil
LastCell nil
Cels nil
FindRow nil
FindRang nil
Sht nil
Wbk nil
ExcelApp nil
)
(gc)
(gc)
(princ)
)
(setq FilePath (getfiled "Select Excel file to read data:"
(getvar "dwgprefix")
"xls"
16
)
)
(initget 6)
(setq ShtNum (getint "\nEnter a sheet number <1>: "))
(if (not ShtNum)
(setq ShtNum 1))
(initget 6)
(setq RowNum (getint "\nEnter a row number <1>: "))
(if (not RowNum)
(setq RowNum 1))
(initget 6)
(setq ColNum (getint "\nEnter a column number <1>: "))
(if (not ColNum)
(setq ColNum 1))
(setq ExcelApp (vlax-get-or-create-object "Excel.Application"))
(vla-put-visible ExcelApp :vlax-true) ;or :vlax-false for invisible mode
(setq Wbk (vl-catch-all-apply
'vla-open
(list (vlax-get-property ExcelApp "WorkBooks") FilePath)))
(setq Sht (vl-catch-all-apply
'vlax-get-property
(list (vlax-get-property Wbk "Sheets")
"Item"
ShtNum)))
(vlax-invoke-method Sht "Activate")
(setq rowlist (readrow Sht RowNum))
(setq columnlist (readcolumn Sht ColNum))
(princ "\nRow data: ")
(print rowlist)
(princ "\nColumn data: ")
(print columnlist)
;; --> work here with this data after
(*error* "")
(princ)
)
(vl-load-com)
~'J'~
下面是VBA示例
~'J'~
ReadExcel。拉链 谢谢亲爱的fixo
我改变了你的代码,现在我可以阅读一个excel文件,有7列和1420行,当它工作正常,完成我的项目,把它放在你的代码之后。还有一次,我非常感谢你和李先生的代码。 不客气,卡德曼
不客气
干杯
~'J'~
页:
[1]