How to convert Text data to xls?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to convert Text data to xls?
# 8  
Old 08-07-2014
IMHO only excel can create excel files... a xls contains more that just data... It has info on how the spreadsheet is structured etc...
# 9  
Old 08-07-2014
You can also add comma delimiters between columns and write to csv file. Then open csv file in Excel. Note you will need to choose another delimiter if the data could have embedded commas. Here is an example:

Code:
SELECT  
COLUMN1, CHAR(','),
COLUMN2, CHAR(','),
COLUMN3, CHAR(','),
COLUMN4
FROM   TABLE

This User Gave Thanks to mjf For This Post:
# 10  
Old 08-07-2014
Why not a python or perl script using one of John Mcnamara's modules. Google search python csv to xlsx mcnamara turns up his GIT repository as the top result.
# 11  
Old 08-07-2014
Have look a this thread where I suggest an awk script in combination with a template file to produce an "XML Spreadsheet 2003" from CSV file(s). Excel can open these XML files directly as if they were spreadsheets.

Would this sort of approach be acceptable?

If so we could tailor this approach for your particular problem.
This User Gave Thanks to Chubler_XL For This Post:
# 12  
Old 08-12-2014
Quote:
Originally Posted by mjf
You can also add comma delimiters between columns and write to csv file. Then open csv file in Excel. Note you will need to choose another delimiter if the data could have embedded commas. Here is an example:

Code:
SELECT  
COLUMN1, CHAR(','),
COLUMN2, CHAR(','),
COLUMN3, CHAR(','),
COLUMN4
FROM   TABLE

Thanks this is almost perfect, but it is causing the Column header row to appear as Column1 2 Column 4 Column 3 6 and all these are not getting separated into different columns. How do i correct this.
# 13  
Old 08-12-2014
You can try something like this to create a formated header record:

Code:
SELECT 
   'COLUMN1,' 
   'COLUMN2,' 
   'COLUMN3,' 
   'COLUMN4' 
FROM 
   SYSIBM.SYSDUMMY1
UNION
SELECT  
   COLUMN1, CHAR(','),
   COLUMN2, CHAR(','),
   COLUMN3, CHAR(','),
   COLUMN4
FROM
   TABLE

# 14  
Old 08-16-2014
Perl code to convert txt file to xls file

You may use Data::Table::Excel, a Perl module, to automate the conversion process. The following example show how to use:

Code:
#!/usr/bin/env perl

use strict;
use warnings;

use Text::CSV;
use Data::Table::Excel qw(tables2xls);

my $csv = Text::CSV->new({binary => 1, eol => "\n"}) or die "$!\n";

my @table_names;
for my $file (@ARGV) {
    my $csv_file = $file;
    $csv_file =~ s/\.txt/.csv/;
    push @table_names, $csv_file;

    open my $FH_TXT, "<", $file or die "$!\n";
    open my $FH_CSV, ">", $csv_file or die "$!\n";

    while (my $line=<$FH_TXT>) {
    my @cols = split /\s+/, $line;
    $csv->print($FH_CSV, \@cols);
    }

    close $FH_TXT or die "$!\n";
    close $FH_CSV or die "$!\n";
}

my $xls_file = "output.xls";

my @tables;
for my $name (@table_names) {
    my $table = Data::Table::fromFile($name);
    push @tables, $table;
}

my @portraits = map { 1 } @tables;
my @column_headers = map { 0 } @tables;
tables2xls($xls_file, \@tables, undef, undef, \@portraits, \@column_headers);

Save the file to convert.pl or other name. To use the script, remove the long dash line in txt; then do this:

Code:
$ convert.pl record01.txt record02.txt ...

All txt file will be saved to one xls file with each txt file in a seperated sheet.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Convert Excel File (xls) to tab delimited text file on AIX

Hi i have a problem in my job i try to convert an excel file (xls extention) to text file (tab delimited), but no result with this comand cat xxx.xls > xxx.txt Do you have eny idea? PS: sorry for my english Thanks!! (4 Replies)
Discussion started by: frisso
4 Replies

2. Shell Programming and Scripting

Perl script to convert xlsx to xls file

Hi I am trying one perl script to convert xlsx to xls file but could not able to get all the rows and columns in the xls file . This scriptFILE is basically to convert XLSX to CSV .. I am tweaking the script to convert XLSX to XLS file also #######################FILE... (3 Replies)
Discussion started by: kshitij
3 Replies

3. Shell Programming and Scripting

Converting text files to xls through awk script for specific data format

Dear Friends, I am in urgent need for awk/sed/sh script for converting a specific data format (.txt) to .xls. The input is as follows: >gi|1234|ref| Query = 1 - 65, Target = 1677 - 1733 Score = 8.38, E = 0.6529, P = 0.0001513, GC = 46 fd sdfsdfsdfsdf fsdfdsfdfdfdfdfdf... (6 Replies)
Discussion started by: Amit1
6 Replies

4. Shell Programming and Scripting

How to convert Excel Files to Xls?

Hi All, I have created a BI Publisher report in Oracle apps R12. It has generated the output with *.EXCEL file extension. I have a shell script to mail this output. in my shell script I have copied this file and saved as *.xls file. But the R12 generated *.EXCEL file is not a real excel... (5 Replies)
Discussion started by: kalidoss
5 Replies

5. Shell Programming and Scripting

How to convert a xls file to csv?

Hi, My requirement is to convert the xls to csv file with utf-8 conversion. Is there any way please suggest me. Thanks, Raja (4 Replies)
Discussion started by: cnraja
4 Replies

6. UNIX and Linux Applications

Tool for Convert XLS into CSV in UNIX

Hi I wanted to convert some XLS files into CSV format in my UNIX box. Unix box is handling very important data which are related to data warehouse.It is fully optimized by installing minimum packages since server need more resources to handle reports generating. Just for convert XLS files... (6 Replies)
Discussion started by: luke_devon
6 Replies

7. Shell Programming and Scripting

how to convert .xls to .csv

Hi, I have problem..How to convert .xls file to .csv.. Plz help me for this problem.. (1 Reply)
Discussion started by: varma457
1 Replies

8. Shell Programming and Scripting

Shell convert xls to csv

Hi does anybody know how to convert xls to csv undex linux. I need only data (that is log from test, dont need any macro and so on) from xls. Any idea how to do that? Perl? shell? Could you give me any example? Thanks in advance for answer. Gracjan (4 Replies)
Discussion started by: Gracjan
4 Replies

9. Shell Programming and Scripting

Convert a csv file to an xls format

Hi, I have a file coming in xxx.txt(csv format) i do some work on it and i need to send out as a .xls format. Is there any way there is some code i can use in my script to convert this? I'm struggling on this. Thanks (11 Replies)
Discussion started by: Pablo_beezo
11 Replies

10. Programming

trying to convert binary data to text using C++

i hav tried to convert binary 2D data into text using binreader and writing into text file using streamwriter. i use ReadSingle() function to convert from binary to ascii, although it works good in 1D data but not in more dimensions. the kind of values i get are -1.265369923E+038 and like ... (2 Replies)
Discussion started by: geet
2 Replies
Login or Register to Ask a Question