How to use correctly Spreadsheet::WriteExcel to convert xml to xls


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 10-11-2011
How to use correctly Spreadsheet::WriteExcel to convert xml to xls

Hi to all,

I want to convert xml file to binary Excel file, after googling for a while, I found cpan tool "Spreadsheet::WriteExcel::FromXML". I installed both,
Spreadsheet::WriteExcel and Spreadsheet::WriteExcel::FromXML.

To test Spreadsheet::WriteExcel I executed a example script that comes within it, "a_simple.pl" and works.

But the codes below intended to use convert xml to xls don't work for me.

I've been trying to follow 2 examples of xml to xls:
This code below
Ref: http://search.cpan.org/~rbo/Excel-Template-0.33/lib/Excel/Template.pm
Code:
  #!/usr/bin/perl -w

  use strict;

  use Excel::Template;

  # Create the Excel template
  my $template = Excel::Template->new(
      filename => 'test.xml',
  );
  # Add a few parameters
  $template->param(
      HOME => $ENV{HOME},
      PATH => $ENV{PATH},
  );
  $template->write_file('test.xls');

and the options from the code below:
Ref: http://search.cpan.org/dist/Spreadsheet-WriteExcel-FromXML/lib/Spreadsheet/WriteExcel/FromXML.pm
Code:
  use strict;
  use warnings;
  use Spreadsheet::WriteExcel::FromXML;
  my $fromxml = Spreadsheet::WriteExcel::FromXML->new( "file.xml" );
  $fromxml->parse;
  $fromxml->buildSpreadsheet;
  $fromxml->writeFile("file.xls");
  # or
  my $data = $fromxml->getSpreadsheetData;
  # then write $data to a file...or do with it as you wish

  # or, even simpler:
  my $data = Spreadsheet::WriteExcel::FromXML->BuildSpreadsheet( "file.xml" );

  # or, even simpler:
  Spreadsheet::WriteExcel::FromXML->XMLToXLS( "file.xml", "file.xls" );

Follow the 1rst example, the test.xml is as simple as:
Code:
  <workbook>
      <worksheet name="tester">
          <cell text="$HOME" />
          <cell text="$PATH" />
      </worksheet>
  </workbook>

and I get the following errors when I run the 2nd code:
Code:
./xml_to_xls.pl # I only trying the lines in red in code above
Must define a title attribute for worksheet!
 at /usr/local/share/perl/5.10.1/Spreadsheet/WriteExcel/FromXML.pm line 248
    Spreadsheet::WriteExcel::FromXML::_processTree('Spreadsheet::WriteExcel::FromXML=HASH(0x9f2a818)', 
'ARRAY(0xa4b5340)', 'worksheet', 'SCALAR(0xa4a08d0)', 'SCALAR(0xa4a08f0)', undef, undef) called at /usr/local/share/perl/5.10.1/
Spreadsheet/WriteExcel/FromXML.pm line 328
    Spreadsheet::WriteExcel::FromXML::_processTree('Spreadsheet::WriteExcel::FromXML=HASH(0x9f2a818)', 'ARRAY(0xa4b5270)', 
'workbook', 'SCALAR(0xa4a08d0)', 'SCALAR(0xa4a08f0)') called at /usr/local/share/perl/5.10.1/Spreadsheet/WriteExcel/FromXML.pm line 186
    Spreadsheet::WriteExcel::FromXML::parse('Spreadsheet::WriteExcel::FromXML=HASH(0x9f2a818)') called at ./xml_to_xls.pl line 7

May somebody please help me saying me how to test/use correctly the module Spreadsheet::WriteExcel::FromXML or
Spreadsheet::WriteExcel in order to convert XML files to Excel XLS files?

Thanks in advance


---------- Post updated at 03:51 PM ---------- Previous update was at 05:32 AM ----------

May somebody help me with this

Thanks in advance.

