When I copy data from Excel and paste onto a word document. They have "\t" in between each word & "\n" at the end of the line, it looks like this:
Letter Number Symbol
A 1 #
B 2 !
C 3 %
Thanks Joasih for all your help. the missing piece of this puzzle is that if there is no data, it needs to have a space.
Without pipes:
Letter Number Symbol
A 1 #
B !
C 3 %
With pipes:
||Letter||Number||Symbol||
|A|1|#|
|B| |!|<-- Needs to have a space if no data
|C|3|%|
var submitBtn = true;
$("#reset").click(function () {
$("#withoutPipes").val("");
submitBtn = true;
});
$("#submit").click(function () {
if (submitBtn && $("#withoutPipes").val() != "") {
var excelText = $("#withoutPipes").val();
var excelLines = excelText.replace(/\t\t/g, "\t \t");
var split = excelLines.replace(/\t\t/g, "\t \t ").split("\n");
var header = "||" + split[0].replace(/\t/g, "||") + "||";
var cells = "|" + split.slice(1).join("|\n|").replace(/\t/g, "|") + "|";
var formattedTable = header + "\n" + cells;
$("#withoutPipes").val(formattedTable);
submitBtn = false;
}
});
#withoutPipes {
width: 400px;
height: 200px;
font-size: 14pt;
margin-top: 50px;
padding: 10px 10px 10px 10px;
vertical-align: top;
}
.textBox {
margin: 0;
text-align: center;
}
.buttons {
margin: 40px 20px 20px 40px;
font-size: 14pt;
}
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<form id="testForm">
<textarea id="withoutPipes" autofocus="on" placeholder="Copy and paste the table here. Just Ctrl-V and submit"></textarea>
</form>
<button type="button" class="buttons" id="submit">Format table for JIRA</button>