基于BCompare数据比对

需求

在数据(excel格式 )导入的时候,需要对数据库中的数据信息与新导入的信息做比对,显示每项信息的差异点。

解决方法

导出数据库中的文件为excel格式,使用 beyondcompare 工具直接比对两个excel文件即可

步骤
beyondcompare 执行命令,比对file1 与file2文件,输出为html文件,输出格式具体设置在 bcscript.txt 中

BCompare.exe "@bcscript.txt" "file1" "file2" "diff.html"

bcscript.txt 文件内容

file-report layout:side-by-side options:display-mismatches output-to:"%3" output-options:wrap-word,html-color "%1" "%2"

比对结果显示
在这里插入图片描述

显示优化

使用 BeautifulSoup 解析比对结果,使用jinja2重新渲染显示格式

from bs4 import BeautifulSoup
from jinja2 import FileSystemLoader, Environment


soup = BeautifulSoup(open('admin.html', encoding='utf-8'), 'html.parser')
tags = ''
diff_num = 0
for i in soup.find_all('tr')[1:]:
    diff_num += 1
    sys_stock_info = ''.join([str(x) for x in i.find_all('td')[:6]])
    import_stcok_info = ''.join([str(x) for x in i.find_all('td')[7:13]])
    tags += '''
    <tr> <td colspan="7" ><b>差异点 %d </b></td></tr>
    <tr class="SectionMiddle"><td>系统存货信息</td> %s </tr>
    <tr class="SectionMiddle"><td>本次导入存货</td> %s </tr> 
    ''' % (diff_num, sys_stock_info, import_stcok_info)

env = Environment(loader=FileSystemLoader(r'D:\codepath\kunlun_automation_bom\bom_system\utils'))  # 指定模板文件的加载路径
template = env.get_template('temp.html')  # 获取加载路劲下的模板文件
out_html = template.render(tags=tags)  # 渲染
with open('out.html', 'w', encoding='utf-8') as f:
    f.write(out_html)

temp.html 模板文件,省略css样式设置

****
<table cellspacing="0" cellpadding="0">
    <tr>
        <td width="90px"></td>
        <td width="90px">料号</td>
        <td width="90px">存货名称</td>
        <td width="90px">生产类别</td>
        <td>规格型号</td>
        <td width="90px">品牌</td>
        <td width="90px">互替品牌</td>
    </tr>
    {% autoescape off %}
    {{ tags }}
    {% endautoescape %}
</table>
****

重新生成的比对信息
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值