Excel处理
是否可以为val或其他(取Excel单元格内容)编写表达式?(setq XlsApp (vlax-get-or-create-object "Excel.Application")
myWBooks (vlax-get-property XlsApp 'Workbooks)
myWBook (vla-Add myWBooks)
aSht (vlax-get-property XlsApp 'ActiveSheet)
cel (vlax-get-property aSht 'Cells))
(vla-put-Visible XlsApp 1)
(setq val (vlax-variant-value (vla-get-Value (vlax-variant-value (vlax-get-property cel 'Item r c))) ) )
因为在Excel单元格中编写非常简单:
(vlax-put-property cel 'Item r c value)
以下内容未经测试,但请尝试:
未记录的vlax get函数应返回使用本机AutoLISP数据类型表示的数据,避免从Visual LISP变体和安全数组转换。 测试:
(vlax-get cel 'item 1 1)
; error: too many arguments
或:
(vlax-get cel 'item "A1")
; error: too many arguments
或:
(vlax-get cel "A1")
; error: ActiveX Server returned the error: unknown name: "A1"
vlax get仅用于与AutoCAD R14兼容
(vlax-get cel 'Item r c)
(vlax-dump-object cel t)
; Range: nil
; Property values:
; AddIndent = 0
; Address (RO) = ...Indexed contents not shown...
; AddressLocal (RO) = ...Indexed contents not shown...
; AllowEdit (RO) = -1
; Application (RO) = #<VLA-OBJECT _Application 18fee4dc>
; Areas (RO) = #<VLA-OBJECT Areas 1afea0f4>
; Borders (RO) = #<VLA-OBJECT Borders 1afea184>
; Cells (RO) = #<VLA-OBJECT Range 1afea214>
; Characters (RO) = ...Indexed contents not shown...
; Column (RO) = 1
; Columns (RO) = #<VLA-OBJECT Range 1afea2a4>
; ColumnWidth = 8.43
; Comment (RO) = nil
; Count (RO) = Exception occurred
; CountLarge (RO) = unsupported result type: 20
; Creator (RO) = 1480803660
; CurrentArray (RO) = Microsoft Office Excel: No cells were found.
; CurrentRegion (RO) = #<VLA-OBJECT Range 1afea334>
; Dependents (RO) = Microsoft Office Excel: No cells were found.
; DirectDependents (RO) = Microsoft Office Excel: No cells were found.
; DirectPrecedents (RO) = Microsoft Office Excel: No cells were found.
; End (RO) = ...Indexed contents not shown...
; EntireColumn (RO) = #<VLA-OBJECT Range 1afea3c4>
; EntireRow (RO) = #<VLA-OBJECT Range 1b111314>
; Errors (RO) = Exception occurred
; Font (RO) = #<VLA-OBJECT Font 1b1113a4>
; FormatConditions (RO) = #<VLA-OBJECT FormatConditions 1b111434>
; Formula = Exception occurred
; FormulaArray = "123"
; FormulaHidden = 0
; FormulaLocal = Exception occurred
; FormulaR1C1 = Exception occurred
; FormulaR1C1Local = Exception occurred
; HasArray (RO) = 0
; HasFormula (RO) = 0
; Height (RO) = 1.57286e+007
; Hidden = Microsoft Office Excel: Unable to get the Hidden property of the Range class
; HorizontalAlignment = 1
; Hyperlinks (RO) = #<VLA-OBJECT Hyperlinks 1b1114c4>
; ID = ""
; IndentLevel = 0
; Interior (RO) = #<VLA-OBJECT Interior 1b111554>
; Item = ...Indexed contents not shown...
; Left (RO) = 0.0
; ListHeaderRows (RO) = 0
; ListObject (RO) = nil
; LocationInTable (RO) = Microsoft Office Excel: Unable to get the LocationInTable property of the Range class
; Locked = -1
; MDX (RO) = Exception occurred
; MergeArea (RO) = Exception occurred
; MergeCells = 0
; Name = Exception occurred
; Next (RO) = #<VLA-OBJECT Range 1b1115e4>
; NumberFormat = "General"
; NumberFormatLocal = "General"
; Offset (RO) = ...Indexed contents not shown...
; Orientation = -4128
; OutlineLevel = Microsoft Office Excel: Unable to get the OutlineLevel property of the Range class
; PageBreak = Microsoft Office Excel: Unable to get the PageBreak property of the Range class
; Parent (RO) = #<VLA-OBJECT _Worksheet 1b06702c>
; Phonetic (RO) = #<VLA-OBJECT Phonetic 1b110ecc>
; Phonetics (RO) = nil
; PivotCell (RO) = Exception occurred
; PivotField (RO) = Microsoft Office Excel: Unable to get the PivotField property of the Range class
; PivotItem (RO) = Microsoft Office Excel: Unable to get the PivotItem property of the Range class
; PivotTable (RO) = Microsoft Office Excel: Unable to get the PivotTable property of the Range class
; Precedents (RO) = Microsoft Office Excel: No cells were found.
; PrefixCharacter (RO) = ""
; Previous (RO) = Microsoft Office Excel: Unable to get the Previous property of the Range class
; QueryTable (RO) = Exception occurred
; Range (RO) = ...Indexed contents not shown...
; ReadingOrder = -5002
; Resize (RO) = ...Indexed contents not shown...
; Row (RO) = 1
; RowHeight = 15.0
; Rows (RO) = #<VLA-OBJECT Range 1b110f5c>
; ServerActions (RO) = Exception occurred
; ShowDetail = Microsoft Office Excel: Unable to get the ShowDetail property of the Range class
; ShrinkToFit = 0
; SmartTags (RO) = #<VLA-OBJECT SmartTags 1b110fec>
; SoundNote (RO) = #<VLA-OBJECT SoundNote 1b11107c>
; Style = #<VLA-OBJECT Style 1b11110c>
; Summary (RO) = Microsoft Office Excel: Unable to get the Summary property of the Range class
; Text (RO) = "123"
; Top (RO) = 0.0
; UseStandardHeight = -1
; UseStandardWidth = -1
; Validation (RO) = #<VLA-OBJECT Validation 1b11119c>
; Value = ...Indexed contents not shown...
; Value2 = Exception occurred
; VerticalAlignment = -4107
; Width (RO) = 786432.0
; Worksheet (RO) = #<VLA-OBJECT _Worksheet 1b06702c>
; WrapText = 0
; XPath (RO) = Microsoft Office Excel: The specified range is invalid due to one or more of the following reasons:
•The range refers to cells in more than one column.
•The range contains mapped cells from more than one XML map.
•The range contains both mapped and unmapped cells.
•The range contains both table and non-table cells.
•The range is not contiguous.
; _Default = ...Indexed contents not shown...
; _NewEnum (RO) = #<IUnknown 1b0bfd6c>
; Methods supported:
; Activate ()
; AddComment (1)
; AdvancedFilter (4)
; ApplyNames (7)
; ApplyOutlineStyles ()
; AutoComplete (1)
; AutoFill (2)
; AutoFilter (5)
; AutoFit ()
; AutoOutline ()
; BorderAround (4)
; Calculate ()
; CalculateRowMajorOrder ()
; CheckSpelling (4)
; Clear ()
; ClearComments ()
; ClearContents ()
; ClearFormats ()
; ClearNotes ()
; ClearOutline ()
; ColumnDifferences (1)
; Consolidate (5)
; Copy (1)
; CopyFromRecordset (3)
; CopyPicture (2)
; CreateNames (4)
; Cut (1)
; DataSeries (6)
; Delete (1)
; DialogBox ()
; Dirty ()
; EditionOptions (7)
; ExportAsFixedFormat (9)
; FillDown ()
; FillLeft ()
; FillRight ()
; FillUp ()
; Find (9)
; FindNext (1)
; FindPrevious (1)
; FunctionWizard ()
; Group (4)
; Insert (2)
; InsertIndent (1)
; Justify ()
; ListNames ()
; Merge (1)
; NavigateArrow (3)
; NoteText (3)
; Parse (2)
; PasteSpecial (4)
; PrintOut (
; PrintPreview (1)
; RemoveDuplicates (2)
; RemoveSubtotal ()
; Replace (
; RowDifferences (1)
; Run (30)
; Select ()
; SetPhonetic ()
; Show ()
; ShowDependents (1)
; ShowErrors ()
; ShowPrecedents (1)
; Sort (15)
; SortSpecial (15)
; Speak (2)
; SpecialCells (2)
; SubscribeTo (2)
; Subtotal (6)
; Table (2)
; TextToColumns (14)
; Ungroup ()
; UnMerge ()
T
_$
看看GETEXCEL。lsp位切除
(setq ExcelRange (vlax-get-property *ExcelApp% "Cells"))
(foreach Item Data@
(vlax-put-property ExcelRange "Item" Row# Column# (vl-princ-to-string Item)) 在GETEXCEL中。lsp它仅使用类似的方法,而不是项、值:
(repeat MaxColumn#
(setq Range$ (strcat (Number2Alpha Column#)(itoa Row#)))
(setq ExcelRange^ (vlax-get-property *ExcelApp% "Range" Range$))
(setq ExcelVariant^ (vlax-get-property ExcelRange^ 'Value))
(setq ExcelValue (vlax-variant-value ExcelVariant^))
(setq ExcelValue
(cond
((= (type ExcelValue) 'INT) (itoa ExcelValue))
((= (type ExcelValue) 'REAL) (rtosr ExcelValue))
((= (type ExcelValue) 'STR) (vl-string-trim " " ExcelValue))
((/= (type ExcelValue) 'STR) "")
);cond
);setq
(setq Data@ (append Data@ (list ExcelValue)))
(setq Column# (1+ Column#))
)
由于上面返回的参数“太多”,请尝试:
(vlax-get cel 'item)
(vlax-get cel 'item)
; error: Invalid number of parameters
(vlax-get-property cel 'Item 1 1)
#<variant 9 1234.567>
我在主题#1中填写了您需要的所有内容,所以您可以尝试一下。 我做过这样的东西
;for example
(setq row 1 column 1)
(setq cell (vlax-variant-value(vlax-get-property cells 'Item (vlax-make-variant row)(vlax-make-variant column))))
(setq celltext (vlax-variant-value (vlax-get-property cell 'Value)))
它对我有效(: 谢谢你的回复,但是Fabricorby,谁是cells variable?
这是一个缺点,因为您必须为读取的每个单元格确定单元格变量。在我的版本中,cel变量可用于整个工作表。
页:
[1]
2