MS Access 03 - 规范化 Excel 电子表格中的数据
我有一个关于分解某些东西的方法的问题。 我收到了这个 Excel 电子表格,它为我提供了制作一份报告所需的数据。 它非常简单明了,但其中有一个特定的部分让我有些悲伤。
在 Excel 电子表格中有一列,其中在一列中列出了“相关方”。 它通常是大约 12 个人的名字,用逗号分隔,但后面还有括号中的 orgID:
joe smith (DIV32)、john doe (DIV12)、roger andrews (DIV14、DIV67、DIV01) 等,
我需要将它们分解为单独的列,以便一旦我将它们导入访问,它们将成为单独的字段。 我知道如何在 Excel 中“文本到列”,但是当 jon doe(DIV13、DIV54 等)有多个分区时,这会搞砸。
不确定如何在访问中执行此操作,但很想知道。
请问有人有excel公式或者访问方法吗?
I have a question about a method to break something apart. I get this Excel spreadsheet that provides me with data that I need to do one report. Its pretty simple and straight forward, however there is one particular part of it that is giving me some grief.
In the Excel spreadsheet there is a column that lists "parties involved" in one column. It usually is about 12 people's names separated by commas, but also has orgID in parenthesis behind it:
joe smith (DIV32), john doe (DIV12), roger andrews (DIV14, DIV67, DIV01), etc
and I need to break these into individual columns so that they will be individual fields once I import them into access. I know how to "text to columns" in Excel, but this get screwed up when jon doe
(DIV13, DIV54, etc), has more than one division.
Not sure how to do this in access but would love to know.
Anyone got either an excel formula, or access method for this please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您正在将其导入数据库中。 如果没有,那么即使是暂时的,也可能会更容易。 并在每次必须运行报告时重做
您最终将得到三个表来代表这种情况
theParty 有一个 ID 列
theOrganization 将有它自己的 ID 列
thePartyOrder 将有它自己的 ID 列,一个代表政党,一个代表组织
每当您想代表一个政党作为组织的成员时,您必须确保该政党存在/已创建; 组织存在/已创建,然后在 thePartyOrg 表中创建一个指向两者的条目。
由于此连接信息仅作为文本存储在单个列中,因此最简单的方法可能是首先将其全部读入暂存表,然后在 VBA 中解析该列
I assume you are importing this into your database. If not, it is probably easier if you do, even if it's temporary; and redone every time you have to run the report
You are going to end up having three tables to represent this situation
theParty with have an ID column
theOrganisation will have it's own ID column
thePartyOrder will have it's own ID column, one for theParty, and one for theOrganisation
Whenever you want to represent a Party as bring a member of and Organisation, you have to make sure the Party exists/is created; the Organisation exists/is created, and hen create an entry in the thePartyOrg table which points at both.
Because this connection information just stored as text within a single column, it's probably a easiest to first read it all into a staging table and then parse that column in VBA
这是一个解决方案:
我编写了一个函数,用 strReplace 替换所有出现的字符串 strFind,但前提是 strFind 出现在括号内。 因此,您可以将所有“,”字符替换为其他字符(例如“*”),然后将 Excel 的文本运行到列中,然后再次将“*”替换为“,”。
步骤如下:
1) 将此宏复制到 Excel 工作簿中的模块中
2) 假设您的字符串位于 A 列中。在 B 列中,设置函数来替换逗号,如下所示
=replace_paren(A1,"," ,"*")
3) 在列中填充公式
4) 将列复制并粘贴为值
5) 使用 Excel 的文本到列以使用“,”作为分隔符来解析列
6) 再次使用replace_paren 替换所有出现的“*“ 经过 ”,”
Here's a solution:
I've written a function that replaces all occurrences of a string strFind by strReplace, but only if strFind occurs within parentheses. So you can replace all of the "," characters by something else (e.g. "*"), then run Excel's text to columns, then replace the "*"'s with "," again.
So the steps are:
1) copy this macro into a module in your Excel workbook
2) Let's say your string is in column A. In column B, set up the function to replace the commas like this
=replace_paren(A1,",","*")
3) Fill the formula down the column
4) Copy and paste the column as values
5) Use Excel's text to columns to parse the column using "," as a delimiter
6) Use replace_paren again to replace all occurrences of "*" by ","