Skip to content

Instantly share code, notes, and snippets.

@coronin
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coronin/900321d4a4c01dabe7e9 to your computer and use it in GitHub Desktop.
Save coronin/900321d4a4c01dabe7e9 to your computer and use it in GitHub Desktop.
copy cells from Excel to get them in a column
<!--
Copyright (c) 2014 Liang Cai (cailiang.net)
Inspired by 2010 Shawn M. Douglas (shawndouglas.com)
-->
<?php
echo "<html>
<head><title>table2col | Excel xls, table to column copy and paste converter</title></head>
<body><h1>Copy &amp; Paste Table-to-Column Converter</h1>
<form action='table2col.php' method='post'>
<textarea name='data' rows='16' cols='80'></textarea><br>
<input type='submit' /></form>";
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
echo "<small><b>Instructions:</b><br>
copy &amp; paste cells from Excel and click submit.<br>
<a style='text-decoration:none; color:blue;'
href=\"https://gist.github.com/coronin/900321d4a4c01dabe7e9\">source
code</a></small>";
} else {
echo "<h2>result</h2>\n<pre>\n";
$lines = preg_split("/\n/", $_POST['data']);
foreach ($lines as $index => $value) {
$line = preg_split("/\t/", $value);
foreach ($line as $indexx => $valuee) {
$cell = preg_replace("/\s/", '', $valuee);
if ($cell !== '') { echo $cell . "\n"; }
}
}
echo "</pre>";
}
echo "</body></html>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment