9
Views
1
Comments
How to paste date from clipboard or copied data from excel
Question
Application Type
Reactive

Hello All,

I'm developing reactive web app.

I'm trying to paste copied data from excel.  I'm able to paste text and numbers but unable to paste Date .
can someone help me here to resolve this issue.


I'm using below JavaScript:



Regards.

Hello,

You have to do some additional manipulation to correctly parse the date. Here's an example:

navigator.clipboard.readText().then((clipText) => {
    var values = clipText.split('\t');
    var dateParts = values[2].split('/');    

    $parameters.Number = parseInt(values[0]);
    $parameters.Text = values[1];
    $parameters.Date = new Date(dateParts[2], dateParts[1] - 1, dateParts[0]);
    $resolve();
});

Some important notes:

  • This example assumes you have an Excel sheet with 3 columns:
    • Column 1: Number value
    • Column 2: Text value
    • Column 3: Date value
  • You might have to adjust the date parsing according to the Date format you're using in Excel. In my example, the assumed format is DD/MM/YYYY.
  • When creating the new date, you always need to specify Month - 1. This is because JavaScript counts months from 0.
  • In my example, I created 3 output parameters with the expected data types. So Number, Text and Date. You can then assign the value of these output parameters to your local variables.
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.