+ if (my $xml = data2xml($type_base,$row,$add_xml,$cfg,$database)) {
+ $xml = $cp2utf->convert($xml);
+ use bytes; # as opposed to chars
+ print "Path-Name: $swishpath\n";
+ print "Content-Length: ".(length($xml)+1)."\n";
+ print "Document-Type: XML\n\n$xml\n";
+ }
+ }
+ }
+ print STDERR "\n";
+
+ } elsif ($type_base eq "excel") {
+ require Spreadsheet::ParseExcel;
+ require Spreadsheet::ParseExcel::Utility;
+ import Spreadsheet::ParseExcel::Utility qw(int2col);
+
+ $import2cp = Text::Iconv->new($config->{excel_codepage},$codepage);
+ my $excel_file = $cfg -> val($database, 'excel_file') || die "$database doesn't have 'excel_file' defined!";
+
+ my $sheet = x($config->{sheet}) || die "no sheet in $type.xml";
+ my $start_row = x($config->{start_row}) - 1 || die "no start_row in $type.xml";
+
+ my $oBook = Spreadsheet::ParseExcel::Workbook->Parse($excel_file) || die "can't open Excel file '$excel_file'";
+
+ my $sheet_nr = 0;
+ foreach my $oWks (@{$oBook->{Worksheet}}) {
+ #print STDERR "-- SHEET $sheet_nr:", $oWks->{Name}, "\n";
+ last if ($oWks->{Name} eq $sheet);
+ $sheet_nr++;
+ }
+
+ my $oWorksheet = $oBook->{Worksheet}[$sheet_nr];
+
+ print STDERR "using sheet: ",$oWorksheet->{Name},"\n";
+ defined ($oWorksheet) || die "can't find sheet '$sheet' in $excel_file";
+ my $end_row = x($config->{end_row}) || $oWorksheet->{MaxRow};
+
+ for(my $iR = $start_row ; defined $end_row && $iR <= $end_row ; $iR++) {
+ my $row;
+ for(my $iC = $oWorksheet->{MinCol} ; defined $oWorksheet->{MaxCol} && $iC <= $oWorksheet->{MaxCol} ; $iC++) {
+ my $cell = $oWorksheet->{Cells}[$iR][$iC];
+ if ($cell) {
+ # this conversion is a cludge.
+ # Files from Excell could have
+ # characters which don't fit into
+ # destination encoding.
+ $row->{int2col($iC)} = $utf2cp->convert($cell->Value) || $cell->Value;
+ }
+ }
+
+ progress($iR, $end_row);
+
+# print "row[$iR/$end_row] ";
+# foreach (keys %{$row}) {
+# print "$_: ",$row->{$_},"\t";
+# }
+# print "\n";
+
+ my $swishpath = $database."#".$iR;
+
+ next if (! $row);
+
+ if (my $xml = data2xml($type_base,$row,$add_xml,$cfg,$database)) {
+ $xml = $cp2utf->convert($xml);
+ use bytes; # as opposed to chars
+ print "Path-Name: $swishpath\n";
+ print "Content-Length: ".(length($xml)+1)."\n";
+ print "Document-Type: XML\n\n$xml\n";
+ }
+ }
+ } elsif ($type_base eq "marc") {
+
+ require MARC::File::USMARC;
+
+ $import2cp = Text::Iconv->new($config->{marc_codepage},$codepage);
+ my $marc_file = $cfg -> val($database, 'marc_file') || die "$database doesn't have 'marc_file' defined!";
+
+ # optional argument is format
+ warn "marc_format is no longer used!" if ($config->{marc_format});
+ print STDERR "Reading MARC file '$marc_file'\n";
+
+ my $marc = MARC::File::USMARC->in( $marc_file )
+ || die "Can't open MARC file '$marc_file': ".$MARC::File::ERROR;
+
+ # count records in MARC file
+ sub marc_count {
+ my $filename = shift || die;
+ my $file = MARC::File::USMARC->in($filename) || die $MARC::File::ERROR;
+ my $count = 0;
+ while ($file->skip()) {
+ $count++;