乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 51|回复: 19

[编程交流] Excel处理

[复制链接]

56

主题

284

帖子

231

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
289
发表于 2022-7-6 06:22:16 | 显示全部楼层 |阅读模式
是否可以为val或其他(取Excel单元格内容)编写表达式?
 
  1. (setq XlsApp (vlax-get-or-create-object "Excel.Application")
  2.        myWBooks (vlax-get-property XlsApp 'Workbooks)
  3.        myWBook (vla-Add myWBooks)
  4.        aSht (vlax-get-property XlsApp 'ActiveSheet)
  5.        cel (vlax-get-property aSht 'Cells)  )
  6. (vla-put-Visible XlsApp 1)
  7. [color=red](setq val (vlax-variant-value (vla-get-Value (vlax-variant-value [/color][color=red](vlax-get-property cel 'Item r c))) ) )[/color]

 
因为在Excel单元格中编写非常简单:
  1. (vlax-put-property cel 'Item r c value)
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 06:28:23 | 显示全部楼层
以下内容未经测试,但请尝试:
未记录的vlax get函数应返回使用本机AutoLISP数据类型表示的数据,避免从Visual LISP变体和安全数组转换。
回复

使用道具 举报

56

主题

284

帖子

231

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
289
发表于 2022-7-6 06:29:09 | 显示全部楼层
测试:
 
  1. (vlax-get cel 'item 1 1)
  2. ; error: too many arguments

 
或:
  1. (vlax-get cel 'item "A1")
  2. ; error: too many arguments

或:
  1. (vlax-get cel "A1")
  2. ; error: ActiveX Server returned the error: unknown name: "A1"

 
vlax get仅用于与AutoCAD R14兼容
  1. (vlax-get cel 'Item r c)
回复

使用道具 举报

56

主题

284

帖子

231

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
289
发表于 2022-7-6 06:34:08 | 显示全部楼层
  1. (vlax-dump-object cel t)
  2. ; Range: nil
  3. ; Property values:
  4. ;   AddIndent = 0
  5. ;   Address (RO) = ...Indexed contents not shown...
  6. ;   AddressLocal (RO) = ...Indexed contents not shown...
  7. ;   AllowEdit (RO) = -1
  8. ;   Application (RO) = #<VLA-OBJECT _Application 18fee4dc>
  9. ;   Areas (RO) = #<VLA-OBJECT Areas 1afea0f4>
  10. ;   Borders (RO) = #<VLA-OBJECT Borders 1afea184>
  11. ;   Cells (RO) = #<VLA-OBJECT Range 1afea214>
  12. ;   Characters (RO) = ...Indexed contents not shown...
  13. ;   Column (RO) = 1
  14. ;   Columns (RO) = #<VLA-OBJECT Range 1afea2a4>
  15. ;   ColumnWidth = 8.43
  16. ;   Comment (RO) = nil
  17. ;   Count (RO) = Exception occurred
  18. ;   CountLarge (RO) = unsupported result type: 20
  19. ;   Creator (RO) = 1480803660
  20. ;   CurrentArray (RO) = Microsoft Office Excel: No cells were found.
  21. ;   CurrentRegion (RO) = #<VLA-OBJECT Range 1afea334>
  22. ;   Dependents (RO) = Microsoft Office Excel: No cells were found.
  23. ;   DirectDependents (RO) = Microsoft Office Excel: No cells were found.
  24. ;   DirectPrecedents (RO) = Microsoft Office Excel: No cells were found.
  25. ;   End (RO) = ...Indexed contents not shown...
  26. ;   EntireColumn (RO) = #<VLA-OBJECT Range 1afea3c4>
  27. ;   EntireRow (RO) = #<VLA-OBJECT Range 1b111314>
  28. ;   Errors (RO) = Exception occurred
  29. ;   Font (RO) = #<VLA-OBJECT Font 1b1113a4>
  30. ;   FormatConditions (RO) = #<VLA-OBJECT FormatConditions 1b111434>
  31. ;   Formula = Exception occurred
  32. ;   FormulaArray = "123"
  33. ;   FormulaHidden = 0
  34. ;   FormulaLocal = Exception occurred
  35. ;   FormulaR1C1 = Exception occurred
  36. ;   FormulaR1C1Local = Exception occurred
  37. ;   HasArray (RO) = 0
  38. ;   HasFormula (RO) = 0
  39. ;   Height (RO) = 1.57286e+007
  40. ;   Hidden = Microsoft Office Excel: Unable to get the Hidden property of the Range class
  41. ;   HorizontalAlignment = 1
  42. ;   Hyperlinks (RO) = #<VLA-OBJECT Hyperlinks 1b1114c4>
  43. ;   ID = ""
  44. ;   IndentLevel = 0
  45. ;   Interior (RO) = #<VLA-OBJECT Interior 1b111554>
  46. ;   Item = ...Indexed contents not shown...
  47. ;   Left (RO) = 0.0
  48. ;   ListHeaderRows (RO) = 0
  49. ;   ListObject (RO) = nil
  50. ;   LocationInTable (RO) = Microsoft Office Excel: Unable to get the LocationInTable property of the Range class
  51. ;   Locked = -1
  52. ;   MDX (RO) = Exception occurred
  53. ;   MergeArea (RO) = Exception occurred
  54. ;   MergeCells = 0
  55. ;   Name = Exception occurred
  56. ;   Next (RO) = #<VLA-OBJECT Range 1b1115e4>
  57. ;   NumberFormat = "General"
  58. ;   NumberFormatLocal = "General"
  59. ;   Offset (RO) = ...Indexed contents not shown...
  60. ;   Orientation = -4128
  61. ;   OutlineLevel = Microsoft Office Excel: Unable to get the OutlineLevel property of the Range class
  62. ;   PageBreak = Microsoft Office Excel: Unable to get the PageBreak property of the Range class
  63. ;   Parent (RO) = #<VLA-OBJECT _Worksheet 1b06702c>
  64. ;   Phonetic (RO) = #<VLA-OBJECT Phonetic 1b110ecc>
  65. ;   Phonetics (RO) = nil
  66. ;   PivotCell (RO) = Exception occurred
  67. ;   PivotField (RO) = Microsoft Office Excel: Unable to get the PivotField property of the Range class
  68. ;   PivotItem (RO) = Microsoft Office Excel: Unable to get the PivotItem property of the Range class
  69. ;   PivotTable (RO) = Microsoft Office Excel: Unable to get the PivotTable property of the Range class
  70. ;   Precedents (RO) = Microsoft Office Excel: No cells were found.
  71. ;   PrefixCharacter (RO) = ""
  72. ;   Previous (RO) = Microsoft Office Excel: Unable to get the Previous property of the Range class
  73. ;   QueryTable (RO) = Exception occurred
  74. ;   Range (RO) = ...Indexed contents not shown...
  75. ;   ReadingOrder = -5002
  76. ;   Resize (RO) = ...Indexed contents not shown...
  77. ;   Row (RO) = 1
  78. ;   RowHeight = 15.0
  79. ;   Rows (RO) = #<VLA-OBJECT Range 1b110f5c>
  80. ;   ServerActions (RO) = Exception occurred
  81. ;   ShowDetail = Microsoft Office Excel: Unable to get the ShowDetail property of the Range class
  82. ;   ShrinkToFit = 0
  83. ;   SmartTags (RO) = #<VLA-OBJECT SmartTags 1b110fec>
  84. ;   SoundNote (RO) = #<VLA-OBJECT SoundNote 1b11107c>
  85. ;   Style = #<VLA-OBJECT Style 1b11110c>
  86. ;   Summary (RO) = Microsoft Office Excel: Unable to get the Summary property of the Range class
  87. ;   Text (RO) = "123"
  88. ;   Top (RO) = 0.0
  89. ;   UseStandardHeight = -1
  90. ;   UseStandardWidth = -1
  91. ;   Validation (RO) = #<VLA-OBJECT Validation 1b11119c>
  92. ;   Value = ...Indexed contents not shown...
  93. ;   Value2 = Exception occurred
  94. ;   VerticalAlignment = -4107
  95. ;   Width (RO) = 786432.0
  96. ;   Worksheet (RO) = #<VLA-OBJECT _Worksheet 1b06702c>
  97. ;   WrapText = 0
  98. ;   XPath (RO) = Microsoft Office Excel: The specified range is invalid due to one or more of the following reasons:
  99. •The range refers to cells in more than one column.
  100. •The range contains mapped cells from more than one XML map.
  101. •The range contains both mapped and unmapped cells.
  102. •The range contains both table and non-table cells.
  103. •The range is not contiguous.
  104. ;   _Default = ...Indexed contents not shown...
  105. ;   _NewEnum (RO) = #<IUnknown 1b0bfd6c>
  106. ; Methods supported:
  107. ;   Activate ()
  108. ;   AddComment (1)
  109. ;   AdvancedFilter (4)
  110. ;   ApplyNames (7)
  111. ;   ApplyOutlineStyles ()
  112. ;   AutoComplete (1)
  113. ;   AutoFill (2)
  114. ;   AutoFilter (5)
  115. ;   AutoFit ()
  116. ;   AutoOutline ()
  117. ;   BorderAround (4)
  118. ;   Calculate ()
  119. ;   CalculateRowMajorOrder ()
  120. ;   CheckSpelling (4)
  121. ;   Clear ()
  122. ;   ClearComments ()
  123. ;   ClearContents ()
  124. ;   ClearFormats ()
  125. ;   ClearNotes ()
  126. ;   ClearOutline ()
  127. ;   ColumnDifferences (1)
  128. ;   Consolidate (5)
  129. ;   Copy (1)
  130. ;   CopyFromRecordset (3)
  131. ;   CopyPicture (2)
  132. ;   CreateNames (4)
  133. ;   Cut (1)
  134. ;   DataSeries (6)
  135. ;   Delete (1)
  136. ;   DialogBox ()
  137. ;   Dirty ()
  138. ;   EditionOptions (7)
  139. ;   ExportAsFixedFormat (9)
  140. ;   FillDown ()
  141. ;   FillLeft ()
  142. ;   FillRight ()
  143. ;   FillUp ()
  144. ;   Find (9)
  145. ;   FindNext (1)
  146. ;   FindPrevious (1)
  147. ;   FunctionWizard ()
  148. ;   Group (4)
  149. ;   Insert (2)
  150. ;   InsertIndent (1)
  151. ;   Justify ()
  152. ;   ListNames ()
  153. ;   Merge (1)
  154. ;   NavigateArrow (3)
  155. ;   NoteText (3)
  156. ;   Parse (2)
  157. ;   PasteSpecial (4)
  158. ;   PrintOut (
  159. ;   PrintPreview (1)
  160. ;   RemoveDuplicates (2)
  161. ;   RemoveSubtotal ()
  162. ;   Replace (
  163. ;   RowDifferences (1)
  164. ;   Run (30)
  165. ;   Select ()
  166. ;   SetPhonetic ()
  167. ;   Show ()
  168. ;   ShowDependents (1)
  169. ;   ShowErrors ()
  170. ;   ShowPrecedents (1)
  171. ;   Sort (15)
  172. ;   SortSpecial (15)
  173. ;   Speak (2)
  174. ;   SpecialCells (2)
  175. ;   SubscribeTo (2)
  176. ;   Subtotal (6)
  177. ;   Table (2)
  178. ;   TextToColumns (14)
  179. ;   Ungroup ()
  180. ;   UnMerge ()
  181. T
  182. _$
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 06:36:53 | 显示全部楼层
看看GETEXCEL。lsp位切除
 
  1. (setq ExcelRange (vlax-get-property *ExcelApp% "Cells"))
  2. (foreach Item Data@
  3.    (vlax-put-property ExcelRange "Item" Row# Column# (vl-princ-to-string Item))
回复

使用道具 举报

56

主题

284

帖子

231

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
289
发表于 2022-7-6 06:38:25 | 显示全部楼层
在GETEXCEL中。lsp它仅使用类似的方法,而不是项、值:
 
  1. (repeat MaxColumn#
  2.      (setq Range$ (strcat (Number2Alpha Column#)(itoa Row#)))
  3.      (setq ExcelRange^ (vlax-get-property *ExcelApp% "Range" Range$))
  4.      (setq ExcelVariant^ (vlax-get-property ExcelRange^ [color=red]'Value[/color]))
  5.      (setq ExcelValue (vlax-variant-value ExcelVariant^))
  6.      (setq ExcelValue
  7.        (cond
  8.          ((= (type ExcelValue) 'INT) (itoa ExcelValue))
  9.          ((= (type ExcelValue) 'REAL) (rtosr ExcelValue))
  10.          ((= (type ExcelValue) 'STR) (vl-string-trim " " ExcelValue))
  11.          ((/= (type ExcelValue) 'STR) "")
  12.        );cond
  13.      );setq
  14.      (setq Data@ (append Data@ (list ExcelValue)))
  15.      (setq Column# (1+ Column#))
  16.    )
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 06:43:12 | 显示全部楼层
 
由于上面返回的参数“太多”,请尝试:
  1. (vlax-get cel 'item)
回复

使用道具 举报

56

主题

284

帖子

231

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
289
发表于 2022-7-6 06:47:16 | 显示全部楼层
  1. (vlax-get cel 'item)
  2. ; error: Invalid number of parameters

 
  1. (vlax-get-property cel 'Item 1 1)
  2. #<variant 9 [color=red]1234.567[/color]>

 
我在主题#1中填写了您需要的所有内容,所以您可以尝试一下。
回复

使用道具 举报

9

主题

71

帖子

62

银币

初来乍到

Rank: 1

铜币
45
发表于 2022-7-6 06:49:42 | 显示全部楼层
我做过这样的东西
  1. ;for example
  2. (setq row 1 column 1)
  3. (setq cell (vlax-variant-value(vlax-get-property cells 'Item (vlax-make-variant row)(vlax-make-variant column))))
  4. (setq celltext (vlax-variant-value (vlax-get-property cell 'Value)))

它对我有效(:
回复

使用道具 举报

56

主题

284

帖子

231

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
289
发表于 2022-7-6 06:50:55 | 显示全部楼层
谢谢你的回复,但是Fabricorby,谁是cells variable?
 
这是一个缺点,因为您必须为读取的每个单元格确定单元格变量。在我的版本中,cel变量可用于整个工作表。
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-10 17:55 , Processed in 0.587723 second(s), 83 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表