diff --git a/excel.psgi b/excel.psgi new file mode 100644 index 0000000..db29bb1 --- /dev/null +++ b/excel.psgi @@ -0,0 +1,109 @@ +use strict; +use warnings; +use Plack::Request; +use Plack::Response; + +my $app = sub { + my $env = shift; + my $req = Plack::Request->new($env); + + my $rows = 20; + my $cols = 10; + + if ($req->method eq 'POST') { + my $params = $req->parameters; + + my $output = "

Submitted Data

";
+        for my $r (0 .. $rows - 1) {
+            for my $c (0 .. $cols - 1) {
+                my $key = "cell_${r}_${c}";
+                my $val = $params->{$key} // '';
+                $output .= sprintf("%-10s", $val);
+            }
+            $output .= "\n";
+        }
+        $output .= "
Back"; + + return [ + 200, + [ 'Content-Type' => 'text/html' ], + [$output] + ]; + } + + my $html = <<"HTML"; + + + +PSGI Spreadsheet + + + + +

Excel-like Grid

+ +
+ + + +HTML + + # Column headers (A, B, C...) + for my $c (0 .. $cols - 1) { + my $label = chr(65 + $c); + $html .= ""; + } + $html .= ""; + + # Rows + for my $r (0 .. $rows - 1) { + $html .= ""; + $html .= ""; + + for my $c (0 .. $cols - 1) { + my $name = "cell_${r}_${c}"; + $html .= qq{}; + } + + $html .= ""; + } + + $html .= <<"HTML"; +
$label
" . ($r + 1) . "
+
+ +
+ + + +HTML + + return [ + 200, + [ 'Content-Type' => 'text/html' ], + [$html] + ]; +}; + +return $app;