Python modifies instance code for Excel data

Source: Internet
Author: User
In the previous article, we described how to read and write Excel data in Python, and how to modify Excel data with Python today. Need to use the Xlutils module. The download address is https://pypi.python.org/pypi/xlutils. After downloading, execute the Python setup.py install command for installation.
The following code is used:
Copy CodeThe code is as follows:


#-*-coding:utf-8-*-
From xlutils.copy import Copy # Http://pypi.python.org/pypi/xlutils
From xlrd import Open_workbook # http://pypi.python.org/pypi/xlrd
From XLWT import EASYXF # HTTP://PYPI.PYTHON.ORG/PYPI/XLWT

Import Sys
Reload (SYS)
Sys.setdefaultencoding (' Utf-8 ')

# 0 based (subtract 1 from Excel row number)
Start_row = 404

Ismal_index = 2
#url所在列
Url_index = 12
#domain所在列
Domain_index = 11
#malinfo所在列
Malinfo_index = 9

File_path = "C:\\users\\***\\desktop\\20130514.xls"
#formatting_info =true The format of the data before saving
RB = Open_workbook (file_path,formatting_info=true)
R_sheet = Rb.sheet_by_index (0) # Read only copy to introspect the file
WB = Copy (RB) # A writable copy (I can ' t read values out of this, only write to it)
W_sheet = Wb.get_sheet (0) # The sheet to write to within the writable copy

Malurl = "' Http://xbox.ooqqxx.com/res/ext.jar
Http://xbox.ooqqxx.com/res/stat.jar
Http://xbox.ooqqxx.com/pages/v.html
Http://xbox.ooqqxx.com/pages/extv.html
Http://xbox.ooqqxx.com/pages/r.html ""
Domain_info = "Http://xbox.ooqqxx.com"
Malinfo = u "gets the malicious URL, writes the configuration file, and downloads the malicious executable program. "

#r_sheet. Nrows is the total number of rows
For Row_index in range (Start_row, r_sheet.nrows):
#xlsvalue = R_sheet.cell (Row_index, col_age_november). Value
W_sheet.write (Row_index, Ismal_index, U ' is ')
W_sheet.write (Row_index, Url_index, Malurl)
W_sheet.write (Row_index, Domain_index, Domain_info)
W_sheet.write (Row_index, Malinfo_index, Malinfo)
#wb. Save (File_path + '. Out ' + os.path.splitext (file_path) [-1])
Wb.save ("C:\\users\\***\\desktop\\2013.xls")

  • 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.