add a tab listing up to 65k rows of the actual data being summarized. Only for excel...
[migration-tools.git] / mig-bin / mig-quicksheet
index e97377a..22ed33e 100755 (executable)
@@ -238,6 +238,7 @@ sub write_worksheets {
     print 'File #' . $counter . "\n";
     print "Sheet: Field Summary\n";
     my $tab_name = (scalar(@ARGV) > 1 ? $counter . ') ' : '') . 'Field Summary';
+    $tab_name = substr($tab_name,0,31); # truncate for WriteExcel
     if ($outfile) {
         $first_sheet = $workbook->add_worksheet( $tab_name );
         $first_sheet->set_column(0,6,30);
@@ -285,6 +286,7 @@ sub write_worksheets {
         };
     }
 
+    handle_list();
     handle_columns();
 
     if ($outfile) {
@@ -318,6 +320,46 @@ exit 0;
 
 ###############################################################################
 
+sub handle_list {
+    my $dbh = Mig::db_connect();
+    my $sth = $dbh->prepare("
+        SELECT *
+        FROM " . $MIGSCHEMA. "." . $table . "
+        LIMIT 65530;
+    ");
+    my $rv = $sth->execute()
+        || die "Error retrieving data from staging table: $!";
+    my $list_sheet;
+
+    $sheet_row_offset = 0;
+    $has_x_source = 0;
+    if ($outfile) {
+        print "Sheet: $table\n";
+        $list_sheet = $workbook->add_worksheet( $table );
+    }
+
+    my $handle_headers = 1;
+
+    while (my $data = $sth->fetchrow_hashref) {
+        if ($handle_headers) {
+            my $_idx = 0;
+            foreach my $col (sort keys %{ $data }) {
+                $list_sheet->write($sheet_row_start + $sheet_row_offset,$_idx++,$col,$bold);
+            }
+            $handle_headers = 0;
+        }
+        $sheet_row_offset++;
+        my $idx = 0;
+        foreach my $col (sort keys %{ $data }) {
+            my $cdata = $$data{$col};
+            if (!defined $cdata) { $cdata = '\N'; }
+            if ($outfile) {
+                $list_sheet->write($sheet_row_start + $sheet_row_offset,$idx++,$cdata,$left);
+            }
+        }
+    }
+}
+
 sub handle_columns {
     my $dbh = Mig::db_connect();
     my $sth = $dbh->prepare("
@@ -472,7 +514,8 @@ sub group_by {
     my $col_sheet;
     my $col_table;
 
-    my $sheet_name = (scalar(@ARGV) > 1 ? $counter . ') ' : '') . substr($column,0,31);
+    my $sheet_name = (scalar(@ARGV) > 1 ? $counter . ') ' : '') . $column;
+    $sheet_name = substr($sheet_name,0,31);
 
     print "Sheet: $sheet_name\n";
     if ($has_x_source) {