2023-02-14 08:22:31 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
# ExecSheetJS.rb (c) SheetJS LLC -- https://sheetjs.com
|
|
|
|
require "execjs"
|
|
|
|
require "base64"
|
|
|
|
|
2023-09-25 07:30:54 +00:00
|
|
|
source = File.open("xlsx.full.min.js", "rb").read();
|
|
|
|
source.force_encoding("UTF-8");
|
2023-02-14 08:22:31 +00:00
|
|
|
context = ExecJS.compile(source);
|
|
|
|
puts context.eval("XLSX.version");
|
|
|
|
|
2023-09-25 07:30:54 +00:00
|
|
|
data = Base64.strict_encode64(File.open(ARGV[0], "rb").read);
|
2023-02-14 08:22:31 +00:00
|
|
|
result = context.call(<<EOF, data);
|
|
|
|
function(data) {
|
|
|
|
var wb = XLSX.read(data, {type: 'base64'});
|
|
|
|
var ws = wb.Sheets[wb.SheetNames[0]];
|
|
|
|
/* to avoid re-parsing, CSV and XLSB are written in the same call */
|
|
|
|
return [
|
|
|
|
XLSX.utils.sheet_to_csv(ws),
|
|
|
|
XLSX.write(wb, {bookType: "xlsb", type: "base64"})
|
|
|
|
];
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
puts result[0];
|
|
|
|
xlsb = Base64.strict_decode64(result[1]);
|
|
|
|
File.write("sheetjsw.xlsb", xlsb, mode: "wb");
|