#!/usr/bin/env python
# -*- coding: utf-8 -*- #You can use the chinese language by this.
import os
import sys
import xlwt
import xlrd
import xdrlib
from xlutils.copy import copy
from xlwt import Style #Add the plug-in
in_put=input('Please enter input file name:')
in_put_index_col=int(input('Please enter input index col :'))
in_put_col_data=int(input('Please enter input data col :'))
in_put_row_beginrange=int(input('Please enter input row begin range :'))
in_put_row_endrange=int(input('Please enter input row end range :'))
out_put=input('Please enter output file name:')
out_put_index_col=int(input('Please enter output index col :'))
out_put_col_data=int(input('Please enter output data col :'))
out_put_row_beginrange=int(input('Please enter output row begin range :'))
out_put_row_endrange=int(input('Please enter output row end range :'))
out_data = xlrd.open_workbook(out_put,formatting_info=True) # Get the out_data object of the Execl file
get_out_index=out_data.sheet_by_index(0) #Obtaining sheet objects by sheet index
in_data= xlrd.open_workbook(in_put,formatting_info=True) # Get the in_data object of the Execl file
get_in_data=in_data.sheet_by_index(0) #Obtaining sheet objects by sheet index
#book=xlwt.Workbook(encoding='utf-8',style_compression=0)
#sheet=book.add_sheet('Sheet1',cell_overwrite_ok=True)
co_file=copy(out_data) #Copy output file format
getsheet=co_file.get_sheet(0) #Get the sheet of the output file
for j in range(in_put_row_beginrange,in_put_row_endrange): #input start 8row ,end 33row
for i in range(out_put_row_beginrange,out_put_row_endrange): #output start 4row ,end 102row
in_stud_numb=get_in_data.cell_value(j,in_put_index_col) #0 5 input index col
accomplishment=get_in_data.cell_value(j,in_put_col_data) #4 9 input data col
out_stud_numb=get_out_index.cell_value(i,out_put_index_col) #2 output index col
if in_stud_numb==out_stud_numb: #Whether the comparison index is the same
getsheet.write(i,out_put_col_data,accomplishment,Style.default_style) #15 write the output data col
co_file.save(out_put) #save the output file