将一段python代码用aardio实现,看看区别

光庆 2023-7-28 1198

代码功能

检测一个目录下的所有.xlsx文件,将每个表、每个单元格中,包含全角空格或全角符号的,都列出来。

python代码(网友提供,未经本人测试):

var pycode = /***
def check_isfullwidth(dirname):
    con = ["检查结束"]
    # 便利指定路径下,所有文件的格式内容
    if dirname:
        os.chdir(dirname)
        path = os.walk(dirname)
        for dirpath, dirnames, filenames in path:
            if filenames:
                for filename in filenames:
                    if os.path.splitext(filename)[1] == ".xlsx":
                        workbook = openpyxl.load_workbook(filename)
                        for sheetname in workbook.sheetnames:
                            worksheet = workbook[sheetname]
                            for row in worksheet.iter_rows():
                                for cell in row:
                                    for uchar in str(cell.value):
                                        inside_code = ord(uchar)
                                        # 全角空格
                                        if inside_code == 12288:
                                            strins = uchar + '全角空格' + f"in {filename} of {worksheet} at {cell.coordinate}"
                                            con.append(strins)
                                        # 全角字符(除空格)根据关系转化
                                        elif 65281 <= inside_code <= 65374:
                                            strinsk = uchar + '全角字符' + f"in {filename} of {worksheet} at {cell.coordinate}"
                                            con.append(strinsk)
    return con
***/
import console;
import py3;  
py3.exec(pycode);
console.dump(py3.main.check_isfullwidth("C:\Users\Administrator\Desktop\"));
console.pause();
 
aardio代码
import console;
var check_isfullwidth = function(dirname){
	import fsys;
	import godking.libxl;
	var con = {};
	var list = fsys.list(dirname,"xlsx");
	for(i=1;#list;1){
		var workbook = godking.libxl.open(list[list[i]]);
		for(i=1;workbook.getSheetCount();1){
			var worksheet = workbook.sheet(i);
			for(row=worksheet.firstFilledRow;worksheet.lastFilledRow;1){
				for(col=worksheet.firstFilledCol;worksheet.lastFilledCol;1){
					var str = worksheet.getCellStr(row,col):"";
					for(n=1;..string.len(str);1){
						var char,code = ..string.charAt(str,n),string.charCodeAt(str,n);
						if code==12288 {
							..table.push(con, char + '全角空格' + ..string.format("in %s of %s at %s",list[list[i]],worksheet.name,worksheet.addr(row,col)));
						} elseif (code>=65281 and code<=65374) {
							..table.push(con, char + '全角字符' + ..string.format("in %s of %s at %s",list[list[i]],worksheet.name,worksheet.addr(row,col)));
						}
					}
				}
			}
		}
	}
	return con; 
}
console.dump(check_isfullwidth("C:\Users\Administrator\Desktop\"));
console.pause();

运行效果


最新回复 (6)
  • lcj21 2023-7-31
    0 2
    感谢分享,学习了!
  • tanzh 2023-7-31
    0 3
    学习了
  • lerh 2023-8-4
    0 4
    感谢分享
  • lhzhygxy 2023-8-4
    0 5
    大佬,有没有比较下性能
  • 光庆 2023-8-4
    0 6
    没有。python的我没测试,只是根据代码,用aardio实现了。
  • 光庆 2023-8-4
    0 7
    此楼层已删除
返回