i need support! My loop doensn´t work and i don´t know why :/
I want only one xlsx (ProductList.xlsx), but for each product a sheet. I tried it with for-loop but it doesn´t work.
const product = [];
//fill out product
for (let i = 0; i < product_seller.length; i++){
//use this if everything is needed
product.push({
Seller: product_seller[i],
ItemsRemain: items_remain[i],
ProductPrice: product_price[i+1],
ProductCountry: product_country[i],
SellerCountry: seller_country[i],
ProductSales: product_sales[i]
});
}
//console.log(product);
const convertJsonToExcel=()=>{
const workBook = xlsx.utils.book_new();
for(let i = 0; i < product_list.length; i++){
const workSheet = xlsx.utils.json_to_sheet(product);
xlsx.utils.book_append_sheet(workBook, workSheet, product_list[i]);
//xlsx.write(workBook, {bookType:'xlsx', type:'buffer'});
//xlsx.write(workBook, {bookType:'xlsx', type:'binary'});
}
xlsx.writeFile(workBook, 'ProductList.xlsx');
}
convertJsonToExcel();
this is in an axios and i´ve got a json like this:
[
{
Seller: 'SpielFilmMusik',
ItemsRemain: '1',
ProductPrice: '159,95 €',
ProductCountry: 'Englisch',
SellerCountry: 'Artikelstandort: Deutschland',
ProductSales: '6K'
},
{
Seller: 'SpielFilmMusik',
ItemsRemain: '2',
ProductPrice: '159,95 €',
ProductCountry: 'Deutsch',
SellerCountry: 'Artikelstandort: Deutschland',
ProductSales: '6K'
},
...
]
and i´ve got an Error: Sheet names cannot exceed 31 chars
product_list is a list with all products and for each product the axios scrape the seller, price, items remain etc.