Fix style
This commit is contained in:
parent
36979b0ae1
commit
60e39d9e1a
10
src/index.js
10
src/index.js
@ -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)
|
||||
})
|
||||
|
||||
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user