Fix style

This commit is contained in:
Hou Samnang 2021-03-30 11:28:16 +07:00
parent 36979b0ae1
commit 60e39d9e1a
2 changed files with 19 additions and 23 deletions

View File

@ -25,7 +25,7 @@ app.get('/', function (req, res) {
res.sendFile('/upload.html', { root: __dirname }) res.sendFile('/upload.html', { root: __dirname })
}); });
let port = 4000 let port = 5000
app.listen(port, () => { app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`) console.log(`Example app listening at http://localhost:${port}`)
}) })
@ -36,13 +36,11 @@ var XLSX = require('xlsx')
app.use(upload.none()); app.use(upload.none());
app.post('/upload', async function (req, res) { app.post('/upload', async function (req, res) {
let input = req.body.myFile; let input = req.body.myFile;
let wb = XLSX.read(input, { type: 'binary' });
let wb = XLSX.read(input, {type : 'binary'}); let xlData = XLSX.utils.sheet_to_json(wb.Sheets['Sheet2']);
let data = xlData.map((row) => ({ productName: row['Product name'], smallTypeName: row.smallTypeName, productCategory: { productCategoryId: row['CategoryID'] }, alert: row.alert, cost: row.cost, qtyStock: row.qtystock, sellPrice: row.sellPrice }))
let xlData = XLSX.utils.sheet_to_json(wb.Sheets['Sheet1']);
let data = xlData.map((row) => ({ id: row.No, name: row['Product name'] }))
res.send(data) res.send(data)
console.log('dawdaw', data)
}) })

View File

@ -7,27 +7,25 @@
<input type="file" id="myFile" name="myFile" /> <input type="file" id="myFile" name="myFile" />
<input type="submit" /> <input type="submit" />
<br /><br /><br /><br /> <br /><br /><br /><br />
<textarea id="result"l style="width:100%" rows="5"></textarea> <textarea id="result" style="width: 100%" rows="10"></textarea>
</form> </form>
<script> <script>
function upload(event) { function upload(event) {
let file = document.getElementById("myFile").files[0]; let file = document.getElementById("myFile").files[0];
let formData= new FormData() let formData = new FormData();
const reader = new FileReader() const reader = new FileReader();
reader.onload = async (e)=>{ reader.onload = async (e) => {
console.log(e.target.result) console.log(e.target.result);
formData.append("myFile", e.target.result) formData.append("myFile", e.target.result);
const res = await fetch("/upload", { const res = await fetch("/upload", {
method: "POST", method: "POST",
body: formData, body: formData,
}); });
const json = await res.json() const json = await res.json();
document.getElementById('result').value = JSON.stringify(json) document.getElementById("result").value = JSON.stringify(json);
};
reader.readAsBinaryString(file);
}
reader.readAsBinaryString(file)
} }
</script> </script>
</body> </body>