LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-12-2009, 09:44 AM   #1
sumitdevbharadwaj
LQ Newbie
 
Registered: Nov 2008
Posts: 20

Rep: Reputation: 0
Thumbs up Convert a Unix file to .xls format.


Hi, I have one doubt. How can I convert a file in unix to MS excel format.
Suppose if I have a file named 'Studata' and it contains like:

/root # cat Studata
Roll no. Name Age Sex
1 ABC 12 M
2 DEF 13 M
3 XYZ 12 F

I want this table to be converted to .xls format and to be saved on my local server. I have perl script but I dont know perl so I want the code in shell scripting.
Is it possible? If yes, can anybody please help me out as how can this be achieved.
Thanks in advance.

Warm regards
Sumit Dev Bharadwaj
 
Old 04-12-2009, 10:26 AM   #2
amani
Senior Member
 
Registered: Jul 2006
Location: Kolkata, India
Distribution: Debian 64-bit GNU/Linux, Kubuntu64, Fedora QA, Slackware,
Posts: 2,766

Rep: Reputation: Disabled
Use Gnumeric or OOcalc
 
Old 04-12-2009, 10:39 AM   #3
IBall
Senior Member
 
Registered: Nov 2003
Location: Perth, Western Australia
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088

Rep: Reputation: 62
You could convert it into a .csv (Comma Separated Values), which will open by default in Excel and be displayed as a spreadsheet.

I doubt you could make a .xls - hell even Microsofts own .Net can't do that easily...

--Ian
 
Old 04-12-2009, 11:41 PM   #4
sumitdevbharadwaj
LQ Newbie
 
Registered: Nov 2008
Posts: 20

Original Poster
Rep: Reputation: 0
Thanks Ian.
 
Old 04-14-2009, 09:43 AM   #5
billybadfoot
LQ Newbie
 
Registered: Dec 2006
Location: UK
Distribution: Fedora
Posts: 8

Rep: Reputation: 1
Spreadsheets can be saved as xml in both MS Excel and in OpenOffice Calc. If you store the following with a .xml extension, and open it with Excel or OpenOffice, then you get it opening as a spreadsheet with the worksheet name set to Student Data. After opening it in Excel or OpenOffice, you can 'save as' in spreadsheet format.

Code:
<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns:x="urn:schemas-microsoft-com:office:excel"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:html="http://www.w3.org/TR/REC-html40">
 <Worksheet ss:Name="Student Data">
  <Table>
   <Row>
    <Cell><Data ss:Type="String">Roll No.</Data></Cell>
    <Cell><Data ss:Type="String">Name</Data></Cell>
    <Cell><Data ss:Type="String">Age</Data></Cell>
    <Cell><Data ss:Type="String">Sex</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="Number">1</Data></Cell>
    <Cell><Data ss:Type="String">ABC</Data></Cell>
    <Cell><Data ss:Type="Number">12</Data></Cell>
    <Cell><Data ss:Type="String">M</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="Number">2</Data></Cell>
    <Cell><Data ss:Type="String">DEF</Data></Cell>
    <Cell><Data ss:Type="Number">13</Data></Cell>
    <Cell><Data ss:Type="String">M</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="Number">3</Data></Cell>
    <Cell><Data ss:Type="String">XYZ</Data></Cell>
    <Cell><Data ss:Type="Number">12</Data></Cell>
    <Cell><Data ss:Type="String">F</Data></Cell>
   </Row>
  </Table>
 </Worksheet>
</Workbook>
 
1 members found this post helpful.
Old 04-14-2009, 10:03 AM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by sumitdevbharadwaj View Post
How can I convert a file in unix to MS
change the spaces to commas then import from Excel
Code:
# awk '{$1=$1}1' OFS="," file
1,ABC,12,M
2,DEF,13,M
3,XYZ,12,F
another way, if you have Perl and can install the Spreadsheet::WriteExcel module
Code:
#!/usr/bin/perl

use Spreadsheet::WriteExcel;
my $workbook = Spreadsheet::WriteExcel->new("test.xls"); 
my $worksheet = $workbook->add_worksheet();
open(FH,"<file") or die "Cannot open file: $!\n";
my ($x,$y) = (0,0);
while (<FH>){ 
 chomp;
 @list = split /\s+/,$_;
 foreach my $c (@list){
    $worksheet->write($x, $y++, $c);     
 }
 $x++;$y=0;
}
close(FH);
$workbook->close();

Last edited by ghostdog74; 04-14-2009 at 10:19 AM.
 
Old 04-18-2009, 12:18 AM   #7
sumitdevbharadwaj
LQ Newbie
 
Registered: Nov 2008
Posts: 20

Original Poster
Rep: Reputation: 0
Hi Ghostdog74 and Billybadfoot,

Great ideas, I have used both of them and it really worked for me. Thanks in loads.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Odt File Convert To Odf Format DOUGLASdc6b Linux - Newbie 3 05-06-2008 07:27 AM
Is there a way to convert a PDF file to another format? M$ISBS General 10 05-09-2007 01:43 AM
Script to convert csv 2 xls or odt xowl Linux - Software 1 01-16-2007 09:06 PM
script to convert dos to unix format kapilcool Linux - Software 3 06-15-2006 11:50 AM
Command to convert dos file to a unix format sathish80 Linux - Newbie 1 03-22-2006 11:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration