明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1162|回复: 0

[提问] 求大神帮忙解决数据导入excel合并问题

[复制链接]
发表于 2014-5-15 14:56:33 | 显示全部楼层 |阅读模式
本人菜鸟,想实现a*b-c格式a,b,c分开导入到excel中,其中excel导入是搬运langjs大神的http://bbs.mjtd.com/thread-92023-1-1.html中的代码。字符串分割是搬运自贡黄明儒大神的http://bbs.mjtd.com/forum.php?mod=viewthread&tid=108027中的代码,都不是太明白,但能实现了基本的excel导入(不能识别并排除不正确的格式),请问大神们,能不能实现再加一列数量,将相同的行合并,然后显示数量。
  1. (defun c:tt()
  2.   (vl-load-com)
  3.   (if (setq ss (ssget '((0 . "*TEXT"))));选取文字
  4.     (progn
  5.   (setq lsta '())
  6.   (setq lstb '())
  7.   (setq lstc '())
  8.       (repeat (setq i (sslength ss))
  9.        (setq ent (entget (ssname ss (setq i (1- i))))
  10.            txt (cdr (assoc 1 ent)));文字值
  11.        (setq txta (HH:GetBeforeStr1 txt "*"))
  12.        (setq txtc (HH:GetBehindStr1 txt "-"))
  13.        (setq txtbc (HH:GetBehindStr1 txt "*"))
  14.        (setq txtb (HH:GetBeforeStr1 txtbc "-"))
  15.        (setq lsta (cons txta lsta))
  16.        (setq lstb (cons txtb lstb))
  17.        (setq lstc (cons txtc lstc))
  18.     )
  19.       (setq lsta (cons "宽度" lsta))
  20.     (setq lstb (cons "高度" lstb))
  21.     (setq lstc (cons "编号" lstc))
  22.      )
  23.    )
  24.    (initexcel)
  25.    (setq numrow 1)
  26.    (foreach f lsta
  27. (datacell numrow 1 f)
  28. (setq numrow (1+ numrow))
  29.       )
  30.     (setq numrow 1)
  31.     (foreach f lstb
  32. (datacell numrow 2 f)
  33. (setq numrow (1+ numrow))
  34.       )
  35.     (setq numrow 1)
  36.     (foreach f lstc
  37. (datacell numrow 3 f)
  38. (setq numrow (1+ numrow))
  39.       )
  40.   (princ)
  41. )

  42. (defun HH:GetBehindstr1 (str st);区分大小写
  43.   (car (xd::string:regexps (strcat "[^" st "]+$") str "I"))
  44. )
  45. (defun HH:GetBeforeStr1 (str st);区分大小写
  46.   (car (xd::string:regexps (strcat "[^" st "]+") str "I"))
  47. )
  48. (defun XD::String:RegExpS (pat str key / end keys matches x)
  49.   (if (not *xxvbsexp)
  50.     (setq *xxvbsexp (vlax-get-or-create-object "VBScript.RegExp"))
  51.   )
  52.   (vlax-put *xxvbsexp 'Pattern pat)
  53.   (if (not key)
  54.     (setq key "")
  55.   )
  56.   (setq key (strcase key))
  57.   (setq        keys '(("I" "IgnoreCase")
  58.                ("G" "Global")
  59.                ("M" "Multiline")
  60.               )
  61.   )
  62.   (mapcar
  63.     '(lambda (x)
  64.        (if (wcmatch key (strcat "*" (car x) "*"))
  65.          (vlax-put *xxvbsexp (read (cadr x)) 0)
  66.          (vlax-put *xxvbsexp (read (cadr x)) -1)
  67.        )
  68.      )
  69.     keys
  70.   )
  71.   (setq matches (vlax-invoke *xxvbsexp 'Execute str))
  72.   (vlax-for x matches (setq end (cons (vla-get-value x) end)))
  73.   (reverse end)
  74. )

  75. (defun initexcel ()
  76.     (setq appxls (vlax-get-or-create-object "excel.application");返回应用程序对象的运行实例。如果应用程序当前未运行,则创建新实例
  77.    xlsworkbooks (vlax-get-property appxls "workbooks");
  78.    newbook (vlax-invoke-method xlsworkbooks "add")
  79.    newsheet (vlax-get-property newbook "sheets")
  80.    newitem (vlax-get-property newsheet "item" 1)
  81.    xlscells (vlax-get-property newitem "cells")
  82.     )
  83.     (vla-put-visible appxls :vlax-true)
  84.   )
  85. (defun endexcel ()
  86.     (vlax-release-object xlscells)
  87.     (vlax-release-object newitem)
  88.     (vlax-release-object newsheet)
  89.     (vlax-release-object newbook)
  90.     (vlax-release-object xlsworkbooks)
  91.     (vlax-release-object appxls)
  92.   )
  93. (defun datacell (nurow col value)
  94.     (vlax-put-property xlscells "item" numrow col
  95.          (vl-princ-to-string value)
  96.     )
  97.   )

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

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

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-5-18 15:53 , Processed in 0.188645 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表