【问题标题】:MS Access 03 - Normalizing Data from an Excel spreadsheetMS Access 03 - 规范化 Excel 电子表格中的数据
【发布时间】:2009-07-21 14:54:20
【问题描述】:

我有一个关于分解某些东西的方法的问题。我得到了这个 Excel 电子表格,它为我提供了制作一份报告所需的数据。它非常简单直接,但是其中有一个特别的部分让我有些悲伤。

在 Excel 电子表格中,有一列在其中一列中列出了“所涉及的各方”。一般是12人左右的名字,用逗号隔开,后面括号里也有orgID:

joe smith (DIV32)、john doe (DIV12)、roger andrews (DIV14、DIV67、DIV01) 等

我需要将它们分成单独的列,以便在我将它们导入访问时它们将成为单独的字段。我知道如何在 Excel 中“文本到列”,但是当jon doe(DIV13、DIV54 等)有多个部门时,这会搞砸。

不确定如何在访问中执行此操作,但很想知道。

请问谁有excel公式,或者这个的访问方法?

【问题讨论】:

    标签: excel ms-access excel-formula normalizing


    【解决方案1】:

    我假设您正在将它导入到您的数据库中。如果没有,即使是暂时的,如果你这样做可能会更容易;并在每次必须运行报告时重做

    你最终会得到三个表来代表这种情况

    1. 党(人)
    2. 组织
    3. 党组织

    具有 ID 列的一方

    组织将拥有自己的 ID 列

    PartyOrder 将有它自己的 ID 列,一个用于 theParty,一个用于 theOrganisation

    当您想代表一个政党作为组织的成员时,您必须确保该政党存在/已创建;组织存在/已创建,然后在 thePartyOrg 表中创建一个指向两者的条目。

    由于此连接信息仅作为文本存储在单个列中,因此首先将其全部读入临时表然后在 VBA 中解析该列可能是最简单的方法

    【讨论】:

      【解决方案2】:

      这里有一个解决方案:

      我编写了一个函数,它用 strReplace 替换所有出现的字符串 strFind,但前提是 strFind 出现在括号内。因此,您可以将所有“,”字符替换为其他字符(例如“*”),然后将 Excel 的文本运行到列,然后再次将“*”替换为“,”。

      Function replace_paren(strSource As String, strFind As String, strReplace As String) As String
          ' Within strString, replaces any occurrence of strFind with strReplace *IF* strFind occurs within parentheses '
      
          Dim intOpenParenIndex As Integer
          Dim intCloseParenIndex As Integer
      
          Do
              intOpenParenIndex = InStr(intCloseParenIndex + 1, strSource, "(")
              intCloseParenIndex = InStr(intOpenParenIndex + 1, strSource, ")")
              If intOpenParenIndex = 0 Then
                  Exit Do
              End If
      
              Mid(strSource, intOpenParenIndex, intCloseParenIndex - intOpenParenIndex) = Replace(Mid(strSource, intOpenParenIndex, intCloseParenIndex - intOpenParenIndex), strFind, strReplace)
          Loop
      
          replace_paren = strSource
      
      End Function
      

      所以步骤是:

      1) 将此宏复制到 Excel 工作簿中的模块中

      2)假设您的字符串在A列中。在B列中,设置函数以替换逗号

      =replace_paren(A1,",","*")

      3) 将公式向下填充列

      4) 将该列复制并粘贴为值

      5) 使用 Excel 的文本到列来解析列,使用“,”作为分隔符

      6) 再次使用replace_paren 将所有出现的“*”替换为“,”

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-10-24
        • 2021-11-07
        • 1970-01-01
        • 2014-10-13
        相关资源
        最近更新 更多