I am trying to access values in Excel plugin via Officejs.
Office.context.document.getSelectedDataAsync(
Office.CoercionType.Matrix,
function(asyncResult => ...)
What I am looking for is an automatic way to access date values in their raw format without deduction if it is a date (initially, they are in Excel-like format, represented by a number of days after 01/01/1900).
Text of callback, but I can't find any interface to use so far.
Office.context.document.getSelectedDataAsync(zone, options, callback) returns numbers in all the cases.
You may try to get the value by using range.values API, then use setNumberFormat("dd/MM/yyyy") to set it into time format.
Related
I have a column which consists of a date-time value 'for example: 2017-2-2 10:30:20'. I want this rows used as an input to Date Range Filter in Google chart.
How can this be created? I have tried using an array of that column values, but that doesn't worked for me.
Google's just using the standard javascript Date object. Easier method would be to get a unix_timestamp(yourdatefield) out of MySQL, which gives you seconds-since-the-epoch.
(example) mysql> SELECT UNIX_TIMESTAMP('2015-11-13 10:20:19');
-> 1447431619
Javascript's date object accepts milliseconds-since-the-epoch as one initializer value, so:
data.addRow(new Date(<?php echo ($seconds_from_db) ?>000));
^^^--- 3 extra zeroes to make it a millisecond value
To use the unix_timestamp command
select unix_timestamp(yourfield) as seconds
I've found partial solutions but retrieving the date from a SharePoint list adds one more level of fun. The code I've got which is returning NaN is:
var LifeCycleStart = new Date(item.DeviceAvailableFrom);
Obviously the SharePoint column is DeviceAvailableFrom.
I'm not familiar with Sharepoint, but I'd first check that the value of item.DeviceAvailableFrom is either a positive integer, or a string containing a date that Date's constructor is able to parse.
With libary moment there is option to bring a array of formating options and momentjs use the best match for parsing the input.
For Example:
var date = moment("29-06-1995", ["MM-DD-YYYY", "DD-MM", "DD-MM-YYYY"]);
but what if I want the take the same format that using in parsing for output formating.
var dateText = date.format('selected parse')
How do I know which format moment choose to use?
Currently there is no exposed function for getting the chosen format, however there is a "private" field named _f that contains this information.
var m = moment("29-06-1995", ["MM-DD-YYYY", "DD-MM", "DD-MM-YYYY"]);
m._f // "DD-MM-YYYY"
If you use this, be careful when updating versions of moment. Private fields are not guaranteed to be maintained, and could break between versions.
I've logged this as a feature request for future moment.js functionality.
I am working on a parse (Facebook) app. I have a table however I want to be able to get the expired events (aka events that occur after some date). What is the best way to do this. I didn't see a date documentation with Parse.
My thought from dynamo experience was to simply save it and compare the values but this is costly. Is there a more efficient way?
Any ideas / anyone done this?
Thanks!
Just use the greaterThan, greaterThanOrEqualTo, lessThan and lessThanOrEqualTo methods on Parse.Query, and pass in date objects.
I.e.
var query = new Parse.Query("Event");
query.lessThan("eventDate", new Date());
This query will get you all objects from the table "Event", whose column "eventDate" (a Date column) contains a date that is before the current date.
I'm trying to convert an HTML table to Excel in Javascript using new ActiveXObject("Excel.application"). Bascially I loop through table cells and insert the value to the corresponding cell in excel:
//for each table cell
oSheet.Cells(x,y).value = cell.innerText;
The problem is that when the cell is in date format of 'dd-mm-yyyy' (e.g. 10-09-2008), excel would read as 'mm-dd-yyyy' (i.e. 09 Oct 2008). I tried to specify NumberFormat like:
oSheet.Cells(x,y).NumberFormat = 'dd-mm-yyyy';
But, it has no effect. It seems that this only affect how excel display the value, not parse. My only solution now is to swap the date like:
var txt = cell.innerText;
if(/^(\d\d)-(\d\d)-\d\d\d\d$/.test(txt)) txt = txt.replace(/^(\d\d)-(\d\d)/,'$2-$1');
But, I'm worrying that it is not generic and a differnt machine setting would fail this.
Is there a way to specific how excel parse the input value?
You can avoid Excel's date parsing by entering the data using its native 'serial' date format. e.g '22nd Dec 08' is 39804 as an Excel serial date. (See here for a good explanation of these)
Then format the cell as you did before.
determine what culture-neutral date formats excel supports
use javascript to parse your date string and output in the an appropriate format
I don't know what formats excel supports but you'd want something like .net's round trip or sortable formats, where it will always be read consistently.
for #2, if you can trust javascript to construct an appropriate date from whatever string you feed it that's fine. if you're not sure about that you might look at a library like datejs where you can be more specific about what you want to happen.
Instead of
oSheet.Cells(x,y).NumberFormat = 'dd-mm-yyyy';
set this:
oSheet.Cells(x,y).NumberFormat = 14;
In Vbscript, we use to resolve this by
If IsDate ( Cell.Value ) Then
Cell.Value = DateValue ( Cell.Value )
End If
Maybe, In java script also you need to play with same approach.
I've tried your code but at end of the process, I re-applied format to the columns containing dates. It works fine, no matter what local language you have configurated yor machine.
Being my excel object defined as 'template', as soon as I got it data filled, I applied (just for example):
template.ActiveSheet.Range("D10:F99").NumberFormat = "dd/MMM/yyyy;#";
best regards