2019年10月4日金曜日

シート保護掛けたが、パスワードを忘れてしまいました?ハッキング方法

下記のソースコードを解除したいシートにコピーして、実行するだけ…
Sub PasswordBreaker()
Dim i As Integer, j As Integer, k As Integer
Dim l As Integer, m As Integer, n As Integer
Dim i1 As Integer, i2 As Integer, i3 As Integer
Dim i4 As Integer, i5 As Integer, i6 As Integer
On Error Resume Next
For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
ActiveSheet.Unprotect Chr(i) & Chr(j) & Chr(k) & _
Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
If ActiveSheet.ProtectContents = False Then
MsgBox "One usable password is " & Chr(i) & Chr(j) & _
Chr(k) & Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & _
Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
Exit Sub
End If
Next: Next: Next: Next: Next: Next
Next: Next: Next: Next: Next: Next
End Sub
ここ参照

2019年10月1日火曜日

javascriptで月末日を求める

12+1=13になるけど、そこも問題ないみたい、0が1月らしい

var n = new Date('2019-12-01')
var m = new Date(n.getFullYear(),n.getMonth()+1,0);
console.log(m);

> Tue Dec 31 2019 00:00:00 GMT+0900 (日本標準時)

2019年7月10日水曜日

sql DATE_ADD

select DATE_ADD('2019-01-31', INTERVAL + 1 MONTH);
2019-02-28

select DATE_ADD('2019-01-30', INTERVAL + 1 MONTH);
2019-02-28

select DATE_ADD('2019-01-29', INTERVAL + 1 MONTH);
2019-02-28

select DATE_ADD('2019-01-28', INTERVAL + 1 MONTH);
2019-02-28

select DATE_ADD('2019-01-27', INTERVAL + 1 MONTH);
2019-02-27

2019年7月2日火曜日

2019年7月1日月曜日

vlookupではできない、範囲指定のカスタマイズ関数

Function vlookups(val As Range, min As Range, max As Range, col As Range) As String
Dim cl As Range
For Each cl In min
    If val.Value >= cl.Value And val.Value <= cl.Worksheet.Cells(cl.Row, max.Column) Then
        vlookups = cl.Worksheet.Cells(cl.Row, col.Column)
        Exit For
    End If
Next
End Function
使い方: =vlookups(E4,$A$1:$A$4,$B$1:$B$4,$C$1:$C$4) 結果:

2019年5月24日金曜日

G Suiteのバグ?仕様?

G Suiteのバグ?仕様?
Steps:
1.グループメールabc@xxx.comを作成
2.xyz@xxx.comの個人メールのGmail設定から、「アカウント追加」して、abc@xxx.comから送信できるように登録
3.グループメールabc@xxx.comを削除
4.アカウントabc@xxx.comを作成します
結果:
xyz@xxx.comがabc@xxx.comのパスワードを知らなくでも、abc@xxx.comが送信者として送信できる。
但しabc@xxx.comアカウントの送信済みには残りません。
abc@xxx.comの受信もxyz@xxx.comの受信されません。

ややこしいけど、これは仕様ですかバグですか?

2019年5月10日金曜日

令和数式を置換してくれる自作関数

ポイントは正規表現のReplaceで、パターン化して一致されたセルの番地を更にReplaceに使ったこと。「$1」を使って一個目のマッチングを引用すること。
Option Explicit
Public Const REIWA = "IF(_CELL_>=DATE(2019,5,1),""令和""&IF(YEAR(_CELL_)-2018=1,""元"",YEAR(_CELL_)-2018)&""年""&MONTH(_CELL_)&""月""&DAY(_CELL_)&""日"",TEXT(_CELL_,""ggge年m月d日""))"
Function reiwa_switch(strFormual, strCellAddr As String) As String

Dim reg As Object
Set reg = CreateObject("VBScript.RegExp")
With reg
    .Pattern = "TEXT\((" & strCellAddr & "),""ggge年m月d日""\)"
    .IgnoreCase = False
    .Global = True
End With
reiwa_switch = reg.Replace(strFormual, Replace(REIWA, "_CELL_", "$1"))
End Function

=reiwa_switch(A1,A2)→関数


