Word 2007 - 如何将制表符不一致的文本转换为表格?

发布于 2024-09-04 02:13:58 字数 675 浏览 2 评论 0原文

我有一大堆格式很奇怪的表格,因为当一群人用选项卡制作表格时,人们不能指望所有表格上的选项卡都保持一致。

例如...我有这个表:2列乘11行...但我想要一个不关心列数和行数的宏

space space space **column header** tab tab tab tab **column header**
tab **data** tab tab tab **data** tab tab
tab **data** tab tab **data**
tab **data** tab tab tab tab **data**
tab **data** tab tab **data**

目前,我有这个宏,

Sub ConvertTextToATable()

     Selection.ConvertToTable Separator:=wdWhite, AutoFitBehavior:=wdAutoFitFixed

End Sub

我已经尝试过制表符分隔符。 ..但两者都给出相似的结果。每次遇到新的空白字符时,它都会创建一个新列。我想要的是忽略所有空白,并在每次遇到文本时创建一个新单元格,并在每次遇到 \n 或 \r 时创建一个新行。

由于我不能保证每个表都具有与数据相同数量的列标题,因此我认为列数应该由原始伪表文本中的第二行或第三行确定。

I have a whole bunch of tables that were formatted weird, because when a bunch of people make tables out of tabs, one cannot expect the tabbing to be consistent on all of them.

For example... I have this table: 2 cols by 11 rows... but I would like a macro that didn't care about the number of columns and rows

space space space **column header** tab tab tab tab **column header**
tab **data** tab tab tab **data** tab tab
tab **data** tab tab **data**
tab **data** tab tab tab tab **data**
tab **data** tab tab **data**

Currently, I have this macro

Sub ConvertTextToATable()

     Selection.ConvertToTable Separator:=wdWhite, AutoFitBehavior:=wdAutoFitFixed

End Sub

I've tried the tab separator... but both give similar results. It creates a new column every time a new white space character is encountered. What I want is ignoring all white space, and creating a new cell every time text is encountered, and creating a new row every time \n or \r is encountered.

And since I can't guarantee that every table with have the same number of column headers as the data, I think the number of columns should be determined by the second or third row in the text of original pseudo table.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〃温暖了心ぐ 2024-09-11 02:13:58

DerNalia,这需要正则表达式。在 Office VBA 编辑器中添加对 Microsoft VBScript 正则表达式 5.5 的引用:
图片VBA 参考
(来源:david at wbtn.net

然后,在宏中使用 Regex 对象将选项卡的所有多个实例替换为一个选项卡。然后您可以像平常一样使用 ConvertToTable 命令。

DerNalia, this calls for a Regular Expression. Add a reference to Microsoft VBScript Regular Expressions 5.5 in your Office VBA editor:
Image of VBA references
(source: david at wbtn.net)

Then, in your Macro use the Regex objects to replace all multiple instances of a tab with just one tab. Then you can use your ConvertToTable command like normal.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文