import pandas as pd
import os
def parseExcel(filePath):
try:
f = open(filePath, 'rb')
reader = pd.ExcelFile(f)
sheet_names = reader.sheet_names
text = ""
for sheet in sheet_names:
df = pd.read_excel(filePath, sheet_name=sheet)
text += str("\n\n\n\n\n")
text += str(sheet)
text += str("\n\n")
col_title = df.columns.values
header = ""
for i in range(len(col_title)):
header += col_title[i]
header += " "
text += str(header)
text += "\n"
for row in range(len(df)):
content = ""
for i in range(len(df.iloc[row])):
content += str(df.iloc[row,i])
content += " "
text += str(content)
text += "\n"
f.close()
return text
except Exception as e:
print(e)
f.close()
return ""
if __name__ == "__main__":
parseExcel(./111.xls)
文章评论