What is the best way to insert values from an array into a row?

Is there a way to insert values from an array into separate cells in exceljs?

I attempted the following approach:

const columns = ['string', 'string2', 'string3'];

for(let i=0; i < columns.length; i++) {
    workSheet.getRow(1).values  = [dto.columns[i]];
}

However, this code only adds one item from the columns list :/

Does anyone have a suggestion on how to solve this issue? I need to add objects from the array individually, not as a group like this:

workSheet.getRow(1).values  = ['string','string2', 'string3'];

This method does not suit my requirements :( Appreciate any assistance

Answer №1

To avoid always getting the last item inside the values property, you can reassign the value within the for loop by initializing the values as an empty array before the loop begins. This way, each item will be properly added to the values array.

const columns = ['string', 'string2', 'string3'];
workSheet.getRow(1).values = [];
for(let i=0; i < columns.length; i++) {
    workSheet.getRow(1).values.push(dto.columns[i]);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for developing a versatile code for passport.authenticate

I have a scenario where multiple controllers contain various methods that require user authentication to access database data. I am currently attempting to streamline the authentication process to avoid repetition in my code. Within the controller: const ...

Troubleshooting import issues when starting with Webpack

Starting out with Webpack and already facing an issue. I've followed the documentation by creating an app/index.js file, as well as an index.html file (with HTML and CSS copied from the docs). Ran necessary CLI commands including generating a dist/bun ...

Interactive Typescript slider with drag functionality

Seeking assistance in developing a draggable slider using TypeScript. I have managed to retrieve the client and scroll positions, but I am struggling to change the ref scrollLeft position. There are no errors thrown; however, the ref's scrollLeft prop ...

Avoid displaying hidden images or loading content upon clicking a tab

Check out my website here I have created four tabs on my website, and I want each tab to display a different gallery (Nextgen Pro gallery) when clicked. However, the performance is currently very poor because I am loading all the images at once. I plan to ...

Adjusting Text Size Depending on Width

I recently used an online converter to transform a PDF into HTML. Check out the result here: http://www.example.com/pdf-to-html-converted-file The conversion did a decent job, but I'm wondering if it's feasible to have the content scale to 100% ...

Editing the app.js file can cause it to malfunction and stop working

As I work on designing a webpage for a construction company using a template, I face an issue with the js file named app.js. Whenever I make edits to the script, the entire HTML page loses its responsiveness as if the js file was never included in the firs ...

Implementing HTTP GET and POST requests in Angular 2 allows for the functionality of displaying, adding, and deleting objects within a list

Hey there, I'm completely new to dealing with HTTP and fetching data from the server. I've been scouring through various tutorials, examples, and questions on different platforms, but unfortunately, I haven't been able to find exactly what I ...

Retrieving data from an anonymous function in AngularJS and outputting it as JSON or another value

Within the following code, I am utilizing a server method called "getUserNames()" that returns a JSON and then assigning it to the main.teamMembers variable. There is also a viewAll button included in a report that I am constructing, which triggers the met ...

Using Angular 2 to pass a function as an argument to a constructor

How can I create a custom @Component factory where a function is called to return a component, passing the widgetName to the constructor or super constructor? export function createCustomKendoComponent(selector: string, **widgetName**: string) { @Co ...

Using EventEmitter for Component Communication in Angular 2

I have a duo of components: AppComp and SimulationComp AppComp consists of a single function : createEmptyPromise() { return Promise.resolved('') } and it showcases the following html structure : <simulation-comp (simu)='createEm ...

Tips for assigning a value to a data property within a different Vue component

I am faced with a situation where I have two Vue components. The first one triggers the opening of a modal, while the second one serves as the content within that modal in the form of a table and a brief form. Upon completing the form, my goal is to click ...

Understanding the grammar of the Web Speech API

Could someone please explain the meaning of this code snippet? const grammar = '#JSGF V1.0; grammar colors; public <color> = aqua | azure | beige | bisque | black | blue | brown | chocolate | coral | crimson | cyan | fuchsia | ghost | white | g ...

Altering the appearance of a div following the execution of a header redirect

Essentially, I have a SignUp and LogIn form that pops up when activated by a button. See code below: LogIn <!-- Popup LogIn --> <div class="bg-modal"> <div class="modal-content"> <div class="close& ...

Utilizing turbolinks enables the page to be reloaded upon form submission

Currently, I have implemented turbolinks in my Rails application. However, every time I submit a form, the page reloads and the form is submitted. Is there a way to prevent the page from reloading and also submit the form seamlessly? ...

Avoid allowing multiple clicks on the submit button without disabling the validation group

When using an asp.net application, I noticed that clicking several times on a button submits the request multiple times. To prevent this, I implemented a javascript function to ensure that the request is only submitted once. However, this solution caused t ...

When attempting to tab, the cursor is not entering the textbox as expected

My project involves creating tabs with HTML, CSS, and jQuery, without using jQuery UI. I am facing a problem where the tab is not moving to the next tab's text boxes when the user navigates through them. The code can be found on Pastebin and JS Fiddle ...

Determine if a specific checkbox with a particular id has been selected using JQuery

Looking for assistance on how to determine if a checkbox with a specific ID is checked or unchecked. <input name="A" id="test" type="checkbox" value="A" /> <input name="B" id="test" type="checkbox" value="B" /> <input name="C" id="test1" t ...

What is the process for appending a file extension to a Next.js URL?

For instance, I am attempting to redirect the URL : https://example.com/data/publications to this : https://example.com/data/publications.json I made an attempt using Next.js redirection, but encountered difficulty when trying to add a string that does no ...

How can Firebase and Ionic be used to customize the password reset template for sending verification emails and more?

I'm facing an issue with firebase's auth templates not supporting my native language. Is there a way to customize the password reset template to also handle verification and email address change emails? ...

Angular not firing slide.bs.carousel or slid.bs.carousel event for Bootstrap carousel

I've searched high and low with no success. I'm attempting to detect when the carousel transitions to a new slide, whether it's automatically or by user click. Despite my numerous attempts, I have been unable to make this event trigger. I ha ...