0

我有一个以这种方式排列的几千个来源的excel:

示例 1:

Abbott KW, Snidal D (2009) The Governance Triangle: Regulatory Standards Institutions and the Shadow of the State. In: Mattli W , Woods N (eds) The Politics of Global Regulation, pp. 44–88. Princeton University Press, Princeton, NJ

示例 2:

Moschella M , Tsingou E (eds) (2013) Great Expectations, Slow Transformations: Incremental Change in Financial Governance. ECPR Press, Colchester

我需要用这些数据将它们分成 7 列:

  1. 第一作者
  2. 第二作者
  3. 第三到N作者
  4. 出版年
  5. 来源文章的标题
  6. 发表于(不总是包括在内,但总是以 In:) 开头
  7. 更多信息 - 指在源文章标题中/之后发布的所有内容(如果它不是更大出版物的一部分)

我尝试在 excel 中使用拆分为列的工具,但由于数据种类繁多,我无法有效地做到这一点。有谁知道解决这个问题?

4

2 回答 2

1

请参阅如何使用 c# 将参考书目 MLA 字符串拆分为 BibTex?我在其中链接了几个用于从格式化文本中提取书目信息的专用工具。

于 2013-12-27T16:16:55.893 回答
0

试试这个 VBA 宏。它使用正则表达式来解析出不同的段;但如果数据不是你呈现的方式,它就会失败;因此,如果出现故障,您需要查看它与我的假设或您呈现数据的方式有何不匹配。

宏假设数据从 A1 开始,位于 A 列,第 1 行没有标签。结果写入 B 列及后续;带有标签第 1 行 - 但这些可以放置在任何地方。

此代码进入常规模块。

Option Explicit
Sub ParseBiblio()
    Dim vData As Variant
    Dim vBiblios() As Variant
    Dim rRes As Range
    Dim re As Object, mc As Object
    Dim I As Long

'Assume Data is in column A.
'Might need to start at row 2 if there is a label row
vData = Range("A1", Cells(Rows.Count, "A").End(xlUp))

'Results to start in Column B with labels in row 1
Set rRes = Range("b1")

Set re = CreateObject("vbscript.regexp")
With re
    .MultiLine = True
    .Global = True
    .ignorecase = True
    .Pattern = "(^[^,]+),?\s*([^,]+?)(?:,\s*([^(]+))?\s*\((\d{4})\)\s*(.*?\.)\s*(?:In:\s*(.*)\.)?\s*(.*)"
End With

'Results array and labels
ReDim vBiblios(1 To UBound(vData) + 1, 1 To 7)
    vBiblios(1, 1) = "First Author"
    vBiblios(1, 2) = "Second Author"
    vBiblios(1, 3) = "Other Authors"
    vBiblios(1, 4) = "Publication Year"
    vBiblios(1, 5) = "Title"
    vBiblios(1, 6) = "Published In"
    vBiblios(1, 7) = "More Info"

For I = 1 To UBound(vData)
    Set mc = re.Execute(vData(I, 1))
    If mc.Count > 0 Then
        With mc(0)
            vBiblios(I + 1, 1) = .submatches(0)
            vBiblios(I + 1, 2) = .submatches(1)
            vBiblios(I + 1, 3) = .submatches(2)
            vBiblios(I + 1, 4) = .submatches(3)
            vBiblios(I + 1, 5) = .submatches(4)
            vBiblios(I + 1, 6) = .submatches(5)
            vBiblios(I + 1, 7) = .submatches(6)
        End With
    End If
Next I

Set rRes = rRes.Resize(rowsize:=UBound(vBiblios, 1), columnsize:=UBound(vBiblios, 2))
rRes.EntireColumn.Clear
rRes = vBiblios
With rRes
    With .Rows(1)
        .Font.Bold = True
        .HorizontalAlignment = xlCenter
    End With
    .EntireColumn.AutoFit
End With

End Sub
于 2013-12-28T12:31:33.163 回答