Tuesday, May 26, 2009

perl vs xml vs excel

use Spreadsheet::ParseExcel;
use XML::DOM;
my $doc = XML::DOM::Document->new;

my $xml_pi = $doc->createXMLDecl ('1.0',"UTF-8","yes");
$doc->setXMLDecl($xml_pi);

my $root = $doc->createElement('tests');
$root->setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance");

my $parser = Spreadsheet::ParseExcel->new(
  CellHandler => \&cell_handler,
  NotSetCell => 1
);

my $workbook = $parser->Parse($filename);
$root->printToFile ($outFile);

exit(0);

  sub cell_handler {

  my $workbook = $_[0];
  my $sheet_index = $_[1];
  my $row = $_[2];
  my $col = $_[3];
  my $cell = $_[4];
 my $myTag;
 my $myText;

  $testName=$cell->value();
  if ($testName !~ m{\w+\.sv}) {$testName = ""; $lastCol = -1; return;}
  $test = $doc->createElement('Test');
  $myTag = $doc->createElement('Name');
  $myText = $doc->createTextNode($cell->value());
  $myTag->appendChild($myText);    #set text content for this tag
  $test->appendChild($myTag);

  if ($implemented == 1) { $root->appendChild($test); } # add new entry only if it's new line

}

No comments: