2013年4月7日日曜日

google spreadsheetに秒数計算関数

google spreadsheetにUNIX秒を挿入したかったので、取り組み。

以下のページの記述が役に立った。google spreadsheetでは、script editorでjsコードを書けて、それをspreadsheet上で関数を実行できることを改めて再認識。
http://productforums.google.com/forum/#!topic/docs/rPf3kgv6OZU
To create a "timestamp" formula, you can write your own custom timestamp() function and then have it update based on when the contents of another cell are modified.
1. Tools > Scripts > Script Editor2. Paste the following code:
function timestamp() {
return new Date()
}
3. Save and go back to your Spreadsheet
Let's say you want a timestamp in cell B1 whenever cell A1 is updated...
In cell B1 put the forumla =TIMESTAMP(A1)
*** However, this will show a timestamp even if cell A1 is blank.  To only show a timestamp when a cell has content, use this formula:
=IF(ISBLANK(A1),,TIMESTAMP(A1))
Hope this helps! 
で、自分が書いたスクリプトが以下。
function timestamp(a,b,c ,d) { var now=new Date(a,b,c,d); var time=now.getTime(); return time }
年月日時間の四要素から、秒を取得する必要があったので、上記のような感じで。

便利なり、google spreadsheet !

2013年4月5日金曜日

innerHTMLはonload後の処理


innerHTMLを使ってみたら、適用されないので、不思議に思い、
調べたら、
onloadされた後に適用される、と分かった。
onloadされた後の処理に突っ込まないと適用されないinnerHTML。
理解しました。