サーバレス練習帳

着眼大局着手小局

DataTablesの絞り込みオプション

[searchbuilder]
対象と条件を入力して自分で検索条件を組む。
https://datatables.net/extensions/searchbuilder/examples/initialisation/simple.html

[searchpanes]
あらかじめ絞込の選択肢が表示されている。
サンプル1
https://datatables.net/extensions/searchpanes/examples/customisation/verticalPanes.html
サンプル2
https://datatables.net/extensions/searchpanes/examples/initialisation/collapse.html

AWS Lambda / pythonで直接のエクセルファイルアップロードを受け取りパースする

import json
import boto3
import openpyxl
import base64
from io import BytesIO
from openpyxl import load_workbook

def lambda_handler(event, context):
    #test1()
    #return {'statusCode': 200, 'body' :  'OK2!'}

    if 'elb' in event['requestContext']:
        access_type = 'from_elb'
        if 'HealthChecker'in event['headers']['user-agent']:
            print('HealthChecker')
            return {'statusCode': 200, 'body' :  'OK!'}
            
    elif 'local' in event['requestContext']:
        access_type = 'local'
    else:
        access_type = 'from_http_lambda'

    print(access_type)
    print(json.dumps(event))
    # リクエストボディからエクセルファイルの情報を取得
    if 'body' in event:
        body = event['body']
    
        # base64デコード
        excel_data = base64.b64decode(body)
        
        # BytesIOを使ってメモリ上でエクセルファイルを開く
        excel_file = BytesIO(excel_data)
        
        # openpyxlでワークブックをロード
        wb = load_workbook(excel_file, read_only=True, data_only=True)
    
        ws = wb.active
        cell_value = ws['A1'].value
        print(cell_value)    
        return {'statusCode': 200, 'body' :  cell_value}
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <title>Excel Upload</title>
</head>
<body>
    <h1>Upload Excel File2</h1>
    <input type="file" id="fileInput" accept=".xlsx">
    <button id="uploadButton">Upload</button>
    <script>
        document.getElementById('uploadButton').addEventListener('click', async () => {
            alert('OK!');
            const fileInput = document.getElementById('fileInput');
            const file = fileInput.files[0];
            if (file) {
                const formData = new FormData();
                formData.append('file', file);
                
                try {
                    const response = await fetch('http://10.9.60.165/', {
                        method: 'POST',
                        body: formData
                    });
                    const result = await response.json();
                    console.log('Result:', result);
                } catch (error) {
                    console.error('Error:', error);
                }
            } else {
                alert('Please select a file first.');
            }
        });
    </script>
</body>
</html>