vba中如何优化多行文本的TEXTSTRING属性?
本帖最后由 truezhang 于 2024-3-24 22:14 编辑data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA5MAAAATCAYAAAANt1nMAAAE8UlEQVR4nO2d227sIAxFk6P+/y9PH44iIWobG0wCmbWkqk1CNuaSMQY6OT+fz+eoOM/zEE6nIem3ztXXI+mvv8/zPI7jaKaRfrfsAQAAmE3Uf2q+0+MPvTqab8ZPAgC8nx/twuVoPESdheSAsojaHUkf1QcAAMgk4j8vfzXqby2dmf4cAADWRw0msx1Dj7ORZk8993j0apu8QSIOEwAA7qQ3WLP8W2QyNeonAQDge1CDyRmUjkhyjFLgKAWAWvo6bXlszahK2hKSPgAAwGw03yP5OMmXaROptUapH9GxfDMAALyX84n/mYywki0AAAAAAADwn1tXJiMwswkAAAAAALAuywaTBJEAAAAAAADr8u9pAwAAAAAAAGA/CCYBAAAWov5CnJU5z3MLO6NklWk1nV3yhT3p6S+Re97eH63P05X9AsGkwoqNBQAA38nKPkn6ZliNSPA5u8wROzJtWbktn4a6eZaR+r++MNPSuJ6l8kc6r9Hzfvid2PVf/G77n0ntPVcz89i1UQAA4DspB2Rv82H1q0SkgWFPmbVXmmTVnzWAzXpdWOZrx6S+43k1W0Z9aa+d0fL1atZIr6Tx6EfSW32zdS1ax5568zwrPTqalqThybf1+RXpB57nrsxTyyurn4z0n1F7VvYLt34BT1kRozML0gNjPejRBlixsQAA4N2UA7L6/KoDiRKvnVK63sCyNyjNDtq87SMFej06mk1RO2dtxe0pl9Z/pPFjVD+avrZFG9BL71iN4K03zZ4MHa3MVj3UupGA0qoDqe2tcllpLXujx9H7eu2xyrXq5/9t21w9FTwzPwAAAFgX/PY4Uh3uXq93jx+j1IGXxWpbNEcnLqQA8uI61iY46m2tV6Br5Wcd99ifoZdt144s82oQa5uKdq3ugNrWFim9Rz8yY5qxVQcAAMCL5ncs/1bf1/KHV3pthj1qa9Rvj/hhj1bPlrsR/56hUWt59ay29bSlVf8tHc+K6WykYMdjT11vVr/V0Oone7dezzMZTV+vkmnBVCs4nL067l0Fv+6zguIenag9td5OccQSX8BTL70fhz0TVTZ4fV56mKT09XJ9a2ap1qi3NUjaAAAAWWiDnIj/tHyedE3S85z3+GHJdm+e2j1agBAdIGp5jw78s8YHWlu18rYGvp77IzrlypQ1rtLuy6ass54+V58btTMrYOjVida/1t/KOo32SS91sKwFz1b7RvPKet6jOrsFksdhrExGKi97hq3U7anUyH0ZtvfMUgEAAMyix38+6b9mzsa/fdvZSJ1JE+OZOm8ZE2n9M9JvpeB7dv23mBn4edJpx9IE2HVeO46WpQxIRz5/NJ239H0PajB5dyVI+UUa+MlIfsdZBAAAeC+jA6Q7uMu2VcufRasePSuDI22h6Wh/787oSqC13biHUZ2sIFY771nxtWyQVvUk/dHJs4z6H7FnZ86PUNI7Zgdr/fpa+bBpD56UPqrvSduyr1U2AACALLSVDWmwGvWf1sRuyxavnVK+LRtLPem3Vn5LK1Jma9XkCZ3ynlH91rURHWvXViQIjpZL0x4pqxY4efqt5zhyTrO/R0fSutJ5xsuRiQxrNdA6582z9/laSWfHIPTWYPKtaA8LAABANlkrPpHtaK3BW0+wsDJZtq+mM5pvph29K6qz2Lm/ziBjV6AVTB7H322rUqD9hmDLi/V5ujK/K12CA95n8KEAAAAASUVORK5CYII=我的多行文本内容原本是RS1A40D25E 含底座50*80*50,由于位置排版原因,没有选择使用单行文本,发现选择集里面textstring属性有很长一串特殊符号,这些符号有可能去掉吗?想导入到EXCEL里面作为元件规格显示
多行文字解析:
https://help.autodesk.com/view/ACD/2016/CHS/?guid=GUID-7D8BB40F-5C4E-4AE5-BD75-9ED7112E5967 本帖最后由 liuhe 于 2024-3-25 08:56 编辑
简单粗暴的方法是,复制这个图元,然后用自带命令分解(一定要是command的分解命令)成单行文字,就可以读取里面纯文本内容。高级一点的是,通过正则规则,格式化这些格式,输出纯文本。;;-------------------=={ UnFormat String }==------------------;;
;; ;;
;;Returns a string with all MText formatting codes removed. ;;
;;------------------------------------------------------------;;
;;Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;;Arguments: ;;
;;str - String to Process ;;
;;mtx - MText Flag (T if string is for use in MText) ;;
;;------------------------------------------------------------;;
;;Returns:String with formatting codes removed ;;
;;------------------------------------------------------------;;
(defun LM:UnFormat ( str mtx / _replace rx )
(defun _replace ( new old str )
(vlax-put-property rx 'pattern old)
(vlax-invoke rx 'replace str new)
)
(if (setq rx (vlax-get-or-create-object "VBScript.RegExp"))
(progn
(setq str
(vl-catch-all-apply
(function
(lambda ( )
(vlax-put-property rx 'global actrue)
(vlax-put-property rx 'multilineactrue)
(vlax-put-property rx 'ignorecase acfalse)
(foreach pair
'(
("\032" . "\\\\\\\\")
(" " . "\\\\P|\\n|\\t")
("$1" . "\\\\(\\\\)|\\\\[^\\\\;]*;|\\\\")
("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);")
("$1$2" . "\\\\(\\\\S)|[\\\\](})|}")
("$1" . "[\\\\]({)|{")
)
(setq str (_replace (car pair) (cdr pair) str))
)
(if mtx
(_replace "\\\\" "\032" (_replace "\\$1$2$3" "(\\\\)|({)|(})" str))
(_replace "\\" "\032" str)
)
)
)
)
)
(vlax-release-object rx)
(if (null (vl-catch-all-error-p str))
str
)
)
)
)
(vl-load-com)
_ (LM:UnFormat "{\\O\\C1;L\\C256;ee} {\\L\\C2;M\\C256;ac}" nil)
"Lee Mac"
liuhe 发表于 2024-3-25 08:54
简单粗暴的方法是,复制这个图元,然后用自带命令分解(一定要是command的分解命令)成单行文字,就可以读 ...
炸开方式漏洞太大,如果只读的话还得恢复;如果有不同格式,会被炸成多个单行文字。论坛里有去除格式字符的vba源代码。
页:
[1]