Permalink
Browse files

FIXED: sorting on insertion/deletion

NOTE: previous code didn't sort at all and new code
NOTE: uses intergers and is faster
  • Loading branch information...
1 parent 5fb8138 commit 9f828b5f857f2a718d6230825bcbf6fa0a9c55cf nadim khemir committed May 15, 2011
Showing with 45 additions and 33 deletions.
  1. +19 −4 Perl.pm
  2. +2 −9 Perl/ASCIITable.pm
  3. +20 −20 Perl/InsertDelete.pm
  4. +4 −0 Todo.txt
View
23 Perl.pm
@@ -1134,7 +1134,7 @@ Spreadsheet::Perl functionality:
=item * Automatic formula offsetting
-=item * Insertion of rows and columns (no deletion yet)
+=item * Insertion of rows and columns (with some limitation)
=item * Relative and fixed cell addresses
@@ -1270,6 +1270,23 @@ spreadsheet functions are accessed through the tied object.
tie my %ss, "Spreadsheet::Perl", NAME => 'TEST' ;
%ss = do "ss_setup.pl" or confess "Couldn't read setup file 'ss_setup.pl'" ;
+
+=head2 insertion and deletion of rows and columns
+
+#TODO: complete this section
+# list the APIs and show examples
+
+Within a single spreadsheet:
+ - insertion row/col
+ - deletion row/col
+ * dependent still broken
+
+Inter spreadsheet:
+ * insertion row/col
+ * deletion row/col
+ * dependent still broken
+
+
=head2 dumping a spreadsheet
Use the Dump function (see I<Debugging>):
@@ -2506,12 +2523,10 @@ Here are some of the things that I find missing, this doesn't mean all are good
=item * Gnumeric/Excel formula syntax (common format is done)
-=item * complex stuff (I am working on this but Gnumeric and excel do diffrent things)
+=item * complex stuff
=over 4
-=item * Deletion of rows and columns
-
=item * Sorting
=back
View
11 Perl/ASCIITable.pm
@@ -97,15 +97,8 @@ for my $range (@$ranges)
{
if($ss->{DEBUG}{PRINT_DEPENDENT_LIST})
{
- # dependent are set after someone used a cell
- # in DumpTable, a cell can be displayed before
- # its dependents are displayed, thus will have
- # an uncomplete dependent list
- # to make sure the dependent list is up to date
- # before display, Recalculate the spreadsheet
-
- my $dh = $ss->{DEBUG}{ERROR_HANDLE} ;
- print $dh "PRINT_DEPENDENT_LIST set, calling Recalculate before dumping spreadsheet in table form.\n" ;
+# my $dh = $ss->{DEBUG}{ERROR_HANDLE} ;
+# print $dh "PRINT_DEPENDENT_LIST set, calling Recalculate before dumping spreadsheet in table form.\n" ;
$ss->Recalculate() ;
}
View
40 Perl/InsertDelete.pm
@@ -21,7 +21,7 @@ our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ) ;
our @EXPORT ;
push @EXPORT, qw() ;
-our $VERSION = '0.02' ;
+our $VERSION = '0.03' ;
#-------------------------------------------------------------------------------
@@ -48,7 +48,7 @@ for my $cell_address ($self->GetCellList())
}
}
-for my $row (reverse SortCells keys %moved_cell_list)
+for my $row (reverse sort keys %moved_cell_list)
{
for my $cell_address (@{$moved_cell_list{$row}})
{
@@ -66,7 +66,7 @@ for my $row (reverse SortCells keys %moved_cell_list)
# note, the cells don't have to be update in a specific order
# we keep the same order as moved cells to create the illusion
# of order
-for my $row (reverse SortCells keys %not_moved_cell_list)
+for my $row (reverse sort keys %not_moved_cell_list)
{
for my $cell_address (@{$not_moved_cell_list{$row}})
{
@@ -104,17 +104,17 @@ for my $cell_address ($self->GetCellList())
if( $column_index >= $start_column_index)
{
- push @{$moved_cell_list{$column}}, $cell_address ;
+ push @{$moved_cell_list{$column_index}}, $cell_address ;
}
else
{
- push @{$not_moved_cell_list{$column}}, $cell_address ;
+ push @{$not_moved_cell_list{$column_index}}, $cell_address ;
}
}
-for my $column (reverse SortCells keys %moved_cell_list)
+for my $column_index (reverse sort keys %moved_cell_list)
{
- for my $cell_address (@{$moved_cell_list{$column}})
+ for my $cell_address (@{$moved_cell_list{$column_index}})
{
my $new_address = $self->OffsetAddress($cell_address, $number_of_columns_to_insert, 0) ;
@@ -130,9 +130,9 @@ for my $column (reverse SortCells keys %moved_cell_list)
# note, the cells don't have to be update in a specific order
# we keep the same order as moved cells to create the illusion
# of order
-for my $column (reverse SortCells keys %not_moved_cell_list)
+for my $column_index (reverse sort keys %not_moved_cell_list)
{
- for my $cell_address (@{$not_moved_cell_list{$column}})
+ for my $cell_address (@{$not_moved_cell_list{$column_index}})
{
$self->OffsetFormula($cell_address, $start_column, $number_of_columns_to_insert, 0, 0, "${start_column}1:AAAA9999") ;
}
@@ -201,30 +201,30 @@ for my $cell_address ($self->GetCellList())
{
if ($column_index < $start_column_index + $number_of_columns_to_delete)
{
- push @{$removed_cell_list{$column}}, $cell_address ;
+ push @{$removed_cell_list{$column_index}}, $cell_address ;
}
else
{
- push @{$moved_cell_list{$column}}, $cell_address ;
+ push @{$moved_cell_list{$column_index}}, $cell_address ;
}
}
else
{
- push @{$not_moved_cell_list{$column}}, $cell_address ;
+ push @{$not_moved_cell_list{$column_index}}, $cell_address ;
}
}
-for my $column (keys %removed_cell_list)
+for my $column_index (keys %removed_cell_list)
{
- for my $cell_address (@{$removed_cell_list{$column}})
+ for my $cell_address (@{$removed_cell_list{$column_index}})
{
$self->DELETE($cell_address) ; # DELETE would call the appropriate callback
}
}
-for my $column (SortCells keys %moved_cell_list)
+for my $column_index (sort keys %moved_cell_list)
{
- for my $cell_address (@{$moved_cell_list{$column}})
+ for my $cell_address (@{$moved_cell_list{$column_index}})
{
if(exists $self->{CELLS}{$cell_address}{GENERATED_FORMULA})
{
@@ -248,9 +248,9 @@ for my $column (SortCells keys %moved_cell_list)
# note, the cells don't have to be update in a specific order
# we keep the same order as moved cells to create the illusion
# of order
-for my $column (reverse SortCells keys %not_moved_cell_list)
+for my $column_index (reverse sort keys %not_moved_cell_list)
{
- for my $cell_address (@{$not_moved_cell_list{$column}})
+ for my $cell_address (@{$not_moved_cell_list{$column_index}})
{
# TODO GENERATED_FORMULA exists only after the cell has been
# compiled. Is there a case where DeleteColumns could be called
@@ -335,7 +335,7 @@ for my $row (keys %removed_cell_list)
}
}
-for my $row (SortCells keys %moved_cell_list)
+for my $row (sort keys %moved_cell_list)
{
for my $cell_address (@{$moved_cell_list{$row}})
{
@@ -361,7 +361,7 @@ for my $row (SortCells keys %moved_cell_list)
# note, the cells don't have to be update in a specific order
# we keep the same order as moved cells to create the illusion
# of order
-for my $row (reverse SortCells keys %not_moved_cell_list)
+for my $row (reverse sort keys %not_moved_cell_list)
{
for my $cell_address (@{$not_moved_cell_list{$row}})
{
View
4 Todo.txt
@@ -1,7 +1,11 @@
Spreadsheet::Perl
=================
+insert_rows_columns works only in the same spreadsheet
+ this can be fixed though, Recalc and use dependents to modify
+ inter spreadsheet formulas
+deletion of cell should update the dependent list
insert_rows_columns check formulas to see if they are inlclusive in the
insertion range. should they check for intersection as Delete_column does?

0 comments on commit 9f828b5

Please sign in to comment.