Last edited by Ophiuchus; 10-11-2011 at 05:39 AM..
# 2  
Old 10-11-2011
It's giving you a relevant-looking error message:

Code:
Must define a title attribute for worksheet!

I suggest you give your worksheet a title attribute.
# 3  
Old 10-12-2011
Hi Corona,

Thanks for answer me.

I just trying with this example as in the link I show.
Code:
  <workbook>
      <worksheet name="tester">
          <cell text="$HOME" />
          <cell text="$PATH" />
      </worksheet>
  </workbook>

The part in red wouldn't be the title of the worksheet?

Thanks for help so far

---------- Post updated 10-12-11 at 02:07 AM ---------- Previous update was 10-11-11 at 04:57 PM ----------

May somebody help me with this.

Thanks in advance

Moderator's Comments:
Mod Comment No bumping up of posts - re-read the forum rules, thanks.

Last edited by zaxxon; 10-12-2011 at 02:26 AM..
# 4  
Old 10-12-2011
We're not "on call". If we don't answer you in the first 5 minutes, wait! Smilie

I don't see a 'title' attribute in there, I do see a 'name' one, it's asking for 'title', give it 'title'. Computers are the most literal-minded things in the world.

I've been unable to install this Spreadsheet::WriteExcel::FromXML module, too many thousand dependencies, so I can't test it myself.
# 5  
Old 10-14-2011
Sorry for that man.

I've changed title and works and changed some things within the module and fits some
situations, but when I change a few things in xml sample, other errors appear.
I think is better to ask to the author the correct xml structure the module expects.

Quote:
Originally Posted by Corona688
I've been unable to install this Spreadsheet::WriteExcel::FromXML module, too many thousand dependencies, so I can't test it myself.
Don't worry, many thanks for your help and time.

Grettings.
# 6  
Old 10-14-2011
Quote:
Originally Posted by Ophiuchus
Sorry for that man.

I've changed title and works and changed some things within the module and fits some situations, but when I change a few things in xml sample, other errors appear.
Which other errors? As before, it might be telling you exactly what it wants...
# 7  
Old 10-14-2011
parse, scalar errors. but don't worry. I found some xml files that open correctly in excel and others don't because they have more than 256 columns which is what "xls" files accept.

I don't want to take you or anubody else time in this because I realize that won't be the solution since thin perl module only converts xml to xls and now to solve that issues I need to do a script to convert my xml files into xml xlsx format.

I've been seeing how xlsx format works and I know what which files I need to generate in order to get the correct structure.

Probably to get some part of that I will need to ask something to experts in the forum, maybe if that happens and you see my eventual question and you have some time, it would be wonderful receive your help.

Meantime, much appreciated for your time and interest to help.
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
How to convert Text data to xls? srkmish Shell Programming and Scripting 14 08-19-2014 10:14 PM
How to convert Excel Files to Xls? kalidoss Shell Programming and Scripting 5 08-05-2013 03:32 AM
Spreadsheet::WriteExcel::FromXML question(s) garboon Shell Programming and Scripting 1 06-07-2012 06:32 AM
xml to xls userraone Shell Programming and Scripting 3 03-14-2012 05:49 AM
problem with "merge_range" in Spreadsheet::WriteExcel" module kavi.mogu Shell Programming and Scripting 0 02-02-2012 07:06 AM
How to convert a xls file to csv? cnraja Shell Programming and Scripting 4 03-18-2011 05:25 AM
Tool for Convert XLS into CSV in UNIX luke_devon UNIX and Linux Applications 6 06-02-2010 04:54 PM
how to convert .xls to .csv varma457 Shell Programming and Scripting 1 07-29-2009 02:23 AM
Shell convert xls to csv Gracjan Shell Programming and Scripting 4 01-09-2009 10:40 AM
How to input .txt file into .xls spreadsheet wereyou Shell Programming and Scripting 1 12-22-2006 02:33 PM