LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Can you echo results to an excel file (https://www.linuxquestions.org/questions/programming-9/can-you-echo-results-to-an-excel-file-4175436296/)

graphicsmanx1 11-08-2012 01:06 PM

Can you echo results to an excel file
 
I realized I could print results to a .csv but I wanted to know if I could print results to certain columns and rows I assign. I thought that would be something fun to learn.

schneidz 11-08-2012 01:34 PM

look into awk for any column parsing functionality.

also supposedly there are some perl utilities out there that can convert .csv files into binary coompatable .xcl ms-excel formatted files.

markush 11-08-2012 04:37 PM

I agree with schneidz, it could be easily done with Perl, probably it would be good if you posted an example-file and explain your problem in more detail.

Markus

graphicsmanx1 11-09-2012 08:34 AM

well I thought it would be cool if I echoed items and could place them columns and rows in excel. Not long ago I started learning how to use imagemagick and some its features. I started setting thing as variables and I thought it would be fun to learn how to set each variable in a column and start a new row. I dont really have anything just something I wanted to learn.

markush 11-09-2012 08:47 AM

Well, I think independent from the language or command you use, the way to put data into a csv-file will always be, to split the line and putting the data into a list. As an example (Perl-code), when the delimiter in the lines is a ";"
Code:

my @data = split /;/, $line ;
afterwards @data (an Array) holds the data of the fields between the ";"
Now one could substitute (or set) the data
Code:

$data[3]="my new data" ;
would put the text "my new data" into the fourth field of the array.
and join the array to a string
Code:

$newline = join /;/, @data ;
There are also solutions possible with sed or awk.

Markus

graphicsmanx1 11-09-2012 09:40 AM

someone else also mentioned awk. Can you point where some good tutorials and reads would be for awk as well?

markush 11-09-2012 10:09 AM

There are several places in the internet with tutorials about bash and awk, take also a look at sed.

http://bashshell.net/stream-filterin...ng-awk-basics/
http://www.delorie.com/gnu/docs/gawk...l#SEC_Contents
http://tldp.org/LDP/abs/html/awk.html but here's also the whole tutorial (which actually is an advanced bash-guide) very valuable http://tldp.org/LDP/abs/html/

I learned sed with this tutorial http://www.grymoire.com/Unix/Sed.html

Maybe it would be useful to purchase a book, normally a good book about bash will also have chapters with awk and sed.

Markus

Wim Sturkenboom 11-09-2012 12:34 PM

A little off-topic. A csv-file is not the same as an excel-file ;)

markush 11-09-2012 12:37 PM

Quote:

Originally Posted by Wim Sturkenboom (Post 4825967)
A little off-topic. A csv-file is not the same as an excel-file ;)

Yes, that's true, but Excel can open csv-files and one can also save an Excel-file as csv-file. I don't think that your post is off topic, id could have been mentioned earlier in this thread :)

Markus

schneidz 11-09-2012 12:55 PM

thats a good point... ascii (including .csv or .xml) is the most trans-portable format so dealing with .csv (which ms-excel can handle) is easier with trying to translate .xcl files into ascii without a gui.

i remember using a program that would transform open-office odf into ms-excel format (so you can do hundreds at a time) but i forget what it was called.

graphicsmanx1 11-09-2012 01:10 PM

Quote:

Originally Posted by markush (Post 4825878)
There are several places in the internet with tutorials about bash and awk, take also a look at sed.

http://bashshell.net/stream-filterin...ng-awk-basics/
http://www.delorie.com/gnu/docs/gawk...l#SEC_Contents
http://tldp.org/LDP/abs/html/awk.html but here's also the whole tutorial (which actually is an advanced bash-guide) very valuable http://tldp.org/LDP/abs/html/

I learned sed with this tutorial http://www.grymoire.com/Unix/Sed.html

Maybe it would be useful to purchase a book, normally a good book about bash will also have chapters with awk and sed.

Markus

Ive looked for good books but didnt find anything worth wild

Wim Sturkenboom 11-09-2012 10:09 PM

Quote:

Originally Posted by graphicsmanx1 (Post 4825991)
Ive looked for good books but didnt find anything worth wild

sed & awk is in my cupboard ;)

AnanthaP 11-10-2012 08:13 PM

See, excel has its own proprietary format. So you need specific modules to post your data into excel format and that includes specific rows and columns.

I believe that perl has just such modules. awk as such doesn't have the functionality that you need.

OK

catkin 11-10-2012 08:45 PM

How about a script to
  1. Write a LibreOffice macro to populate the cells.
  2. Start LibreOffice with a command that opens the Excel file and runs the macro.
If you don't want the Excel file left open, the macro could also save and exit.

If you don't want to see the Excel file on screen, you could start LibreOffice headless.

schneidz 11-14-2012 11:20 PM

i see this. not sure if it goes the other way:
Code:

xlhtml.x86_64 : Excel 95/97 and PowerPoint to HTML converter

bama90 11-15-2012 03:42 AM

I thinks probably it would be good if you posted an example-file and explain your problem in more detail.

graphicsmanx1 11-15-2012 02:52 PM

actually this doesnt work too bad. I was playing around and it worked for A code I made for fun:

Code:

echo $variable,$variable,$variable >> file.csv
each column was printed to what I set for the variable. I made a script to log what I ran through some other scripts I learned from here:

Code:

name=$(basename $target)
day=$(date +%Y-%m-%d)
point=$(date +%H:%M:%S)
echo $name,$day,$point >> results.csv


AnanthaP 11-15-2012 07:03 PM

file.csv is actually a TEXT file containing comma separated values. IT DOESN'T STORE DATA ABOUT THE DESTINATION FILE'S ROWS AND COLUMNS.

Microsoft and indeed most other spreadsheet programs(like open office and libre office) provide a way to open the data so that it can be used like a spreadsheet.

OK

graphicsmanx1 11-16-2012 03:48 PM

Quote:

Originally Posted by AnanthaP (Post 4830427)
file.csv is actually a TEXT file containing comma separated values. IT DOESN'T STORE DATA ABOUT THE DESTINATION FILE'S ROWS AND COLUMNS.

Microsoft and indeed most other spreadsheet programs(like open office and libre office) provide a way to open the data so that it can be used like a spreadsheet.

OK

yes thanks I am aware of that. All Im stating is that this is something that works for csv

AnanthaP 11-19-2012 04:09 AM

The original discussion was about excel and whether csv files can have row and column ids embedded in them.
Quote:

I wanted to know if I could print results to certain columns and rows I assign.
This was your original problem.

I am concerned that that this default opening of csv files by msexcel has led to a general dumbing down of knowledge about file formats so that people dont know that CSV is a plain human readable format and we can use many command line utilities that predate msexcel (like awk and sed) to to open and interpret the contents.

Even in your redirection example (post #17 in this thread), the destination row and column numbers cant be stored in the csv file.

If you open your spreadsheet and position the cursor in any arbitrary cell say cell "b25", say and import the data by pasting, it will be imported into cell b25 onwards. You are not assigning the desired cell in the csv file.

OK

catkin 11-19-2012 08:17 AM

graphicsmanx1, did you consider AnanthaP's suggestion to look for perl modules that are capable of working with Excel's proprietary format or my suggestion to use LibreOffice's facilities to do the same? Or are you happy to use the CSV route?

graphicsmanx1 11-19-2012 08:52 AM

I like the CSV but I will learn the proper way to do it. Many good ideas

grizzlysmit 11-20-2012 02:49 AM

Perl can do this as can Python try xlwt if you go the python root not sure in perl but CPAN will have it


All times are GMT -5. The time now is 10:23 AM.