xlwt.Workbook()에서 워크 시트의 열 수를 반환하는 방법을 찾지 못하는 것 같습니다. 이 아이디어는 디렉토리에서 .xls 파일의 뭉치를 하나의 파일로 결합하는 것입니다. 한 가지 문제는 다음 파일을 작성할 때 열 위치를 변경하는 것입니다. 이것은 내가 지금까지 함께 일하고 있어요 무엇 :xlwt 워크 시트의 열 수
import xlwt, xlrd, os
def cbc(rd_sheet, wt_sheet, rlo=0, rhi=None,
rshift=0, clo=0, chi=None, cshift = 0):
if rhi is None: rhi = rd_sheet.nrows
if chi is None: chi = 2#only first two cols needed
for row_index in xrange(rlo, rhi):
for col_index in xrange(clo, chi):
cell = rd_sheet.cell(row_index, col_index)
wt_sheet.write(row_index + rshift, col_index + cshift, cell.value)
Dir = '/home/gerg/Desktop/ex_files'
ext = '.xls'
list_xls = [file for file in os.listdir(Dir) if file.endswith(ext)]
files = [Dir + '/%s' % n for n in list_xls]
output = '/home/gerg/Desktop/ex_files/copy_test.xls'
wbook = xlwt.Workbook()
wsheet = wbook.add_sheet('Summary', cell_overwrite_ok=True)#overwrite just for the repeated testing
for XLS in files:
rbook = xlrd.open_workbook(XLS)
rsheet = rbook.sheet_by_index(0)
cbc(rsheet, wsheet, cshift = 0)
wbook.save(output)
list_xls 반환 :
['file2.xls', 'file3.xls', 'file1.xls', 'copy_test.xls']
파일을 반환 :
['/home/gerg/Desktop/ex_files/file2.xls', '/home/gerg/Desktop/ex_files/file3.xls', '/home/gerg/Desktop/ex_files/file1.xls', '/home/gerg/Desktop/ex_files/copy_test.xls']
내 질문 xlwt에 기록 된 각 파일을 닫게하는 방법입니다. 매번 2 번씩 통합 문서. 이 코드는 내게 .../copy_test.xls
에 저장된 첫 번째 파일을 제공합니다. 파일 목록에도 문제가 있습니까? 나는 있을지도 모른다는 느낌이 들었다. 이것은 Python2.6이며 Windows와 Linux간에 바운스됩니다.
이것은 어떻게 ArcGIS (또는 GIS)와 관련이 있습니까? 그것은 파이썬/엑셀 문제처럼 보입니다 : 이것은 당신이 질문을 SO로 옮기는 더 빠르고 (그리고 더 많은) 조언을 얻을 수 있음을 의미합니다. – whuber
전체 질문 : 피처 클래스의 모든 필드에 대한 테이블 요약을 만들고 파이썬을 arcscript 도구로 사용하고 일별, 주별로 자동 파이썬 스크립트를 사용하여 단일 XLS로 출력하는 방법은 무엇입니까? 나는이 질문으로 지금까지 얻었습니다. – gm70560