Last active
August 29, 2015 14:07
-
-
Save coronin/900321d4a4c01dabe7e9 to your computer and use it in GitHub Desktop.
copy cells from Excel to get them in a column
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
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 & 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 & 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