excel to redmine table

copy & paste excel data then converted redmine table format string will be copied

by shed

HTML

<h3>excel에서 copy해서 붙히면. copy & paste your excel data</h3>
<textarea id="in"></textarea>
<hr>
<h3>변환된 결과가 자동 copy 됩니다. then converted tag will be copied</h3>
<textarea id="out"></textarea>

CSS

textarea {
	width:100%;
	height:100px;
}

JavaScript

function excelToRedmineTable() {
	$('#out').val('');
	var lines = $('#in').val().split(/\r\n|\r|\n/);
	lines = lines.slice(0, lines.length-1);
	$.each(lines, function( index, line ) {
		line = line.trim();
		if(index == 0) {
			line = '|_. ' + line + ' |';
			line = line.replace(/\t/g, ' |_. ');
		} else {
			line = '| ' + line + ' |';
			line = line.replace(/\t/g, ' | ');
		}
		$('#out').val($('#out').val() + line + '\r\n');
	});		
	$('#out').select();
	document.execCommand('copy');
}

$( document ).ready(function() {
	$(document).on('input propertychange', "textarea[id='in']", function () {
		excelToRedmineTable();
	});
});