<%@ page import="java.io.*, java.util.zip.*" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.StringUtil" %>
<%@ page import="com.weaver.general.BaseBean" %>
<%@ page import="weaver.hrm.company.DepartmentComInfo" %>
<%@ page import="org.apache.poi.xssf.usermodel.XSSFWorkbook" %>
<%@ page import="km.org.apache.poi.ss.util.WorkbookUtil" %>
<%@ page import="org.apache.poi.ss.usermodel.Workbook" %>
<%@ page import="org.apache.poi.ss.usermodel.Sheet" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.poi.ss.usermodel.Row" %>
<%@ page import="org.apache.poi.ss.usermodel.Cell" %>
<%@page contentType="text/html; charset=UTF-8" %>

<%
    // Sample data
    List<List<String>> data = new ArrayList<>();
    // data.add(Arrays.asList("Header1", "Header2", "Header311"));
    // data.add(Arrays.asList("Row1Col1", "Row1Col2", "Row1Col3"));
    // data.add(Arrays.asList("Row2Col1", "Row2Col2", "Row2Col3","任广鹏"));
    RecordSet rs1 = new RecordSet();
    RecordSet rs2 = new RecordSet();

    rs1.executeQuery("SELECT requestid ,requestname " +
            "   FROM workflow_requestbase " +
            "   WHERE workflowid IN (SELECT id FROM workflow_base WHERE ACTIVEVERSIONID = 471");

    // Create a workbook and a sheet
    Workbook workbook = new XSSFWorkbook();
    String safeSheetName = WorkbookUtil.createSafeSheetName("Sheet1");
    Sheet sheet = workbook.createSheet(safeSheetName);

    // Populate the sheet with data
    for (int i = 0; i < data.size(); i++) {
        Row row = sheet.createRow(i);
        List<String> rowData = data.get(i);
        for (int j = 0; j < rowData.size(); j++) {
            Cell cell = row.createCell(j);
            cell.setCellValue(rowData.get(j));
        }
    }

    int i = 0;
    while (rs1.next()){
        Row row = sheet.createRow(i);
        String requestid = rs1.getString("requestid");
        String requestname = rs1.getString("requestname");
        rs2.executeQuery("");

    }

    // Set the response headers
    response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    response.setHeader("Content-Disposition", "attachment; filename=\"export.xlsx\"");

    // Write the workbook to the response output stream
    try (OutputStream outt = response.getOutputStream()) {
        workbook.write(outt);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        workbook.close();
    }


%>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Export Excel</title>
</head>
<body>
<h1>Excel file should start downloading automatically...</h1>
</body>
</html>

