Changing the data type of a column in an Excel file from XLSX to

I am currently working with the XLSX npm package and attempting to download a sample Excel file, add some data to it, and then upload it back. The fields in the file include MOBILE NUMBER, DATE, TIME, and NAME. When I upload the file, the values for the DATE, TIME, and MOBILE NUMBER fields are being received in decimal and exponential formats, so I am attempting to modify the excel column datatype to Text by default when downloading the Excel file using the code snippet below:

this.headers[0] = ['Name', 'Mobile','Time','Date']

const ws = XLSX.utils.aoa_to_sheet(this.headers);
const wb: XLSX.WorkBook = XLSX.utils.book_new();

var range = XLSX.utils.decode_range(ws['!ref']);
for (var r = range.s.r; r <= range.e.r; r++) {
  for (var c = range.s.c; c <= range.e.c; c++) {
    var cellName = XLSX.utils.encode_cell({ c: c, r: r });
  }
}

XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');

wb.Sheets['Sheet1']['B1'].z = 'Text';

wb.Sheets['Sheet1']['C1'].z = 'Text';

wb.Sheets['Sheet1']['D1'].z = 'Text';

XLSX.writeFile(wb, 'Sample.xlsx');

Despite using the above code, I am unable to change the column datatype to TEXT, and I am uncertain if what I am expecting is achievable. Any suggestions would be greatly appreciated. Thank you.

Answer №1

For those looking to input a number as text in an excel sheet, simply follow these steps:

var fmt = '@'; 
then use fmt instead of 'Text' like this : 

wb.Sheets['Sheet1']['B1'].z = fmt;

If this solution works for you, feel free to reach out and let me know.

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

Is there a way to bypass the default layout on app router in Next.js and implement our own custom page layout

Utilizing a default layout in layout.jsx, I passed all my other pages as children through props. In the page router, we typically configure the router path to specify which layout to use. However, in this new system, I am facing challenges with coding it. ...

I'm having trouble accessing the data stored in req.user within the user controller, despite having integrated it into the user isLoggedIn middleware

I am encountering an issue where I cannot access my req.user in the usercontroller, even though I have implemented it in the usermiddleware. Both storing data in req.user and retrieving data using req.user from the middleware to my controller are not work ...

Utilize Page.evaluate() to send multiple arguments

I am facing an issue with the Playwright-TS code below. I need to pass the email id dynamically to the tester method and have it inside page.evaluate, but using email:emailId in the code throws an undefined error. apiData = { name: faker.name.firstNa ...

Having trouble with the onChange function within the rc-field-form wrapper

I created a wrapper for the Field component from the rc-field-form package as shown below: import * as React from "react"; import Form from "rc-field-form"; import type { FieldProps } from "rc-field-form/lib/Field"; const { F ...

The discord.js argument for startsWith should not be a standard regular expression

What could be the reason behind this not working as expected? I am trying to check if a string starts with a number, and furthermore, I want it to handle multiple numbers. For instance, if the string starts with 1259823 then execute this code. I assume t ...

What could be the reason for TypeScript throwing an error that 'product' does not exist in type '{...}' even though 'product' is present?

Structure of Prisma Models: model Product { id String @id @default(auto()) @map("_id") @db.ObjectId name String description String price Float image String createdAt DateTime @default(now()) updatedAt Da ...

Issue with relative templateUrl in Angular 2 not resolving paths

As I embark on creating my first Angular 2 app, I'm faced with the task of setting my template in an HTML file using `templateUrl`. Currently, both the component.ts and view.html are stored in the same folder under src/ directory. Here's what I ...

Retrieving Data from a Nested JSON Array

How do I modify my JavaScript code to extract the last 3 values from the JSON list provided below? The current code is unable to read these values with different formatting. Example section of the JSON list: {...... 'Design_Lump_Sum': {0: {&a ...

Angular encountered an ERROR of type TypeError where it cannot access properties that are undefined when trying to read the 'title'

I designed a form and I am trying to save the information entered. However, when I attempt to use the save method, an error keeps popping up. How can I troubleshoot this issue and successfully save the data from the form? ...

Calculate the total length of the nested arrays within an object

Check out this object: const obj = { name: "abc", arr: [{ key1: "value1", arr1: [1, 2, 3] }, { key1: "value2", arr1: [4, 5, 6] }] } I'm looking to find a way to quickly calculate the sum of lengths of arrays arr1 and arr2. ...

Issue with publishing npm package using yarn package manager

I'm currently in the process of releasing a fresh package. Utilizing ES6, I've been transpiling my files through babel to start with. However, I've hit a roadblock at this particular stage: https://i.stack.imgur.com/iIVp6.png This part se ...

Is there any importance to port 9229 and is it possible to modify it?

In my initial training, it was always recommended to run a local Node server on port 3000. However, after learning about the Chrome Node debugger in a tutorial that uses port 9229, I decided to switch to this port. For more information on port 3000, you ...

The issue of saving Rails input from an Angular2 front end has been causing some trouble

Currently, I am in the process of developing a front-end application using Angular 2 that retrieves data from a Rails 5 API. This specific application serves as a network inventory tool. One particular feature of this app is an Asset-form in Angular2 whic ...

The jQuery $.ajax request is still in a pending state

I've developed a straightforward chat application that utilizes the long-polling method with jQuery. function sendchat(){ // This function sends the message $.ajax({ url: "send.php", async: true, data: { /* insert inputbox1.value */ }, succe ...

Sharing controller methods in Angular.js is a key aspect of enhancing

In my current project, I originally used Knockout for the CMS functionality, but decided to switch to Angular because I preferred its features. One of the key sections in the CMS is dedicated to 'Users', featuring a table where headers can be cli ...

Vue.js numerical input module

My approach involves utilizing Numeral.js: Vue.filter('formatNumber', function (value) { return numeral(value).format('0,0.[000]') }) Vue.component('input-number', { templa ...

I am experiencing an issue with the Jquery Datepicker not appearing within a Bootstrap modal pop-up in an ASP

The Jquery Date function is not displaying in the popup model. Here is the code I am using: <div class="modal fade" id="DateModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-di ...

Is there a method to redirect and display a JavaScript message efficiently?

Once the user has updated a record, I want to automatically redirect them to another page where they will be notified with a JavaScript message (alertify.notify()) confirming that the update was successful. I am unsure if it's possible to dynamically ...

Is Ajax failing to function correctly?

Below is the AJAX code snippet that I am working with: $('.AllTaskDownloadButton').on('click', '.CheckBoxesForDownload', function(){ var n = $( "input:checked.CheckBoxesForDownload" ).length; var arr=[] for(i=0;i ...

Transferring files using jQuery and AJAX technology

Hey there! I'm trying to transfer files to and from a custom Java server that uses outputstream for sending and receiving files in byte arrays. I'm wondering if there's a similar method to split a file into byte arrays using jQuery and send ...