Spreadsheet::Engine::Storage::SocialCalc - load SocialCalc files


Spreadsheet-Engine documentation Contained in the Spreadsheet-Engine distribution.

Index


Code Index:

NAME

Top

Spreadsheet::Engine::Storage::SocialCalc - load SocialCalc files

SYNOPSIS

Top

  use Spreadsheet::Engine::Storage::SocialCalc;

  my Spreadsheet::Engine $sheet =
       Spreadsheet::Engine:Storage::SocialCalc->load($file);

DESCRIPTION

Top

This instantiates a Spreadsheet::Engine from a saved file in the SocialCalc format.

METHODS

Top

load

  my Spreadsheet::Engine $sheet =
       Spreadsheet::Engine:Storage::SocialCalc->load($file);

Load a saved file.

HISTORY

Top

This is a modified version of code from SocialCalc::DataFiles in SocialCalc 1.1.0

AUTHORS

Top

wikiCalc was developed by Dan Bricklin, at Software Garden, Inc.

SocialCalc 1.1.0 was developed by Dan Bricklin, Casey West, and Tony Bowden, at Socialtext, Inc.

Spreadsheet::Engine is developed and maintained by Tony Bowden <tony@tmtm.com>

COPYRIGHT

Top

LICENCE

Top

The contents of this file are subject to the Artistic License 2.0; you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.perlfoundation.org/artistic_license_2_0


Spreadsheet-Engine documentation Contained in the Spreadsheet-Engine distribution.
package Spreadsheet::Engine::Storage::SocialCalc;

use strict;
use warnings;

use Carp;
use IO::File;

use Spreadsheet::Engine;

sub load {
  my ($class, $file) = @_;
  my $datafile = IO::File->new($file) or croak "Can't open $file: $!\n";

  my ($line,        $boundary);
  my ($headerlines, $sheetlines);

  while ($line = <$datafile>) {
    last if $line =~ m/^Content-Type:\smultipart\/mixed;/i;
  }
  $line =~ m/\sboundary=(\S+)/i;
  $boundary = $1 or croak "No boundary found in $file";

  while ($line = <$datafile>) {
    $line =~ s/\r//g;
    last if $line =~ m/^--$boundary$/o;
  }

  while ($line = <$datafile>) {    # go to blank line
    chomp $line;
    $line =~ s/\r//g;
    last unless $line;
  }

  my $bregex = qr/^--$boundary/;

  while ($line = <$datafile>) {    # copy header lines
    last if $line =~ m/$bregex/;
    push @{$headerlines}, $line if $headerlines;
  }

  while ($line = <$datafile>) {    # go to blank line
    chomp $line;
    $line =~ s/\r//g;
    last unless $line;
  }

  while ($line = <$datafile>) {    # copy sheet lines
    last if $line =~ m/$bregex/;
    push @{$sheetlines}, $line;
  }

  return Spreadsheet::Engine->load_data($sheetlines);

}

1;