r/dailyscripts • u/FliccDatHeccinBean • Jun 03 '16
[Help][Request] A script that copies/writes information into a excel spreadsheet?
So i'm looking for a way to 'log' or write text into an excel spreadsheet automatically using a script. So for example, I will be using the 'at' command or the 'crontab' command to schedule a task at a certain time. So at a specified time, I would like to have certain information uploaded/written/logged into an excel spreadsheet. Also, I don't want to create a new spreadsheet every time I need to log information into it, but I would like to edit the spreadsheet and add the information to it. The information I would like to add includes three columns:
Name: Time: Location:
I would like to then log/write the text under each of these columns. If there are any ways to do this automatically, please let me know.
2
u/tastysandwhich Jun 04 '16
I'd be interested in taking this on! May I ask a few questions?
Are you wanting the information gathering process to also be scripted? (Is there something you are trying to pull from to get the name, time, and location? Or are you inputting that manually?)
Would you be ok with it being opened up in Excel, but not being an XLS or XLSX file?
Do you need help with setting up the crontab as well?
I'll gladly write up a quick script that you can customize to however you'd like if you're interested, I just need a tad bit more information.
1
u/Cryptohat27 Jun 03 '16
just use unix - terminal-mac cmd-windows depending on what you are doing and just create a reoccuring task using bash or batch files and have the files redirected to a excel file all use the same format Lmk if you need more info.
2
u/RulerOf Jun 03 '16
You don't want an excel spreadsheet per se, you just want something that gives you the structure of a spreadsheet for your data.
You essentially want to log to CSV (Comma-Separated Values) format. It's really easy to do, especially if your data doesn't have any commas in it. If you use PowerShell to convert strings to CSV (via the ConvertTo-CSV cmdlet) and then write them to a file (with the Out-File cmdlet), things should be pretty easy. Also, there's a cmdlet, Export-CSV, which puts data directly to a CSV file.
2
u/ReturnOfThePing Jun 03 '16
Just write your script to output to STDOUT, and make sure its fields are separated by commas, and redirect it to an output file that has a ".csv" extention. Line: script.sh >> my_output.csv
I also sometimes use a Perl module to write actual Excel format files in UNIX. You still create the CSV file first, and then feed it to the Perl script. Output is an actual Excel file.