LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Can you echo results to an excel file (http://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


All times are GMT -5. The time now is 01:27 AM.