Excel replaces the contents of a few dates of two names without changing the format

Source: Internet
Author: User

1 #-*-coding:utf-8-*-2 Importxlrd3 ImportSYS4 Importlocale5 ImportOS6 ImportXLWT7  fromXlutils.copyImportCopy8 9 Reload (SYS)TenSys.setdefaultencoding ("Utf-8" ) OneHomedir=OS.GETCWD () A PrintU"file path", Homedir - PrintU"""read the following documentation before executing the file: - 1. First please convert the Excel file to the XLS format, i.e. file Open, click File Options, click Save As and select Format XLS the (You can try the following with xlsx, sometimes error) - 2. Determine the name of the file sheet "class", and the sheet position is ranked first - 3. Place the XLS file under the file path, i.e., in a directory with the program - 4. Each revision of the completed record will be in this directory Xiugai.txt file + """ -  + defGet_col_number (excelname,sheetname,index,name): AFilehandler =Xlrd.open_workbook (excelname) atpage =filehandler.sheet_by_name (sheetname) -col1 =page.col_values (Index) -      forIteminchcol1: -         ifitem = =Name: -nrow=Col1.index (item) -     returnNrow in defchangge_worktable (excelname,sheetname,sheetnumber,number1,number2,date): -Filehandler =Xlrd.open_workbook (excelname) topage =filehandler.sheet_by_name (sheetname) +cell_value1=Page.cell (number1,date). Value -Cell_value2=Page.cell (number2,date). Value theNEWWB = Xlrd.open_workbook (Excelname, Formatting_info=true)#formatting_info with Format import *OUTWB = Copy (NEWWB)#set up a copy to write with XLWT $     #Modifying ValuesPanax Notoginseng     defSetoutcell (Outsheet, col, Row, value): -         def_getoutcell (Outsheet, Colindex, RowIndex): therow =outsheet._worksheet__rows.get (RowIndex) +             if  notRowreturnNone ACell =row._row__cells.get (Colindex) the             returnCell +Previouscell =_getoutcell (Outsheet, col, Row) - outsheet.write (Row, col, value) $         ifPreviouscell: $Newcell =_getoutcell (Outsheet, col, Row) -             ifNewcell: -Newcell.xf_idx =Previouscell.xf_idx theOutsheet =Outwb.get_sheet (Sheetnumber) - Setoutcell (Outsheet, date,number1,cell_value2)Wuyi Setoutcell (outsheet, date, number2,cell_value1) the Outwb.save (excelname) -  Wu defMain (): -Excelname=raw_input (U"Please enter excelname (with file type name):". Encode ('Utf-8'). Decode (sys.stdin.encodingorlocale.getpreferredencoding (True)) About     PrintExcelname $Sheetname=u"Class Table" -Sheetnumber=0 -      forIinchRange (0,500): -         Try: AName1=raw_input ("name1:". Encode ('Utf-8'). Decode (sys.stdin.encodingorlocale.getpreferredencoding (True)) +             Printname1 theName2=raw_input ("name2:". Encode ('Utf-8'). Decode (sys.stdin.encodingorlocale.getpreferredencoding (True)) -             Printname2 $Datenumberlist=raw_input (U"Please enter datenumber (multiple words separated by commas):"). Split (",") the             Printdatenumberlist the  theNumber1=get_col_number (excelname,sheetname,1, name1) theNumber2=get_col_number (excelname,sheetname,1, name2) -              forDatenumberinchdatenumberlist: in  theChangge_worktable (Excelname,sheetname,sheetnumber,number1,number2,int (datenumber) +3) the             Print "I:", I AboutWith open ("Xiugai.txt","a") as output: theOutput.write (name1+"***"+name2+"***"+str (datenumberlist) +"\ r \ n") the             Print "Success" the         except: +             Print "there is a error in your enter,please check and repeat the input again" -             Continue theEsc=raw_input (U"If you want to quit, enter ESC, and then press ENTER:". Encode ('Utf-8'). Decode (sys.stdin.encodingorlocale.getpreferredencoding (True))Bayi         ifesc=="ESC": the              Break the     Print "game is over" -  - if __name__=="__main__": theMain ()

The modified Excel format chart is as follows

Excel replaces the contents of a few dates of two names without changing the format

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.