Python processing spreadsheets

Source: Internet
Author: User

import xlrdimport xlwt# #输入input_ip  = raw_input ("Please enter an IP:") input_count_values =  Int (raw_input ("Enter -1 or +1 :")) #新建电子表格wbk  =XLWT. Workbook (encoding= ' utf-8 ',  style_compression=0) new_sheet1 =wbk.add_sheet (' Sheet1 ',  cell_ Overwrite_ok=true) STYLE = XLWT. Xfstyle ()   #读取电子表格data  = xlrd.open_workbook (' D:\\1.xls ') table_sheet1 = data.sheet_by_ Name (U ' Sheet1 ') #取得原表格的总行数与总列数Sheet1_nrows  = table_sheet1.nrowssheet1_ncols = table_ sheet1.ncols# Create an empty  list  object to get   non-writable Table_sheet1_data =[]for i in range ( Sheet1_nrows):     table_sheet1_data.append (Table_sheet1.row_values (i)) #print  table_ sheet1_data# Cyclic judging condition  count_for_find = 0for where_you_need in table_sheet1_data:     if input_ip in where_you_need:         print  "FIND", Count_for_find        if where_you_need[-1] > 0 or  input_count_values == +1:             where_you_need[-1] = where_you_need[-1] + input_count_values              #print  where_you_need         else:            print  "Last_values=0  cannot -1 "         break    count_ For_find = count_for_find + 1print table_sheet1_data# writes the new list  to a newer spreadsheet count_x  = 0for x in table_Sheet1_data:    count_y =0     for y in x:        new_sheet1.write (count_x , Count_y,y,style)         count_y = count_y + 1     Count_x = count_x + 1wbk.save (' D:\TestData2.xls ')

This article is from the "Romantic Laugh" blog, make sure to keep this source http://lmdtx.blog.51cto.com/6942028/1643537

Python processing spreadsheets

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.