专业的JAVA编程教程与资源

网站首页 > java教程 正文

用BxScript读取Excel(读取blob字段)

temp10 2024-10-08 18:17:34 java教程 8 ℃ 0 评论

BxScript已经更新到V1.0.2了,此次更新增加ole包相关,方便调用COM接口,目前增加了Excel相关支持,可以读取和修改Excel。

仅需不足30行代码,就可以轻松调用WPS来实现读取Excel功能,查询是否包含指定内容;代码示例如下:

用BxScript读取Excel(读取blob字段)

运行示例

软件会在打开的时候弹出文件选择框,选择excel文件;如果没有选择文件会提示请选择excel文件;在输入框中输入商品条码,点击查询如果有对应商品会在输入框上方显示对应的商品名称。

excel文件内容如下:仅包含一个sheet页,sheet中仅两列数据,第一列为商品名称,第二列为商品条码。

代码如下:

Win.create("BxScript", 800, 600, true, false, true);
Win.add([
    {"x":325,"y":135,"width":100,"height":30,"fontSize":10,"font":"微软雅黑","id":"submit","type":"button","title":"查询"},
    {"x":100,"y":135,"width":220,"height":30,"fontSize":10,"font":"微软雅黑","id":"noInput","type":"input","title":"请输入条码"},
    {"x":100,"y":90,"width":500,"height":35,"fontSize":20,"font":"微软雅黑","id":"tips","type":"label","title":"暂无数据"},
]);

var excelPath = Win.chooseFile();
if(!excelPath){
    Win.alert("请选择excel文件","提示");
}

Win.submit.onClick = function(){
    Win.submit.setEnable(false);
    var no = Win.noInput.getText()
    var excel = Excel.open(excelPath).getSheet(0);
    var rowCount = excel.rowCount();
    for(var i = 0 ; i < rowCount; i++){
        var rcv = excel.cell(i, 1).value()
        var rcn = excel.cell(i, 0).value()
        if (rcv == no){
            Win.tips.setText(rcn)
        }
    }
    excel.close()
    Win.submit.setEnable(true);
}

Win.loop()

解释器:「链接」

开发套件:https://gitee.com/javaup/bx-script-ide

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表