in reply to XML to Excel : not Unique ??
This fails on the third element of the second node: <element2><ROOT> <SUB CLASSNAME="SUB1"> <Element1 Type="Type1">Type 1 value</Element1> <Element2 Type="Type2">Type 2 value</Element2> </SUB> <SUB CLASSNAME = "SUB2"> <Element1 Type="Type1">Type 1 value</Element1> <Element2 Type="Type2">Type 2 value</Element2> <Element2 Type="Type3">Type 5 value</Element2> </SUB> <SUB CLASSNAME = "SUB3"> <Element1 Type="Star">content 1</Element1> <Element2 Type="Henry">Some stuff</Element2> </SUB> </ROOT>
Would be great if you guys found what is wrong. Deleting the element2 in the SUB2 will generate an excel file in your current directory.#! /usr/bin/perl use strict; use warnings; use Data::Dumper; use Cwd; use Win32::OLE; use XML::Simple; my $file = 'dataFile.xml'; my $xs1 = XML::Simple->new(); my $doc = $xs1->XMLin( $file, keyattr=>['CLASSNAME'], ForceContent=>1 +); my %subroutines = %{$doc->{SUB}}; my $application = Win32::OLE->new("Excel.Application"); my $workbook = $application->Workbooks->Add(); my $worksheet = $workbook->Worksheets(1); my $rowCount = 2; my $colCount = 2; my $colspan = 1; foreach my $this_routine ( sort keys %subroutines ) { my $element_count = scalar( keys %{$subroutines{$this_routine}} ); $worksheet->Cells($rowCount, $colCount)->{Value} = $this_routine; $rowCount++; foreach my $this_type (sort keys %{$subroutines{$this_routine}} ) { if ( exists $subroutines{$this_routine}-> {$this_type}->{Type}) { $worksheet->Cells($rowCount, $colCount)->{Value} = $this_type; $colCount++; } $rowCount--; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: XML to Excel : not Unique ??
by Anonymous Monk on Oct 31, 2008 at 10:55 UTC | |
by Sporti69 (Acolyte) on Oct 31, 2008 at 11:20 UTC | |
by Anonymous Monk on Oct 31, 2008 at 12:37 UTC |