This commit is contained in:
parent
fc942497ce
commit
5f6983ee65
|
@ -317,11 +317,14 @@ class CNASViewSet(ModelViewSet):
|
||||||
os.chdir(fulldir)
|
os.chdir(fulldir)
|
||||||
CNAS.objects.all().delete()
|
CNAS.objects.all().delete()
|
||||||
with zipfile.ZipFile(fullpath,'r') as zzz:
|
with zipfile.ZipFile(fullpath,'r') as zzz:
|
||||||
|
print(zzz)
|
||||||
zzz.extractall(fulldir)
|
zzz.extractall(fulldir)
|
||||||
for root, dirs, files in os.walk(fulldir):
|
for root, dirs, files in os.walk(fulldir):
|
||||||
for f in files:
|
for f in files:
|
||||||
|
print(f)
|
||||||
if f.endswith('.xls'):
|
if f.endswith('.xls'):
|
||||||
return Response('不支持旧xls格式', status = status.HTTP_400_BAD_REQUEST)
|
return Response('不支持旧xls格式', status = status.HTTP_400_BAD_REQUEST)
|
||||||
|
print(f.encode('cp437').decode('gbk'), os.path.join(root,f))
|
||||||
import_cnas(f.encode('cp437').decode('gbk'), os.path.join(root,f))
|
import_cnas(f.encode('cp437').decode('gbk'), os.path.join(root,f))
|
||||||
return Response(status = status.HTTP_200_OK)
|
return Response(status = status.HTTP_200_OK)
|
||||||
|
|
||||||
|
@ -386,8 +389,11 @@ def import_cma(filename, path):
|
||||||
CMA.objects.bulk_create(datalist)
|
CMA.objects.bulk_create(datalist)
|
||||||
|
|
||||||
def import_cnas(filename, path):
|
def import_cnas(filename, path):
|
||||||
|
print(path)
|
||||||
wb = load_workbook(path)
|
wb = load_workbook(path)
|
||||||
|
|
||||||
sheet = wb.get_sheet_by_name('检测能力范围')
|
sheet = wb.get_sheet_by_name('检测能力范围')
|
||||||
|
print(wb)
|
||||||
datalist = []
|
datalist = []
|
||||||
sszx = filename.replace('.xlsx','').replace('检测能力范围(含能源之星)-','')
|
sszx = filename.replace('.xlsx','').replace('检测能力范围(含能源之星)-','')
|
||||||
i = 3
|
i = 3
|
||||||
|
@ -417,6 +423,7 @@ def import_cnas(filename, path):
|
||||||
data['sszx'] = sszx
|
data['sszx'] = sszx
|
||||||
datalist.append(CNAS(**data))
|
datalist.append(CNAS(**data))
|
||||||
i = i + 1
|
i = i + 1
|
||||||
|
print(i,data)
|
||||||
CNAS.objects.bulk_create(datalist)
|
CNAS.objects.bulk_create(datalist)
|
||||||
|
|
||||||
def import_cma2(filename, path):
|
def import_cma2(filename, path):
|
||||||
|
|
Loading…
Reference in New Issue