We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent afe5798 commit 5cec24bCopy full SHA for 5cec24b
1 file changed
save_excel_to_mysql.py
@@ -3,6 +3,7 @@
3
import MySQLdb
4
import os
5
import logging
6
+import shutil
7
import sys
8
9
@@ -12,17 +13,21 @@ def main(path):
12
13
"""
14
files = os.listdir(path)
15
for file in files:
- save_file(path + '/' + file)
16
+ save_file(path + '/' + file, file)
17
print(file)
- logging.info(file)
18
19
20
-def save_file(file):
+def save_file(file, filename):
21
22
打开excel文件
23
24
- book = xlrd.open_workbook(file)
25
- sheet = book.sheet_by_index(0)
+ try:
+ book = xlrd.open_workbook(file)
26
+ sheet = book.sheet_by_index(0)
27
+ except Exception as e:
28
+ logging.info('错误:{0} 文件:{1}'.format(e, file))
29
+ shutil.copy2(file, './error' + filename)
30
+ return False
31
row_nums = sheet.nrows
32
col_nums = sheet.ncols
33
0 commit comments