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 })
});
let port = 4000
let port = 5000
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
@ -36,13 +36,11 @@ var XLSX = require('xlsx')
app.use(upload.none());
app.post('/upload', async function (req, res) {
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['Sheet1']);
let data = xlData.map((row) => ({ id: row.No, name: row['Product name'] }))
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 }))
res.send(data)
console.log('dawdaw', data)
})

View File

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