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

news/2025/3/4 7:29:33/

编写 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.ppmy.cn/news/1135887.html

相关文章

C++的继承基础和虚继承原理

1.继承概念 “继承”是面向对象语言的三大特性之一(封装、继承、多态)。 继承(inheritance)机制是面向对象程序设计使代码可以复用的最重要的手段,它允许程序员在保持原有类特性基础上进行扩展,增加功能&…

ROS(2)服务模型

服务模型 服务端 构建服务端和服务/turtle_command,当调用服务时,服务端回调函数反馈数据,并控制速度话题的发布 实现: call /turtle_command 调用服务回调数据发布控制速度话题 /cmd_vel,话题类型为geometry_msgs…

RabbitMQ-工作队列

接上文 RabbitMQ-死信队列 1 工作队列模式 xx模式只是一种设计思路,并不是指具体的某种实现,可理解为实现XX模式需要怎么去写业务代码。 之前的是简单的一个消费者一个生产者模式,下边是一个生产者多个消费者的情况: 这里先定义两…

QT 实现 TCP 客户端服务器代码

服务器 头文件&#xff1a; #ifndef WIDGET_H #define WIDGET_H#include <QWidget> #include<QTcpServer> //服务器头文件 #include<QTcpSocket> //客户端头文件 #include<QList> //链表容器 #include<Q…

miniOB笔记

一条SQL语句的处理过程 RC SessionStage::handle_sql(SQLStageEvent *sql_event) {RC rc query_cache_stage_.handle_request(sql_event);if (OB_FAIL(rc)) {LOG_TRACE("failed to do query cache. rc%s", strrc(rc));return rc;}// SQL语法分析 rc parse_stage_.…

TunnelSectionPaletteSet 2023/9/28 下午10:33:16

TunnelSectionPaletteSet 2023/9/28 下午10:33:16 TunnelSectionPaletteSet是一个术语,它可能指代在隧道设计或工程中使用的一种工具或系统。然而,由于缺乏具体的背景和上下文信息,我无法提供更详细的解释。如果您能够提供更多相关的信息或明确您的问题,我将尽力给予帮助…

族的概念理解

在数学和统计学中&#xff0c;“族”&#xff08;family&#xff09;是指一组具有某种共性或特定性质的数学对象的集合。这些数学对象可以是函数、集合、概率分布、曲线、矩阵等等。"族"的概念用于描述这些对象之间的关联或共同属性。 具体来说&#xff0c;"族…

一道求导题:1004T3

需要知识: ( x n ) ′ n x n − 1 (x^n)nx^{n-1} (xn)′nxn−1 ( s i n x ) ′ c o s x (sinx)cosx (sinx)′cosx [ f ( g ( x ) ) ] ′ f ′ ( g ( x ) ) g ′ ( x ) [f(g(x))]f(g(x))\times g(x) [f(g(x))]′f′(g(x))g′(x) 推完之后&#xff0c;考虑导函数与x轴的交点…