当前位置: 首页 > news >正文

aardio 读取 Excel文件,显示在 listview 中

编写 main.aardio 如下

import win.ui;
/*DSG{{*/
winform = win.form(text="excel1";right=801;bottom=500)
winform.add(
button1={cls="button";text="读取Excel文件";left=19;top=14;right=126;bottom=44;z=1};
button2={cls="button";text="导出Excel文件";left=168;top=17;right=291;bottom=45;z=3};
listview={cls="listview";left=2;top=62;right=801;bottom=498;edge=1;gridLines=1;hscroll=1;vscroll=1;z=2}
)
/*}}*/import io;
import sys;
import fsys.dlg;
import win.ui.grid;
win.ui.grid(winform.listview);import console;
import com.excel;console.showLoading(" 正在启动 Excel ");
var excel,err = com.excel(); 
assert(excel,err);excel.alerts = false; //关闭界面提示与屏幕更新
excel.Visible = false;// 读取Excel文件
winform.button1.oncommand = function(id,event){winform.button1.disabled = true;var xls = fsys.dlg.open("*.xls|*.xlsx");if (!io.exist(xls)){winform.msgbox(xls+" not exists.");winform.button1.disabled = false;return ;}winform.listview.clear();try{// 读取.xls 或 .xlsxvar book = excel.Open(xls);		var sheet = book.Sheets(1);var rows = sheet.UsedRange.Rows.count;console.log("rows=",rows)var cols = sheet.UsedRange.Columns.Count;console.log("cols=",cols)var fields = {};for	(j=1; cols; 1){v = sheet.Cells(1, j).value;if (type(v) == type.string) table.push(fields, v);elseif (type(v) == type.number){if (v == math.modf(v)) table.push(fields, string.format("%d",v));else table.push(fields, string.format("%.4f",v));}  // date 字段格式化elseif (type(v) == type.table) table.push(fields, string.left(tostring(v),10));elseif (type(v) == type.null) table.push(fields, ''); else table.push(fields, type(v)); }//console.dump(fields);winform.listview.setColumns(fields);for (i=2; rows; 1){if (i >100) break;values = {};for (j=1; cols; 1){v = sheet.Cells(i, j).value;if (type(v) == type.string) table.push(values, v);elseif (type(v) == type.number){if (v == math.modf(v)) table.push(values, string.format("%d",v));else table.push(values, string.format("%.4f",v));}  // date 字段格式化elseif (type(v) == type.table) table.push(values, string.left(tostring(v),10));elseif (type(v) == type.null) table.push(values, '');else table.push(values, type(v));}//console.dump(values);winform.listview.addItem(values);}	book.close();}catch(e){winform.msgbox(e)}	winform.button1.disabled = false;	
}// 鼠标左键点击事件
winform.listview.onClick = function(item,subItem,nmListView){//var index = winform.listview.selIndex; //选择的行
}
// 鼠标双击修改事件
winform.listview.onEditChanged = function(text,iItem,iSubItem){winform.msgbox(string.join({iItem,iSubItem,text},",")); //修改成功
}
// 鼠标右键事件
winform.listview.onRightClick = function(item,subItem,nmListView){var v = winform.listview.getItemText(item,subItem); //取值winform.msgbox(string.join({item,subItem,v},",")); //显示行、列、值信息
}// 导出Excel文件
winform.button2.oncommand = function(id,event){}winform.show();
return win.loopMessage();
excel.Quit();

参考:aardio开发语言Excel数据表读取修改保存实例练习

import godking.libxl; 在 蓝奏云 下载 libxl.rar 密码:123

解压缩将文件放于:aardio\lib\godking\ ,先要 cd lib; mkdir godking

http://www.lryc.cn/news/184536.html

相关文章:

  • Web:前端常用的几种Http请求GET和POST样例
  • clickonce 发布的winform 如何CA认证?
  • #力扣:13. 罗马数字转整数@FDDLC
  • React18入门(第一篇)——JSX、TSX语法详解
  • 【计算机基础知识】字符的编码表示
  • 【面试题精讲】Java字符型常量和字符串常量的区别?
  • 【Vue面试题六】为什么Vue中的 v-if 和 v-for 不建议一起用?
  • leetCode 674. 最长连续递增序列 动态规划 / 贪心策略
  • 数据中台实战(11)-数据中台的数据安全解决方案
  • 林沛满-TCP之在途字节数
  • HTTPS 加密工作过程
  • 校招秋招,性格和职业有关系吗?
  • 网络和系统操作命令
  • 刷穿力扣(1~30)
  • 栈和队列的基本操作
  • 变压器绕组断股往往导致直流电阻不平衡率超标
  • stack和queque
  • 信息学 学习/复习 抽签器(附源码)
  • 基于LADRC自抗扰控制的VSG三相逆变器预同步并网控制策略(Simulink仿真实现)
  • [0xGame 2023] week1
  • Matlab矩阵——矩阵行列互换
  • OpenMesh 网格面片随机赋色
  • SpringSecurity源码学习一:过滤器执行原理
  • 8.2 JUC - 4.Semaphore
  • 前端try和catch
  • Unity可视化Shader工具ASE介绍——2、ASE的Shader创建和输入输出
  • 目标检测算法改进系列之Backbone替换为Swin Transformer
  • 【技术干货】如何通过 DP 实现支持经典蓝牙的联网单品设备与 App 配对
  • 【Unity Build-In管线的SurfaceShader剖析_PBS光照函数】
  • thinkphp5实现ajax图片上传,压缩保存到服务器