将 CSV 文件中单元格的内容拆分为单独的单元格
我有一个大型 CSV 文件,其中包含组织名称和地址。我需要将一个干净的 csv 文件交给需要围绕它们构建数据库的开发人员。
问题是街道名称和号码位于同一单元格中,并且需要将它们分开,以便我们可以按街道名称过滤组织。
因此,我想将地址单元格的内容拆分为两个单元格。地址单元格的构建方式如下:[街道名称][空格][数字][等] - 所以我只需要保留街道名称,并将街道名称后面的所有内容移动到另一个单元格。
一个示例是内容单元格 D7:
[D7]Konkylievej 3, 1.mf[/D7]
必须像这样拆分:
[D7]Konkylievej[/D7]
[E7]3, 1.mf[/E7 ]
CSV 文件的大小使得无法手动完成此操作。有什么办法可以自动完成吗?
I have a large CSV file full of organisations names and addresses. I need to hand over a clean csv file to our developers who need to build a database around them.
The problem is that the street names and numbers are in the same cell, and they need to be separate, so that we can filter organisations by street names.
So, I would like to split the content of the address cell, into two cells. The address cell is built like this: [streetname][space][digits][etc] - So I need to keep only the street name, and move everything after street name to another cell.
An example would be the content cell D7:
[D7]Konkylievej 3, 1. m.f.[/D7]
Which would have to be split like this:
[D7]Konkylievej[/D7]
[E7]3, 1. m.f.[/E7]
The size of the CSV file makes this impossible to do manually. Is there any way to do it automatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不是最优雅的解决方案,但请尝试这个......
Not the most elegant solution but please try this...
这会随着您使用的 Excel 版本的不同而略有变化,但基本上您应该选择列,然后在菜单中找到“文本到列”(最有可能是 2007 年之前版本中的“数据菜单”,或者 2007 年以后版本中的“数据功能区”。)
然后在对话框中选择“分隔”,然后告诉 Excel 使用空格将文本与列分隔开。
希望有效
This changes slightly with the version of Excel you're using, but basically you should select the column, and find "Text to Columns" in the menu (most probably Data Menu in versions before 2007, or Data Ribbon in 2007 onwards.)
Then in the dialog box, select "Delimited", then tell excel to use spaces to separate the text to columns.
Hope that works
由于您只需将其拆分为两个单元格,因此您可以使用一小段 VBA 代码来完成此操作。将其粘贴到 VBA 工作簿的 Sheet1 代码中(Alt-F11 进入 VBA 编辑器)。将范围从 A1:A200 更改为您需要的任何内容,以及不同的工作表名称(您的数据可能不在 Sheet1 上)。设置完成后,按 F5,它应该会执行您想要的操作。显然,您可能希望在原始数据的副本中对此进行测试,以确保获得预期的结果。我用“123 Main”填充了几个单元格,然后在 A 列中填充了“123”,在 B 列中填充了“Main”。它将把第一个空格右侧的所有内容放入 B 列中,并将所有内容修剪到右侧的空间,并将剩余的内容留在 A 列中。
Since you only need to split this into two cells, you can accomplish this with a short bit of VBA code. Paste this into the Sheet1 code of your VBA workbook (Alt-F11 to get to VBA editor). Change the range from A1:A200 to whatever you need, as well as the different sheet name (your data might not be on Sheet1). Once you've got it set up, hit F5 and it should do what you're looking for. Obviously you might want to test this in a copy of your original data to make sure you get the expected results. I populated several cells with "123 Main" and afterward had "123" in column A and "Main" in column B. It will take everything to the right of the first space and put it into col B, and trim everything to the right of the space and leave what's left in column A.