Weird issue in converting XLSX to TXT


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Weird issue in converting XLSX to TXT
# 1  
Old 07-04-2013
Blade Weird issue in converting XLSX to TXT

Hi Guys,

I have used Perl scripting to convert XLSX file to TXT file using Perl module Spreadsheet::XLSX.

I processed one XLSX file having one column and 65k rows of data .

Strangely ,It is merging data for every 2047 row and I could see data in TXT file as Ex: Suppose in XLSX file ,if 2047 row data is A and 2048 row data is B .
In respective converted TXT file ,for 2047 row data is AB (merging 2047 +2048 data of XLSX ) which it should not print like this .it should print 2047 row as A and 2048 row as B in converted TXT file .

This is the same scenario for every 2047 records repetively in the same converted TXT file
At 4094 row in TXT - merging 4094 + 4095 data of XLSX
At 6141 row in TXT - merging 6141 + 6142 data of XLSX

So finally,comparing with XLSX file records and converted TXT file records of the above file(65K rows), Iam missing around 40 to 60 records/rows in TXT file.

I tried using changing the TXT file to UTF-8 format ,but no luck.

Could anyone please let me know solution to overcome this .
For refernece below is the Perl script used for conversion ,

Code:
#!/usr/bin/perl -w
#main.pl

use POSIX;

@files =<home/*.XLSX>;

foreach $file (@files)

 {
      print $file . "\n";

      use Spreadsheet::XLSX;
      my $excel   = Spreadsheet::XLSX -> new ($file);
      my $filename= $file.".".TXT;       
      print "filename is $filename\n";



        foreach my $sheet (@{$excel -> {Worksheet}})
       {

        $sheet -> {MaxRow} ||= $sheet -> {MinRow};
         foreach my $row ($sheet -> {MinRow} .. $sheet -> {MaxRow})
         {
           $sheet -> {MaxCol} ||= $sheet -> {MinCol};
             foreach my $col ($sheet -> {MinCol} ..  $sheet -> {MaxCol})
           {
              my $cell = $sheet -> {Cells} [$row] [$col];
     
                if ($cell)
               {        
                 open(FILE, ">>$filename") || die("Couldn't open file");
                 printf(FILE "%s\r",$cell -> {Val});
                 close(FILE);  
               }

             }
           }
         }
  }




Thanks,
Rajk
# 2  
Old 07-04-2013
I believe that \r should be an \n. Depending on how you view the file this may cause various problems.
# 3  
Old 07-04-2013
Hi ,
Thanks for the reply..
Tried that ,\n is giving the new line character for every record and avoding 2047 line issue. And also it is randomly giving blank records .More importantly, I should read this converted TXT file form other application .And that application doesn't entertains any new characters expect the records (data) parsed .

Thanks.Raj

---------- Post updated at 03:10 AM ---------- Previous update was at 01:30 AM ----------

Hi Every one ,

Looking for suggestions or any quick responses on this ..If any one have the idea upon the issue .
Or ANyone who has encountered and debugged this issue ..please respond..

Thanks,
Raj
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting String To Integer/Float (weird case)

Hi guys, I'm new here. I have a problem at work. One of our scripts was eventually having a bug and only detected recently. Here's the issue and background: Bash Script which calls AWK script Awk script returns a string as per below (example):var1='00000-123'So, when we convert it, the... (18 Replies)
Discussion started by: sekfarok
18 Replies

2. Shell Programming and Scripting

Using awk for converting xml to txt

Hi, I have a xml script, I converted it to .txt with values comma seperated using awk function. But I want the output values should be inside double quotes My xml script (Workorders.xml) is shown like below: <?xml version="1.0" encoding="utf-8" ?> <scbm-extract version="3.3">... (8 Replies)
Discussion started by: Viswanatheee55
8 Replies

3. UNIX for Advanced & Expert Users

Converting xls file to xlsx on UNIX script / command line.

Hi All, Am needing advise on how to convert xls file to xlsx format on Solaris unix command line or scripting. I tried searching online but it looks like I need to either use Perl packages of Excel or Python packages or some other 3rd party tool. Problem is to install any of these will require... (2 Replies)
Discussion started by: arvindshukla81
2 Replies

4. Shell Programming and Scripting

Converting txt file into CSV using awk or sed

Hello folks I have a txt file of information about journal articles from different fields. I need to convert this information into a format that is easier for computers to manipulate for some research that I'm doing on how articles are cited. The file has some header information and then details... (8 Replies)
Discussion started by: ksk
8 Replies

5. UNIX for Dummies Questions & Answers

Need help converting txt to XML

I have a table as following Archive id Line Author Time Text 1fjj34 3 75jk5l 03:20 this is an evidence regarding ... 1fjj34 4 gjhhtrd 03:21 we have seen those documents before 1fjj34 10 645jmdvvb 04:00 Will you consider such an offer?... (0 Replies)
Discussion started by: A-V
0 Replies

6. Shell Programming and Scripting

Converting txt file in csv

HI All, I have a text file memory.txt which has following values. Average: 822387 7346605 89.93 288845 4176593 2044589 51883 2.47 7600 i want to convert this file in csv format and i am using following command to do it. sed s/_/\./g <... (3 Replies)
Discussion started by: mkashif
3 Replies

7. UNIX for Dummies Questions & Answers

converting xls,xlsx files ??

I think I know the answer to this :rolleyes: but thought I'd ask anyway. You never know. Does anyone know of a program or utility that will run on any unix platform and convert Microsoft Excel files to ascii/plain text files that unix can understand ? Thanks in advance. Floyd (3 Replies)
Discussion started by: fwellers
3 Replies

8. Shell Programming and Scripting

converting .txt to comma delimeted file

Dear all, I have a file with 5L records. one of the record in the file is as shown below. MARIA THOMAS BASIL 1000 FM 1111 MD GHANA YY 77354 4774 99999999 1234567 I need to convert this record in below format "","","","","MARIA","THOMAS","BASIL","","1000 FM 1111 MD","STE... (1 Reply)
Discussion started by: OSD
1 Replies

9. UNIX for Dummies Questions & Answers

converting txt files in linux to windows

HI.. i have this problem..i want to copy a text file from linux and import it into an access file..but so many junk characters are coming in between..what i have to do.. plz help.. thanx in advance, (4 Replies)
Discussion started by: newbuddy
4 Replies

10. UNIX for Dummies Questions & Answers

converting .txt

Hello, I transferred some .txt files from windows to Unix. When i used the editor in Unix to open up the file, all the <cr> show up. How to I get rid of all of them? (4 Replies)
Discussion started by: laila63
4 Replies
Login or Register to Ask a Question