批量修改Excel

TODO: 批量修改Excel

功能: 将图片防止在本地,读取excel数据,拆分数据之后根本地照片名称对比,然后上传服务器,创建新得excel。

#!/usr/bin/python
# -*- coding: UTF-8 -*-
__author__ = 'YongCong Wu'
# @Time : 2019/6/14 16:18
# @Email : : 1922878025@qq.com import requests, os, sys, xlwt
import pandas as pd reload(sys)
sys.setdefaultencoding('utf8') ExcelPath = 'E:\ExcelImg\Drive\\'
DirPath = 'E:\80\\' + "files\\"
read_excel_list = []
read_img_path_list = []
presence_img = None # 读取excel
def excel_list(file_path):
df = pd.read_excel(ExcelPath + file_path, names=None)
df_li = df.values.tolist()
for i in df_li:
split_str = i[1].split("/")[-1]
read_excel_list.append(split_str)
print u"Excel 读取完毕..........." # 读取图片
def red_img(dir_path):
for i in os.listdir(dir_path):
if i.endswith('jpg') or i.endswith("png"):
read_img_path_list.append(i)
print u"Image 读取完毕..........." # 两个list对比
def if_list(excel_list, img_list):
filter_List = [x for x in excel_list if x in img_list]
print u"图片对比完毕..........."
butong = [y for y in (excel_list + img_list) if y not in filter_List]
print u"存在的个数: {0}".format(len(filter_List))
print u"不存在的个数: {0}".format(len(butong))
report_excel_data = []
num = 0
for i in filter_List:
ret = update_file(DirPath + i)
num += 1
report_excel_data.append([num, "https://wuyongcong.com/files/"+ret[0], ret[1] ])
print u"当前上传成功{0}张照片".format(num)
workbook = xlwt.Workbook(encoding='utf-8')
booksheet = workbook.add_sheet("Sheet 1", cell_overwrite_ok=True)
for i, row in enumerate(report_excel_data):
for j, col in enumerate(row):
booksheet.write(i, j, col)
workbook.save(u'司机身份证正面.xls')
print u"导出Excel完成............." # 上传图片, 返回地址保存Excel
def update_file(name):
url = '上传图片服务器地址'
file_s = {'file': open(name, 'rb')}
options = {'output': 'json', 'path': '', 'scene': 'default'}
try:
r = requests.post(url, files=file_s, data=options)
res = r.json()
split_str = name.split("\\")[-1]
return split_str, res['url']
except Exception as er:
print(er) excel_list('CardPhotoPath.xlsx')
red_img(DirPath)
if_list(read_excel_list, read_img_path_list)

  

修改Excel脚本的更多相关文章

  1. Python xlrd、xlwt、xlutils修改Excel文件

    一.xlrd读取excel 这里介绍一个不错的包xlrs,可以工作在任何平台.这也就意味着你可以在Linux下读取Excel文件.首先,打开workbook:    import xlrdwb = x ...

  2. 按模板批量修改Excel文件内容

    Sub 按模板修改Excel文件() Dim MoBanWorkBook As Workbook Set MoBanWorkBook = Application.ActiveWorkbook Dim ...

  3. pythone函数基础(11)读,写,修改EXCEL

    #读EXCEL需要导入xlrd模块---在python控制台pip install xlrd模块import xlrdbook = xlrd.open_workbook('stu3.xls')shee ...

  4. 用pandas库修改excel文件里的内容,并把excel文件格式存为csv格式,再将csv格式改为html格式

    假设有Excel文件data.xlsx,其中内容为: ID  age  height     sex  weight张三   1   39     181  female      85李四   2  ...

  5. Python基础-修改excel、redis、接口开发、组织代码

    pymysql模块补充内容 1. 游标.description():显示表的字段属性 (什么是游标:游标用于交互式应用,就好比word里的光标一样,要修改某个地方,要先把光标移动到这里) 用好这个方法 ...

  6. 【转】Python xlrd、xlwt、xlutils读取、修改Excel文件

    Python xlrd.xlwt.xlutils读取.修改Excel文件 一.xlrd读取excel 这里介绍一个不错的包xlrs,可以工作在任何平台.这也就意味着你可以在Linux下读取Excel文 ...

  7. 关于JXL读写以及修改EXCEL文件<转>

    首先引用网上的文章,谈谈JXL与POI的区别 POI为apache公司的一个子项目,主要是提供一组操作windows文档的Java API. Java Excel俗称jxl是一开放源码项目,通过它Ja ...

  8. Linux:自动获取静态IP地址,清空iptable,修改selinux脚本

    自动获取静态IP地址,清空iptable,修改selinux脚本 环境:VMware 平台:centos6.8全新 功能: 1)应用ifconfig -a,route -n,cat /etc/reso ...

  9. Python xlrd、xlwt、xlutils修改Excel文件-OK

    一.xlrd读取excel 这里介绍一个不错的包xlrs,可以工作在任何平台.这也就意味着你可以在Linux下读取Excel文件. 首先,打开workbook:    import xlrdwb = ...

随机推荐

  1. manjaro web

    https://wiki.manjaro.org/index.php?title=Main_Page https://forum.manjaro.org/ https://gitlab.manjaro ...

  2. mint-ui里面的MessageBox怎么去判断确认还是取消

    MessageBox.confirm('', { title: '请注意', message: '添加供应商前,请先搜索该供应商是否存在,请勿重复添加', showCancelButton: true ...

  3. ubuntu之路——day13 只用python的numpy在较为底层的阶段实现单隐含层神经网络

    首先感谢这位博主整理的Andrew Ng的deeplearning.ai的相关作业:https://blog.csdn.net/u013733326/article/details/79827273 ...

  4. Android 系统属性-SystemProperties详解***

    创建与修改android属性用Systemproperties.set(name, value),获取android属性用Systemproperties.get(name),需要注意的是androi ...

  5. 【SpringBoot】SpringBoot快速入门(一)

    SpringBoot介绍 Spring Boot使创建可运行的独立,生产级基于Spring的应用程序变得容易.对Spring平台和第三方库整合,这样就可以以最小的麻烦开始使用.大多数Spring Bo ...

  6. [译]Pandas列数据展示不全解决方法?

    Pandas数据展示列太多会显示...不显示具体数据. 设置参数可以显示全部数据: pd.set_option('display.expand_frame_repr', False)

  7. Shell中的通配符

    shell常见的通配符,注意与正则稍有不同: 字符 含义 实例 * 匹配0个或多个任意字符 a*b,a与b之间可以有任意长度的字符,也可以没有. 例如:aabcb,ab,azxcb... ? 匹配一个 ...

  8. 【LeetCode算法-28/35】Implement strStr()/Search Insert Position

    LeetCode第28题 Return the index of the first occurrence of needle in haystack, or -1 if needle is not ...

  9. Aspose.Words操作Word.PDF,让图片和文本垂直居中,水平居中解决方案

    x 环境 { "Aspose.Words": {"Version":"18.x"} } 需求与难题 生成试卷的时候,如果数学题目中有特殊符号 ...

  10. 用于抓取vijos所有题目信息的node.js脚本

    代码如下: var superagent = require('superagent'); var fs = require('fs'); /* fetch_vijos_problems 这个脚本用于 ...