-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
105 lines (93 loc) · 3.55 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Grocery List / Multi-Column Converter</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 0 20px;
}
textarea {
width: 100%;
height: 200px;
margin-bottom: 10px;
}
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
button {
padding: 10px;
cursor: pointer;
}
</style>
</head>
<body>
<h2>Delimiter to Table Converter</h2>
<p>Paste your text. Use ")" as a delimiter between columns.</p>
<textarea id="inputText" placeholder="Paste your text here. Example: Banana ) ShopRite Potato ) Farmers Market"></textarea>
<button onclick="convertToTable()">Convert to Table</button>
<table id="resultTable"></table>
<button onclick="copyTableToClipboard()" id="copyButton" style="display:none;">Copy Table to Clipboard</button>
<script>
function convertToTable() {
const inputText = document.getElementById('inputText').value;
const resultTable = document.getElementById('resultTable');
const copyButton = document.getElementById('copyButton');
// Clear previous table
resultTable.innerHTML = '';
// Split the input into lines
const lines = inputText.trim().split('\n');
// Create table header dynamically based on the number of columns
const maxColumns = Math.max(...lines.map(line => line.split(')').length));
const headerRow = document.createElement('tr');
for (let i = 0; i < maxColumns; i++) {
const th = document.createElement('th');
th.textContent = `Column ${i + 1}`;
headerRow.appendChild(th);
}
resultTable.appendChild(headerRow);
// Populate table rows
lines.forEach(line => {
const columns = line.split(')').map(col => col.trim());
const tr = document.createElement('tr');
columns.forEach(col => {
const td = document.createElement('td');
td.textContent = col;
tr.appendChild(td);
});
resultTable.appendChild(tr);
});
// Show copy button
copyButton.style.display = 'block';
}
function copyTableToClipboard() {
const rows = document.querySelectorAll('#resultTable tr');
let tableText = '';
rows.forEach(row => {
const cells = row.querySelectorAll('th, td');
const rowText = Array.from(cells).map(cell => cell.innerText).join('\t');
tableText += rowText + '\n';
});
// Create temporary textarea
const textarea = document.createElement('textarea');
textarea.value = tableText;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
alert('Table copied to clipboard! Paste into Excel with Ctrl+V.');
}
</script>
</body>
</html>