Balawoo has asked for the wisdom of the Perl Monks concerning the following question:
This is my code done with help of many Monks.
#!/usr/bin/perl -w use warnings; #use strict; use Spreadsheet::Read 'ReadData'; use Encode 'decode'; use XML::LibXML; use HTML::Parser; use utf8; use File::Basename; $converted_dir = "converted_files"; # Source file and path are taken as script parameter if (@ARGV) { $full_source_file_path = $ARGV[0]; } else { die (" ! Please, enter file name as script parameter. \n See READM +E.txt for mor details"); } # Parse @ARGV, get path and file from script parameter ($source_file_name, $source_file_path, $source_file_suffix) = filepars +e($full_source_file_path, qr/\.[^.]*/); # Define all files and paths $source_file = "$source_file_name$source_file_suffix"; # Create folders for logs and converted files chdir ($source_file_path); mkdir ($converted_dir); # Output files get names after source file $xml_file = ("$source_file_name\_resulted.xml"); # Files + folders knocked into variables $xml = "$converted_dir/$xml_file"; no warnings; #my $INFILE = 'TestPGR.xlsx'; my $ENCODING = 'MacRoman'; #my $OUTFILE = 'TestPGR.xml'; my %FIELDS = ( 1=>'docid', 2=>'title', 3=>'version', 4=>'revision', 5=>'node_order', 6=>'description', 7=>'status', 8=>'type', 9=>'expected_coverage', ); my $book = ReadData($source_file, rc=>1, cells=>0, parser => "xlsx"); my $sheet = $book->[1] or die "Book doesn't have a sheet 1"; my $doc = XML::LibXML::Document->createDocument('1.0', 'UTF-8'); my $reqs = $doc->createElement('requirements'); $doc->setDocumentElement($reqs); #my $pp = new HTMLStrip; for my $r ( $sheet->{minrow}+1 .. $sheet->{maxrow} ) { my $req = $doc->createElement('requirement'); for my $c ( $sheet->{mincol} .. $sheet->{maxcol} ) { next unless exists $FIELDS{$c}; my $val = $sheet->{cell}[$c][$r]; if ($c ==6) { $val =~ s/\n/<br \/>/g; } my $node = $doc->createElement($FIELDS{$c}); $node->appendText($val); $req->appendChild($node); } $reqs->appendChild($req); } $doc->setEncoding('MacRoman'); $doc->toFile($xml,1);
This is an example of my file to test
https://drive.google.com/file/d/1VGBDtdK9kP6OBVXvTT_oxyh2g45yfsvC/view?usp=sharing
When I launch it, even none file (in and out are opened), I have this error
Have you an idea of issue?MBPPGR:Exigence sapfinance$ perl essai2.pl TestPGR.xlsx i18n error : output conversion failed due to conv error, bytes 0x00 0x +65 0x6D 0x70 I/O error : encoder error
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Newbie i18n error : output conversion failed due to conv error
by haj (Vicar) on Feb 17, 2019 at 21:21 UTC |