【Photoshop JS脚本】jsx如何操作excel
jsx需要借助js开源库来操作excel。github地址:SheetJS
可能你会奇怪这是这是浏览器JS操作excel,并不能用于Photoshop。你只要找到xlsx.extendscript.js 这个文件就可以了。
演示下载:https://download.csdn.net/download/greless/13086810
/*Greless*/
var thisFile = new File($.fileName);
var basePath = thisFile.path;
#include "xlsx.extendscript.js";
var filename = "/sheetjs.xlsx";
/* 读取workbook */
var workbook = XLSX.readFile(basePath + filename, {cellDates:true});
/* 读取worksheet */
var first_sheet_name = workbook.SheetNames[0];
var first_worksheet = workbook.Sheets[first_sheet_name];
var data = XLSX.utils.sheet_to_json(first_worksheet, {header:"A"});
alert(data[1].D);// 第二行D列的数据
// 以下为反射用法
reflectProps(first_worksheet);
reflectMeths(first_worksheet);
reflectProps(data[3]);
reflectMeths(data[3]);
/*************************************************************************/
function reflectProps(obj) {
var props = obj.reflect.properties;
for (var i = 0, len = props.length; i < len; i++) {
try {
$.writeln(props[i].name + ' = ' + obj[props[i].name]);
WriteData(props[i].name + ' = ' + obj[props[i].name])
} catch (e) {}
}
}
function reflectMeths(obj) {
var meths = obj.reflect.methods;
for (var i = 0, len = meths.length; i < len; i++) {
try {
$.writeln(meths[i].name + '();');
WriteData(meths[i].name + '();')
} catch (e) {}
}
}
function WriteData(Txt)
{
var file = new File(Folder.desktop + "/rflection.txt");
file.open("a", "TEXT",null);
file.encoding = "UTF8";
file.seek(0,2);
$.os.search(/windows/i) != -1 ? file.lineFeed = 'windows' : file.lineFeed = 'macintosh';
file.writeln(Txt);
file.close();
}
赞 (0)