使用vba excel将txt(bibtex)文件转换为csv

时间:2017-05-08 17:46:43

标签: excel vba

我想请求您提供以下帮助: 我想将txt文件(bibtex)转换为带有vba的csv这里是我要转换的文本:

@inproceedings{orfila2015ecodriving,
title={Ecodriving performances of human drivers in a virtual and realistic 
world},
author={Orfila, Olivier and Gruyer, Dominique and Judalet, Vincent and 
Revilloud, Marc},
booktitle={Intelligent Vehicles Symposium (IV), 2015 IEEE},
pages={790--795},
year={2015},
organization={IEEE}
}

1 个答案:

答案 0 :(得分:0)

谢谢你的帮助,我发现了怎么做:`

 Sub Button1_Click()
'ADD BIBTEX
 Dim myFile As String, text As String, textline As String, posLat As 
 Integer, 
 posLong As Integer
 myFile = Application.GetOpenFilename()
 Open myFile For Input As #1
 Do Until EOF(1)
 Line Input #1, textline
 text = text & textline
 Loop
 Close #1

'Add Rows
 Dim the_sheet As Worksheet
 Dim table_list_object As ListObject
 Dim table_object_row As ListRow
 Set the_sheet = Sheets("Data")
 Set table_list_object = the_sheet.ListObjects(1)
 Set table_object_row = table_list_object.ListRows.Add



Dim LArray() As String
Dim smallTxt() As String

smallTxt() = Split(text, "@")
lNumElements = UBound(smallTxt()) - LBound(smallTxt())


For i = 1 To lNumElements

LArray() = Split(smallTxt(i), "=")

b = InStr(LArray(0), "@")
If (b = 1) Then a = 5

Title = Mid(LArray(1), InStr(LArray(1), "{") + 1, Len(LArray(1)) - 
Len("Author") - 5)

table_object_row.Range(i, 1).Value = Title

Author = Mid(LArray(2), InStr(LArray(2), "{") + 1, Len(LArray(2)) - 
Len("booktitle") - 5)

table_object_row.Range(i, 2).Value = Author

If InStr(LArray(2), "journal") > 0 Then journal = Mid(LArray(3), 
InStr(LArray(3), "{") + 1, Len(LArray(3)) - Len("pages") - 5)
If InStr(LArray(2), "journal") = 0 Then MsgBox "Verifier que journal vient 
aprés Author"
table_object_row.Range(i, 3).Value = journal

If InStr(LArray(3), "pages") > 0 Then Pages = Mid(LArray(4), 
InStr(LArray(4), "{") + 1, Len(LArray(4)) - Len("year") - 5)
If InStr(LArray(3), "pages") = 0 Then MsgBox "Verifier que pages vient aprés 
journal"
table_object_row.Range(i, 4).Value = Pages

If InStr(LArray(4), "year") > 0 Then Year1 = Mid(LArray(5), InStr(LArray(5), 
"{") + 1, Len(LArray(5)) - Len("publisher") - 5)
If InStr(LArray(4), "year") = 0 Then MsgBox "Verifier que year vient aprés 
pages"
table_object_row.Range(i, 5).Value = Year1
If InStr(LArray(5), "publisher") > 0 Then publisher = Mid(LArray(6), 
InStr(LArray(6), "{") + 1, Len(LArray(6)) - 3)
If InStr(LArray(5), "publisher") = 0 Then MsgBox "Verifier que publisher 
vient aprés year"
table_object_row.Range(i, 6).Value = publisher

Next i



End Sub

这是我与之合作的Bibtext

@article{goldberg1988genetic,
title={Genetic algorithms and machine learning},
author={Goldberg, David E and Holland, John H},
journal={Machine learning},
pages={95--99},
year={1988},
publisher={Springer}
}
@tobii{goldberg1988genetic,
title={Genetic algorithms and machine learning},
author={Goldberg, David E and Holland, John H},
journal={zobi},
pages={95--99},
year={1988},
publisher={Springer}
}
@article{goldberg1988genetic,
title={Genetic algorithms and machine learning},
author={Goldberg, David E and Holland, John H},
journal={tabon},
pages={95--99},
year={1988},
publisher={Springer}
}