问题:我想将xml数据打印到excel文件,但是打印到excel文件失败。
xml 文件:data.xml
<?xml version="1.0" encoding="UTF-8"?>
<ns1:BoardTestXMLExport numberOfIndictedComponents="11" testerTestStartTime=".00000:00" testTime=".00000:00" repairStationId="vvts03" testStatus="Reviewed Passed" testerTestEndTime=".00000:00" xmlns:ns1="http://tempuri.org/BoardTestXMLExport.xsd" numberOfIndictedPins="0" numberOfComponentsTested="113" numberOfJointsTested="0" numberOfDefects="11" repairStatus="Reviewed Passed">
<ns1:BoardXML imageId="0" serialNumber="R174842442 1P00232G01 R02 1C31228G01 R07 JH1711327" assemblyRevision="1P00232G01-LF-SS" boardType="1P00232G01-LF-SS" boardRevision="1511417735000"/>
<ns1:StationXML testerName="huaemsaoi004" stage="V510"/>
<ns1:RepairEventXML numberOfVariationOkDefects="0" numberOfFalseCalledPins="0" numberOfRepairedComponents="0" numberOfVariationOkPins="0" numberOfRepairedPins="0" numberOfRepairLaterPins="0" numberOfFalseCalledDefects="11" numberOfActiveDefects="0" numberOfVariationOkComponents="0" repairEndTime="2017-11-23T14:31:05.000+08:00" repairStartTime="2017-11-23T14:30:58.000+08:00" numberOfRepairLaterDefects="0" repairOperator="1066689" numberOfRepairLaterComponents="0" numberOfActiveComponents="0" numberOfActivePins="0" numberOfRepairedDefects="0" numberOfFalseCalledComponents="11"/>
<ns1:TestXML name="r1">
<ns1:IndictmentXML algorithm="rep-3a99979127l-lf" indictmentType="Left off, Right off">
<ns1:RepairActionXML repairOperator="1066689" repairTime="2017-11-23T14:30:58.000+08:00" repairActionType="-" indictmentType="Left off, Right off" comment="-" repairStatus="False Call"/>
<ns1:ComponentXML packageId="EP-3A99979127L-LF" partId="EP-3A99979127L-LF" designator="r1"/>
</ns1:IndictmentXML>
</ns1:TestXML>
</ns1:BoardTestXMLExport>
我的代码如下:
# use module
use strict;
use warnings;
use XML::Simple;
use Data::Dumper;
use Excel::Writer::XLSX;
# create object
my $xml = XML::Simple->new;
# create object
my $xml = XML::Simple->new;
#create excel object
my $OutFile = "Output". "\." . "xlsx";
my $workbook = Excel::Writer::XLSX->new($OutFile);
my $worksheet = $workbook->add_worksheet('SotredProcedures');
# Create a format for the column headings
my $header = $workbook->add_format();
$header->set_bold();
$header->set_color('red');
# Create a Text Wrap format
my $format1 = $workbook->add_format();
$format1->set_text_wrap();
$worksheet->write(0, 0, "RepairStationID", $header);
$worksheet->write(0, 1, "BoardType", $header);
$worksheet->write(0, 2, "ComponentsTested", $header);
$worksheet->write(0, 3, "NumberOfDefects", $header);
$worksheet->set_column(0, 1, 12);
$worksheet->set_column(1, 2, 20);
$worksheet->set_column(1, 3, 20);
$worksheet->set_column(1, 4, 20);
# read XML file
my $data = $xml->XMLin("data.xml",KeyAttr=>"ns1");
print $data ->{"ns1:BoardXML"}->{"boardType"}->{$worksheet};
结果:boardtype打印到excel文件失败,输出如下:
我该怎么办?