ankane / secure-spreadsheet Goto Github PK
View Code? Open in Web Editor NEWEncrypt and password protect sensitive CSV and XLSX files
License: MIT License
Encrypt and password protect sensitive CSV and XLSX files
License: MIT License
Hello everyone.
I'm getting this error while generatin an 12k rows XLSX.
(node:6042) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'children' of undefined at Cell._parseNode (/nix/store/6i3kkqyrhwd225yxcxqybd2mv6f9rf2z-nodejs-module-secure-spreadsheet/node_modules/xlsx-populate/lib/Cell.js:608:24) at Cell._init (/nix/store/6i3kkqyrhwd225yxcxqybd2mv6f9rf2z-nodejs-module-secure-spreadsheet/node_modules/xlsx-populate/lib/Cell.js:541:18) at new Cell (/nix/store/6i3kkqyrhwd225yxcxqybd2mv6f9rf2z-nodejs-module-secure-spreadsheet/node_modules/xlsx-populate/lib/Cell.js:24:14) at _node.children.forEach.cellNode (/nix/store/6i3kkqyrhwd225yxcxqybd2mv6f9rf2z-nodejs-module-secure-spreadsheet/node_modules/xlsx-populate/lib/Row.js:352:26) at Array.forEach (<anonymous>) at Row._init (/nix/store/6i3kkqyrhwd225yxcxqybd2mv6f9rf2z-nodejs-module-secure-spreadsheet/node_modules/xlsx-populate/lib/Row.js:351:29) at new Row (/nix/store/6i3kkqyrhwd225yxcxqybd2mv6f9rf2z-nodejs-module-secure-spreadsheet/node_modules/xlsx-populate/lib/Row.js:20:14) at _sheetDataNode.children.forEach.rowNode (/nix/store/6i3kkqyrhwd225yxcxqybd2mv6f9rf2z-nodejs-module-secure-spreadsheet/node_modules/xlsx-populate/lib/Sheet.js:1381:25) at Array.forEach (<anonymous>) at Sheet._init (/nix/store/6i3kkqyrhwd225yxcxqybd2mv6f9rf2z-nodejs-module-secure-spreadsheet/node_modules/xlsx-populate/lib/Sheet.js:1380:38) (node:6042) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:6042) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
This just happens with this kind of 'huge' XLSX files. For example, for those with 8k lines there's no problem.
Thanks in advance for any help.
Hi,
I am trying to use secure-spreadsheet with my PHP scripts to encrypt an excel sheet,
when using the secure-spreadsheet as a command in cmd it works correctly,
secure-spreadsheet --password password < C:\wamp64\www\test.csv > C:\wamp64\www\test.xlsx
but when using PHP script it generates the file, but it can't open as the following image:
this the PHP script:
$infilepath = 'C:\wamp64\www\test.csv'; $outfilepath = 'C:\wamp64\www\test.xlsx'; $encryptionPassword = 'password'; //$encryptCommand = "type $infilepath | secure-spreadsheet --password $encryptionPassword > $outfilepath"; $encryptCommand = "secure-spreadsheet --password $encryptionPassword < $infilepath > $outfilepath"; exec($encryptCommand); //system($encryptCommand);
I will be appreciated for any guides to work around this issue.
Hello,
Would you be able to add XLSM support to this project? I forked your code a few weeks ago to add it, and it has been working fine. There are no additional changes needed other than checking for 'xlsm' in addition to 'xlsx' in this line of src/cli.js:
if (options.inputFormat == "xlsx") {
With the new release of 'csv-parse' the module stopped working with the error:
When trying to execute cli.js directly from the repository
(node:5984) ExperimentalWarning: The ESM module loader is experimental.
file:///C:/Dev/secure-spreadsheet/src/cli.js:5
import parse from 'csv-parse';
^^^^^
SyntaxError: The requested module 'csv-parse' does not provide an export named 'default'
at ModuleJob._instantiate (internal/modules/esm/module_job.js:97:21)
at async ModuleJob.run (internal/modules/esm/module_job.js:136:20)
at async Loader.import (internal/modules/esm/loader.js:179:24)
When using the installed module:
root@6929069cb676:/src/pkg/cryptography/encrypter# echo "var,value\ntemp,10\n" | secure-spreadsheet --password secret > output.xlsx
Error: parse is not a function
This is because 16 hours before csv-parse published a mayor upgrade 5.0.1. That is not compatible anymore.
I propose to fix the dependencies version with ^
in order to prevent the module to update a mayor and possible not compatible version of the dependancies.
Hello,
Not sure if it would be out of scope for this project, but would you be able to change it so that the CLI commands allows you to just convert CSV to XLSX without a password.
I know this is a secure spreadsheet package, however I would have expected if the --password option was left out, it would have just directly converted the document. However it generates a 0kb XLSX file.
First of all, thank you for the library.
I was using secure-spreadsheet
for xlsx encryption with Python.
Everything worked fine until I came across Error: program.option is not a function
in this February.
After a research I found commander.js, which is one of the dependencies of secure-spreadsheet, has been updated to v12 on February 3rd.
This update introduces several breaking changes including
- Breaking: Commander 12 requires Node.js v18 or higher
- Breaking: removed default export of a global Command instance from CommonJS
https://github.com/tj/commander.js/releases/tag/v12.0.0
Since secure-spreadsheet
currently install commander v.12, this library is also affected by this.
"commander": ">=7",
Now in src/cli.js
there is default import of program
.
const program = require('commander');
[...]
program
.option('--password <password>', 'Password')
.option('--input-format <format>', 'Input format')
.parse(process.argv);
Line 5 in 4924b86
One solution is to specify commander.js version, namely
- "commander": ">=7",
+ "commander": ">=7.0.0 <12.0.0",
It's relatively safe, but obvious drawback is this library is pegged to under v12.
Another is to rewrite default import as stated in commander.js docs.
https://github.com/tj/commander.js/blob/master/docs/deprecated.md#default-import-of-global-command-object
- const program = require('commander');
+ const { program } = require('commander');
I tried the second fix on my local and tested as private package, and it seems to work as before.
But I am not sure about backward compatibilities.
I appreciate if @ankane confirm this problem and solution.
Lastly here's sample code in question.
def encrypt_file(input_file_path, output_file_path, password):
cat_process = subprocess.Popen(["cat", input_file_path], stdout=subprocess.PIPE)
secure_spreadsheet_process = subprocess.Popen(
["secure-spreadsheet", "--password", password, "--input-format", "xlsx"],
stdin=cat_process.stdout,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
with open(output_file_path, "wb") as f:
while True:
data = secure_spreadsheet_process.stdout.read(1024)
if not data:
break
f.write(data)
cat_process.wait()
secure_spreadsheet_process.wait()
stdout, stderr = secure_spreadsheet_process.communicate()
if stderr:
print("Error:", stderr.decode()) # Error: program.option is not a function
I was run below script ( save xlsx bytes to BytesIO and use it for input )
import pandas as pd
from subprocess import check_output
from io import BytesIO
df = pd.read_csv("SalesJan2009.csv")
bio = BytesIO()
with pd.ExcelWriter(bio,'openpyxl') as xlw:
df.to_excel(xlw, sheet_name="yallacha")
print(check_output(args=['secure-spreadsheet','--password','sectet','--input-format','xlsx'],input=bio.getvalue()))
and I have got error below. and got exception "subprocess.CalledProcessError"
+) When I change pd.ExcelWriter's engine to xlsxwiter, secure-spreadsheet works correctly. but when engine of pd.ExcelWriter id "openpyxl", secure-spreadsheet does not works
When I try to create I get the following error.
internal/modules/cjs/loader.js:1216
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /root/.nvm/versions/node/v14.4.0/lib/node_modules/secure-spreadsheet/node_modules/get-stdin/index.js
require() of ES modules is not supported.
require() of /root/.nvm/versions/node/v14.4.0/lib/node_modules/secure-spreadsheet/node_modules/get-stdin/index.js from /root/.nvm/versions/node/v14.4.0/lib/node_modules/secure-spreadsheet/src/cli.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /root/.nvm/versions/node/v14.4.0/lib/node_modules/secure-spreadsheet/node_modules/get-stdin/package.json.
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1216:13)
at Module.load (internal/modules/cjs/loader.js:1049:32)
at Function.Module._load (internal/modules/cjs/loader.js:937:14)
at Module.require (internal/modules/cjs/loader.js:1089:19)
at require (internal/modules/cjs/helpers.js:73:18)
at Object.<anonymous> (/root/.nvm/versions/node/v14.4.0/lib/node_modules/secure-spreadsheet/src/cli.js:4:18)
at Module._compile (internal/modules/cjs/loader.js:1200:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
at Module.load (internal/modules/cjs/loader.js:1049:32)
at Function.Module._load (internal/modules/cjs/loader.js:937:14) {
code: 'ERR_REQUIRE_ESM'
}
Running the following command produces an empty excel file when using the attached .csv file.
secure-spreadsheet --password 123 < ../tmp/dayzz_leads.csv > ../tmp/dayzz_leads.xlsx
I am on MacOS 10.15.7 using [email protected]
on [email protected]
This also happened on an older versions and newer versions of node.
Encrypting a simple file with just a,b
works fine.
Input: dayzz_leads.csv.txt (had to add .txt extension since github does not allow csv files).
Output: dayzz_leads.xlsx
Thanks
Hi i tried the the ruby code in the documentation. the "output.xlsx" file created to my project file. is this possible to trigger on the browser? for example the user click the button and then the "output.xlsx(with password)" file will downloaded?
The blank file is created when the service is run with cronjob. I couldn't find the reason.
Hello,
I am facing issue while trying to run the secure-spreadsheet codes through Crontab/Cronjobs. I've created both the version of the codes, i.e. PHP and Python to test the issue.
My python file contains below code
#!/usr/bin/env python3.6
import subprocess
csv_str = b'awesome,csv'
result = subprocess.check_output(['/usr/local/bin/secure-spreadsheet', '--password', 'secret'], input=csv_str)
with open('output.xlsx', 'wb') as f:
f.write(result)
My PHP file contains below code
<?php
$csv_str = "this,is,a,test";
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w")
);
$process = proc_open("/usr/local/bin/secure-spreadsheet --password secret", $descriptorspec, $pipes);
if (is_resource($process)) {
fwrite($pipes[0], $csv_str);
fclose($pipes[0]);
$result = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$return_value = proc_close($process);
if ($return_value != 0) {
die("Command failed");
}
}
$file = fopen("output.xlsx", "w") or die("Unable to open file!");
fwrite($file, $result);
fclose($file);
Though I am able to simply run the below commands straight by logging in via SSH into server, and it generates the XLSX files successfully, it doesn't work when I am trying to run both the files through cronjobs.
python test.py
php test.php
I've setup below crontabs
# m h dom mon dow command
10 17 * * * /usr/bin/php /home/ubuntu/xxxx.com/wp-content/plugins/xxxx/tmp/test.php >> /home/ubuntu/xxxx.com/wp-content/plugins/xxxx-automated-registration-data-share/tmp/log.log 2>&1
07 17 * * * /usr/bin/python3.6 /home/ubuntu/xxxx.com/wp-content/plugins/xxxx-automated-registration-data-share/tmp/test.py >> /home/ubuntu/xxxx.com/wp-content/plugins/xxxx-automated-registration-data-share/tmp/log.log 2>&1
When the cronjobs are done running, it returns below output, in both the cases, i.e. PHP and Python:
/usr/local/lib/node_modules/secure-spreadsheet/node_modules/get-stdin/index.js:13
for await (const chunk of stdin) {
^^^^^
SyntaxError: Unexpected reserved word
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/usr/local/lib/node_modules/secure-spreadsheet/src/cli.js:4:18)
Command failed
Please let me know how to proceed further. My agenda is to simply generate the password protected excel sheet.
Thanks,
Jay.
I have installed library in my local system. After that I tried to run secure-spreadsheet command but it didn't found. can anyone help to fix it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.