main file create
This commit is contained in:
parent
8d63343e8b
commit
8fe8144ef3
1 changed files with 109 additions and 0 deletions
109
excel.psgi
Normal file
109
excel.psgi
Normal file
|
|
@ -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 = "<h2>Submitted Data</h2><pre>";
|
||||
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 .= "</pre><a href='/'>Back</a>";
|
||||
|
||||
return [
|
||||
200,
|
||||
[ 'Content-Type' => 'text/html' ],
|
||||
[$output]
|
||||
];
|
||||
}
|
||||
|
||||
my $html = <<"HTML";
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>PSGI Spreadsheet</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
}
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
}
|
||||
td, th {
|
||||
border: 1px solid #ccc;
|
||||
padding: 0;
|
||||
}
|
||||
input {
|
||||
width: 80px;
|
||||
border: none;
|
||||
padding: 5px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
th {
|
||||
background: #eee;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Excel-like Grid</h1>
|
||||
|
||||
<form method="POST">
|
||||
<table>
|
||||
<tr>
|
||||
<th></th>
|
||||
HTML
|
||||
|
||||
# Column headers (A, B, C...)
|
||||
for my $c (0 .. $cols - 1) {
|
||||
my $label = chr(65 + $c);
|
||||
$html .= "<th>$label</th>";
|
||||
}
|
||||
$html .= "</tr>";
|
||||
|
||||
# Rows
|
||||
for my $r (0 .. $rows - 1) {
|
||||
$html .= "<tr>";
|
||||
$html .= "<th>" . ($r + 1) . "</th>";
|
||||
|
||||
for my $c (0 .. $cols - 1) {
|
||||
my $name = "cell_${r}_${c}";
|
||||
$html .= qq{<td><input name="$name" /></td>};
|
||||
}
|
||||
|
||||
$html .= "</tr>";
|
||||
}
|
||||
|
||||
$html .= <<"HTML";
|
||||
</table>
|
||||
<br>
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
HTML
|
||||
|
||||
return [
|
||||
200,
|
||||
[ 'Content-Type' => 'text/html' ],
|
||||
[$html]
|
||||
];
|
||||
};
|
||||
|
||||
return $app;
|
||||
Loading…
Add table
Add a link
Reference in a new issue