如何将CSV /表格数据转换成不同的形状?

我有一个稀疏的n列电子表格,其中前两列描述一个人,其余(n-2)列跟踪RSVP和各种事件(每个占用一列)的出席数据。 它看起来像这样:

PersonID, Name, Event29108294, Event01838401, Event10128384 12345, John Smith, Registered - NoShow, Registered and Attended, RSVPed Maybe and did not attend 982348, Mary Levitsky, Registered - NoShow, RSVPed No, 1873218, Alexa Maris, , Registered and Attended, 8294, Katlyn Johnson, , , Registered and Attended 

我需要将其加载到存储出勤信息的数据库中,作为“每个人和事件的填充交叉点的一行”。 因此,我需要将数据转换为如下所示:

  EventID, PersonID, PersonName, Status Event29108294, 12345, John Smith, Registered - NoShow Event29108294, 982348, Mary Levitsky, Registered - NoShow Event01838401, 12345, John Smith, Registered and Attended Event01838401, 982348, Mary Levitsky, RSVPed No Event01838401, 1873218, Alexa Maris, Registered and Attended Event10128384, 12345, John Smith, RSVPed Maybe and did not attend Event10128384, 8294, Katlyn Johnson, Registered and Attended 

(我知道包含这些名称并不是正常的forms……他们不会在最终的数据加载中,但在进行数据加载之前,他们对于人类的校对是很好的。)

我如何使用Excel或Windows PC用户轻松访问的任何其他工具来执行此操作? (我已经安装了Excel,Microsoft LogParser,Microsoft Access和PortablePython。)

谢谢!

-K

假设你的事件是在不同的列,这样的事情会起作用 –

 Sub test() Dim wsOrig As Worksheet Set wsOrig = ActiveSheet Dim wsDest As Worksheet Set wsDest = Sheets("Sheet2") Dim lcol As Integer lcol = Cells(1, Columns.Count).End(xlToLeft).Column Dim lrow As Integer lrow = Cells(Rows.Count, "A").End(xlUp).row Dim x As Integer x = 2 wsDest.Cells(1, 1) = "EventID" wsDest.Cells(1, 2) = wsOrig.Cells(1, 1) wsDest.Cells(1, 3) = wsOrig.Cells(1, 2) wsDest.Cells(1, 4) = "Status" For i = 2 To lrow For j = 3 To lcol If Cells(i, j) <> "" Then wsDest.Cells(x, 1) = wsOrig.Cells(1, j) wsDest.Cells(x, 2) = wsOrig.Cells(i, 1) wsDest.Cells(x, 3) = wsOrig.Cells(i, 2) wsDest.Cells(x, 4) = wsOrig.Cells(i, j) x = x + 1 End If Next Next End Sub 

如果您使用的是.csv,则可能需要避免使用两张纸。 此外,可能有一个更优雅的方式来做到这一点与数组。