Greetings,

I recently wrote some code for Excel to MARC conversion. The script doesn't
require Excel to be installed, so it should work just fine on Unix boxes
(not tested though).

#!c:\perl\bin\perl.exe
# xl2m.pl
# Convert Excel data into valid MARC21 records

use strict;
use warnings;
use MARC::Record;
use Spreadsheet::ParseExcel::Simple;

# Open the Excel file
my $fh;
unless ( $fh = Spreadsheet::ParseExcel::Simple->read( $ARGV[0] ) ) {
    die "No input Excel file.\n";
} else {
    print "Preparing MARC records ... \n\n";
}

# Open the Output filehandle
open( OUT, ">$ARGV[1]" );
binmode OUT, ":encoding(UTF-8)"; # Handle UTF-8 data sans warnings

my $rec_num = 0;

# Open the worksheet
foreach my $sheet ( $fh->sheets ) {
    while ( $sheet->has_data ) {
        my @row = $sheet->next_row;
        $rec_num++;
        my $bib_id    = $row[0];
        my $title    = $row[1];
        #[...]

        my $record = MARC::Record->new();
        $record->leader('00054nam a22002891a 4500');

        # Create the tags
        if ($title) {
            $record->append_fields(
                MARC::Field->new( '245', 1, 0, 'a' => $title )
            );
        }
        # [...]
        print OUT $record->as_usmarc();
        print ".";
    }
}
close(OUT);

print "\n\n$rec_num records created.\n";


I happened to see the Swollen Appendices section in the MARC::Doc::Tutorial
where the Excel section was empty. I guess this one can find a place there.

Regards,
Saiful
-- 
Saiful Amin
+91-9343826438

Attachment: xl2m.pl
Description: Binary data

Reply via email to