⭕ まず、信頼するサイトに localhost( またはイントラネットのサーバ ) を登録します。⭕ レベルのカスタマイズで『スクリプトを実行しても安全だとマークされていないActiveX コントロール』を『有効』にします。
▼ 以下の .reg ファイルをエクスプローラからダブルクリックしてインポートする事もできます
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2] "1201"=dword:00000000
▼ .reg ファイルをダウンロード その上で以下のコードを localhost で実行が可能です。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-type" content="text/html; charset=shift_jis">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
// *************************************
// IE 用オブジェクト作成関数
// *************************************
function newObject( className ) {
var obj;
try {
obj = new ActiveXObject( className );
}
catch (e) {
obj = null;
}
return obj;
}
// *************************************
// Excel 用オブジェクト 格納変数
// *************************************
var excelApp = null;
var myBook = null;
// *************************************
// Exce ブックを読み込んで更新して終了
// *************************************
function excelTest() {
// Excel オブジェクト作成
if ( excelApp == null ) {
excelApp = newObject("Excel.Application");
}
// Excel ブックの読み込み
myBook = excelApp.Workbooks.Open("C:\\Users\\lightbox\\Documents\\Book1.xlsx");
// アクティブなウィンドウを最大化
excelApp.ActiveWindow.WindowState = 2;
// 表示時様態にする
excelApp.Visible = true;
// jQuery でオブジェクトの一覧を取得して Excel のセルに情報をセットする
var row = 0;
$.each( window.navigator, function( key, value ){
row++;
// シートのセルに書き込み
myBook.Sheets("Sheet1").Cells(row, 1) = key;
myBook.Sheets("Sheet1").Cells(row, 2) = typeof value;
myBook.Sheets("Sheet1").Cells(row, 3) = value;
});
// 保存
myBook.Save();
// Excel の終了
if ( excelApp != null ) {
excelApp.Quit();
excelApp = null;
}
}
</script>
</head>
<body>
<input id="export" type="button" value="Excel のテスト" onclick="excelTest();">
</body>
</html>
⭕ レベルのカスタマイズで『スクリプトを実行しても安全だとマークされていないActiveX コントロール』を『有効』にします。
▼ 以下の .reg ファイルをエクスプローラからダブルクリックしてインポートする事もできます