原由:
昨天晚上跟小B聊天,發現他的頭像上寫了幾個字:WYN喜歡HYJ
八卦心理作祟,想到有他的全校花名單Excel,so想找出這個HYJ還不容易。
昨晚簡單搜索了下,excel 將姓名一欄變為漢語拼音(漢字轉拼音),然后提取漢語拼音首字母縮寫。
在excel要用函數實現,發現有點復雜。放棄。
今天想想,如何拿Python去實現,搜索:python把中文文檔變為拼音,內容很多
以上參考連接:https://blog.csdn.net/qq_33232071/article/details/50915760
具體實現
import xlrd from xpinyin import Pinyin book = xlrd.open_workbook('result.xls') # 打開一個excel sheet = book.sheet_by_index(0) # 根據順序獲取sheet for i in range(sheet.nrows): p = Pinyin() # print(p.get_initials(sheet.col_values(0)[i])) if p.get_initials(sheet.col_values(0)[i])=="H-Y-J": print( sheet.row(i),i+1 )
執行結果:
[text:'何*潔', text:'1910151019', text:'23', text:'合**中', number:344.5, number:18.0, number:1004.0, number:99.0, number:98.0, number:62.5, number:23.0, number:22.0, number:40.0] 1008
用到的知識點:
1.excel文件讀取:打開文件,讀取sheet表,獲取表的所有行和列 獲取某個單元格的位置(行和列)
2.xpinyin 模塊:p.get_initials(u'上海') SH