TEXT(data!FU3,"ggge年m月d日")→第一引数(A1)
data!FU3→第二引数(A2)
IF(data!FU3>=DATE(2019,5,1),"令和"&IF(YEAR(data!FU3)-2018=1,"元",YEAR(data!FU3)-2018)&"年"&MONTH(data!FU3)&"月"&DAY(data!FU3)&"日",TEXT(data!FU3,"ggge年m月d日"))→結果

2019年4月3日水曜日

【新年号】令和元年、エクセル数式での対応方法


=IF(D1>=DATE(2019,5,1),"令和"&IF(YEAR(D1)-2018=1,"元",YEAR(D1)-2018)&"年"&MONTH(D1)&"月"&DAY(D1)&"日",TEXT(D1,"ggge年m月d日"))

※数式の中の「D1」は実際日付が書いてあるセルです、そこは適当に変更してください。
※「令和元年」ではなく「令和1年」として表示したければ、「IF(YEAR(D1)-2018=1,"元",」を削除し、「-2018)&"年"」の中の「)」も削除すればOK

2019年3月29日金曜日

PHPでCSVを読み込んで、Arrayに変換するメソッド、最初の行を横方向連想配列のキーとするや、縦方向のid列を指定するや、一部の列のみ抽出するとか、機能盛りだくさん

/* $csvPath: CSV file path
  * $firstRowAsKey: whether make the first row as key horizontally. or just number, duplicate will not be over writed
  * $columnAsKey: whether to set key(column name or column index) column vertically. or just number, duplicate will not be over writed
  * $columnAsVal: Array or Single Column name or column index from 0, whether to filte columns
  * $smartFlat:if horizontally array only have one key, then falt it.
  *
  * For Example: CSV(this methord will take care of sjis utf8 encode problem)
  * name,point
  * Joe,2
  * Peter,321
  * Jane,34
  *
  * $firstRowAsKey = true, $columnAsKey = null, $columnsAsVal = null
  * Array([0] => Array([name] => Joe, [point] => 2), [1] => Array([name] => Peter,[point] => 321), [2] => Array([name] => Jane, [point] => 34))
  *
  * firstRowAsKey = false, $columnAsKey = 0, $columnsAsVal = null
  * Array([name] => Array([0] => name, [1] => point), [Joe] => Array([0] => Joe, [1] => 2), [Peter] => Array([0] => Peter, [1] => 321), [Jane] => Array([0] => Jane, [1] => 34))
  *
  * firstRowAsKey = true, $columnAsKey = 'name', $columnsAsVal = point
  * Array([Joe] => Array([point] => 2), [Peter] => Array([point] => 321), [Jane] => Array([point] => 34))
  */
 function readArrayCSV($csvPath, $firstRowAsKey = true, $columnAsKey = null, $columnsAsVal = null, $smartFlat = true) {
  $sjis = file_get_contents($csvPath);
  $utf8 = mb_convert_encoding($sjis, 'UTF-8', 'SJIS-win');
  $temp = tempnam(sys_get_temp_dir(), 'TMP_');
  file_put_contents($temp, $utf8);
  $csv = file($temp, FILE_IGNORE_NEW_LINES);

  if ($firstRowAsKey) {
   $titles = explode(",", array_shift($csv));
   $csv = array_map('str_getcsv', $csv);
   $csv = array_map(function ($row) use ($titles) {
       return array_combine($titles, $row);
   },$csv);
  } else {
   $csv = array_map('str_getcsv', $csv);
  }

  if ($columnAsKey !== null) {
   $result = array();
   if (is_int($columnAsKey) && $columnAsKey > 0) $columnAsKey--;
   foreach ($csv as $row) {
    if (isset($row[$columnAsKey])) {
     $row_filtered = $row;
     if ($columnsAsVal !== null) {
      $row_filtered = array_intersect_key($row, array_flip((array)$columnsAsVal));
     }
     $result[$row[$columnAsKey]] = ($smartFlat?(count($row_filtered) == 1?array_shift(array_values($row_filtered)):$row_filtered):$row_filtered);
    }
   }

  } else {
   $result = $csv;
  }
  return $result;
 }

2019年3月25日月曜日

mysql グループ毎、最初のレコードを取得 Select first recorder in every group

方法1:

SELECT * FROM
(
SELECT * FROM `table`
ORDER BY AnotherColumn
) t1
GROUP BY SomeColumn
;





方法2:

SELECT somecolumn, anothercolumn
FROM sometable
WHERE id IN (
SELECT min(id)
FROM sometable
GROUP BY somecolumn
);