import sys
print("sys.path")
print(sys.path)
import xlrd
def Col2Int(s:str)->int:
for i in s:
if not 64<ord(i)<91:
raise ValueError('Excel Column ValueError')
return sum([(ord(n)-64)*26**i for i,n in enumerate(list(s)[::-1])])
file_name=r"D:\download\savedrecs.xls"
wb = xlrd.open_workbook(file_name)
sh = wb.sheet_by_name('savedrecs')
print("sh.nrows")
print(sh.nrows)
print("sh.ncols")
print(sh.ncols)
print("sh.cell(0,0).value 输出第一行第一列的值")
print(sh.cell(0,0).value)
print("输出第一行的所有值")
print(sh.row_values(0))
print("将数据和标题组合成字典")
print(dict(zip(sh.row_values(0),sh.row_values(1))))
print("遍历excel,打印所有数据")
for i in range(sh.nrows):
print(sh.row_values(i))
val_row=1
Authors_col=1
Publication_Year_col=Col2Int('AU')-1
Article_Title_col=Col2Int('I')-1
Start_Page_col=Col2Int('BB')-1
End_Page_col=Col2Int('BC')-1
print("Publication_Year_col",Publication_Year_col)
j_int=Col2Int('J')
print("j_int",j_int)
Source_Title_col_int=9
Source_Title_val = sh.cell_value(val_row,Source_Title_col_int)
Authors = sh.cell_value(val_row,Authors_col)
Publication_Year = sh.cell_value(val_row,Publication_Year_col)
Publication_Year=int(Publication_Year)
Article_Title = sh.cell_value(val_row,Article_Title_col)
Start_Page = sh.cell_value(val_row,Start_Page_col)
Start_Page=int(Start_Page)
End_Page = sh.cell_value(val_row,End_Page_col)
End_Page=int(End_Page)
print("Source_Title_val")
print(Source_Title_val)
cite_str=f"{Authors}. {Article_Title}.{Source_Title_val}.{Publication_Year}:{Start_Page}-{End_Page}"
print(cite_str)
cols="""
Publication_Year_col=Col2Int('AU')-1
Article_Title_col=Col2Int('I')-1
Start_Page_col=Col2Int('BB')-1
End_Page_col=Col2Int('BC')-1"""
lines=cols.split("\n")
print(lines)
for line in lines:
if line =="":
continue
sps=line.split("_col")
name=sps[0]
print(f"{name} = sh.cell_value(val_row,{name}_col)")
如何让web of science 的文章成为你的参考文献?
回答