J'essaie de combiner 2 files Excel différents. (grâce à la publication Importer plusieurs files Excel dans Python Pandas et les concaténer dans un seul dataframe )
Ce que je travaille jusqu'à présent est:
import os import pandas as pd df = pd.DataFrame() for f in ['c:\\file1.xls', 'c:\\ file2.xls']: data = pd.read_excel(f, 'Sheet1') df = df.append(data) df.to_excel("c:\\all.xls")
Voici comment ils ressemblent.
Cependant, je veux:
Par exemple:
C'est possible? Merci.
Pour num. 1, vous pouvez spécifier skip_footer
comme expliqué ici ; ou, en variante, faites
data = data.iloc[:-2]
une fois que vous avez lu datatables.
Pour num. 2, vous pouvez faire:
from os.path import basename data.index = [basename(f)] * len(data)
from os.path import basenamefrom os.path import basename data.index = [basename(f)] * len(data)
Aussi, peut-être serait-il préférable de mettre tous les frameworks de données dans une list, puis de les concat
à la fin; quelque chose comme:
df = [] for f in ['c:\\file1.xls', 'c:\\ file2.xls']: data = pd.read_excel(f, 'Sheet1').iloc[:-2] data.index = [os.path.basename(f)] * len(data) df.append(data) df = pd.concat(df)
df = []df = [] for f in ['c:\\file1.xls', 'c:\\ file2.xls']: data = pd.read_excel(f, 'Sheet1').iloc[:-2] data.index = [os.path.basename(f)] * len(data) df.append(data) df = pd.concat(df)
pour f dans ['c: \\ file1.xls', 'c: \\ file2.xls']:df = [] for f in ['c:\\file1.xls', 'c:\\ file2.xls']: data = pd.read_excel(f, 'Sheet1').iloc[:-2] data.index = [os.path.basename(f)] * len(data) df.append(data) df = pd.concat(df)
data = pd.read_excel (f, 'Sheet1'). iloc [: - 2]df = [] for f in ['c:\\file1.xls', 'c:\\ file2.xls']: data = pd.read_excel(f, 'Sheet1').iloc[:-2] data.index = [os.path.basename(f)] * len(data) df.append(data) df = pd.concat(df)
data.index = [os.path.basename (f)] * len (données)df = [] for f in ['c:\\file1.xls', 'c:\\ file2.xls']: data = pd.read_excel(f, 'Sheet1').iloc[:-2] data.index = [os.path.basename(f)] * len(data) df.append(data) df = pd.concat(df)
df.append (data)df = [] for f in ['c:\\file1.xls', 'c:\\ file2.xls']: data = pd.read_excel(f, 'Sheet1').iloc[:-2] data.index = [os.path.basename(f)] * len(data) df.append(data) df = pd.concat(df)
import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
importer desimport os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
import os.pathimport os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
import xlrdimport os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
import xlsxwriterimport os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
file_name = input ("Décider le nom du file de destination dans DOUBLE CITATIONS:")import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
fusioned_file_name = nom_file + ".xlsx"import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
dest_book = xlsxwriter.Workbook (fusionné_file_name)import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
dest_sheet_1 = dest_book.add_worksheet ()import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
dest_row = 1import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
temp = 0import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
path = input ("Entrez le path dans DOUBLE CITATIONS:")import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
pour root, dirs, files dans os.walk (path):import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
files = [_ for _ dans les files si _.endswith ('. xlsx')]import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
pour xlsfile dans les files:import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
imprimer ("Fichier dans le dossier mentionné est:" + file xls)import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
temp_book = xlrd.open_workbook (os.path.join (root, xlsfile))import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
temp_sheet = temp_book.sheet_by_index (0)import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
si temp == 0:import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
pour col_index dans la gamme (temp_sheet.ncols):import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
str = temp_sheet.cell_value (0, col_index)import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
dest_sheet_1.write (0, col_index, str)import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
temp = temp + 1import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
pour row_index dans la plage (1, temp_sheet.nrows):import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
pour col_index dans la gamme (temp_sheet.ncols):import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
str = temp_sheet.cell_value (row_index, col_index)import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
dest_sheet_1.write (dest_row, col_index, str)import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
dest_row = dest_row + 1import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
dest_book.close ()import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
book = xlrd.open_workbook (fusion_file_name)import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
feuille = livre.sheet_by_index (0)import os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols
imprimer "nombre de lignes dans le file de destination sont:", sheet.nrowsimport os import os.path import xlrd import xlsxwriter file_name = input("Decide the destination file name in DOUBLE QUOTES: ") merged_file_name = file_name + ".xlsx" dest_book = xlsxwriter.Workbook(merged_file_name) dest_sheet_1 = dest_book.add_worksheet() dest_row = 1 temp = 0 path = input("Enter the path in DOUBLE QUOTES: ") for root,dirs,files in os.walk(path): files = [ _ for _ in files if _.endswith('.xlsx') ] for xlsfile in files: print ("File in mentioned folder is: " + xlsfile) temp_book = xlrd.open_workbook(os.path.join(root,xlsfile)) temp_sheet = temp_book.sheet_by_index(0) if temp == 0: for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(0, col_index) dest_sheet_1.write(0, col_index, str) temp = temp + 1 for row_index in range(1, temp_sheet.nrows): for col_index in range(temp_sheet.ncols): str = temp_sheet.cell_value(row_index, col_index) dest_sheet_1.write(dest_row, col_index, str) dest_row = dest_row + 1 dest_book.close() book = xlrd.open_workbook(merged_file_name) sheet = book.sheet_by_index(0) print "number of rows in destination file are: ", sheet.nrows print "number of columns in destination file are: ", sheet.ncols