Example usage for org.apache.poi.hssf.usermodel HSSFWorkbook createCellStyle

List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook createCellStyle

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFWorkbook createCellStyle.

Prototype

@Override
public HSSFCellStyle createCellStyle() 

Source Link

Document

Create a new Cell style and add it to the workbook's style table.

Usage

From source file:com.aimluck.eip.modules.screens.AddressBookXlsExportScreen.java

License:Open Source License

private void setupAddressBookSheet(RunData rundata, Context context, HSSFWorkbook wb) throws Exception {

    AddressBookFilterdSelectData listData;
    listData = new AddressBookFilterdSelectData();

    listData.initField();// w  w w. j  a  v a 2s  .co  m
    listData.setRowsNum(1000);
    listData.doSelectList(this, rundata, context);

    String sheet_name = "";
    // ?
    String[] headers = { "???", "???", "", "?",
            "??", "?", "??", "???" };
    // 01
    short[] cell_enc_types = { HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16,
            HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16,
            HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16 };
    HSSFSheet sheet = createHSSFSheet(wb, sheet_name, headers, cell_enc_types);

    int rowcount = 0;

    // ?
    HSSFCellStyle style_col = wb.createCellStyle();
    style_col.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
    style_col.setAlignment(HSSFCellStyle.ALIGN_JUSTIFY);

    int listsize = listData.getCount();
    AddressBookResultData rd;
    for (int j = 0; j < listsize; j++) {
        rd = (AddressBookResultData) listData.getList().get(j);
        String[] rows = { rd.getName().getValue(), rd.getNameKana().getValue(), rd.getEmail().getValue(),
                rd.getTelephone().getValue(), rd.getCellularPhone().getValue(), rd.getCellularMail().getValue(),
                rd.getCompanyName().getValue(), rd.getPositionName().getValue() };

        rowcount = rowcount + 1;
        addRow(sheet.createRow(rowcount), cell_enc_types, rows);
    }

    int uid = ALEipUtils.getUserId(rundata);
    ALEventlogFactoryService.getInstance().getEventlogHandler().logXlsScreen(uid, "",
            163/* ALEventlogConstants.PORTLET_TYPE_ADDRESSBOOK_XLS_SCREEN */);
}

From source file:com.aimluck.eip.modules.screens.ExtTimecardNewXlsExportScreen.java

License:Open Source License

private void setupTimecardSheet(RunData rundata, Context context, HSSFWorkbook wb) throws Exception {

    ExtTimecardSelectData listData = new ExtTimecardSelectData();
    listData.initField();//from   w  w w  .  j  a  va  2s. c om
    listData.setRowsNum(1000);
    listData.doViewList(this, rundata, context);

    String sheet_name = "";
    // ?
    String[] headers = { "???", "", "", "", "", "",
            "", "", "", "??",
            "?", "", "", "?",
            "?", "?", "", "?", "",
            "", "", "", "???", "?", "",
            "", "", "", "", "", "", "",
            "", "", "" };
    // 01
    short[] cell_enc_types = { HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16,
            HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16,
            HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC,
            HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC,
            HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC,
            HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC,
            HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC,
            HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.ENCODING_UTF_16,
            HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16,
            HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16,
            HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16,
            HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16 };
    HSSFSheet sheet = createHSSFSheet(wb, sheet_name, headers, cell_enc_types);

    int rowcount = 0;

    // ?
    HSSFCellStyle style_col = wb.createCellStyle();
    style_col.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
    style_col.setAlignment(HSSFCellStyle.ALIGN_JUSTIFY);

    String user_name = ALEipUtils.getUserFullName(Integer.parseInt(listData.getTargetUserId()));// ???
    String system_name = ExtTimecardUtils
            .getEipTExtTimecardSystemByUserId(Integer.parseInt(listData.getTargetUserId())).getSystemName();

    ExtTimecardListResultDataContainer container = ExtTimecardUtils.groupByWeek(listData.getQueryStartDate(),
            listData.getAllList(), null);
    container.calculateWeekOvertime();

    ExtTimecardListResultData tclistrd = null;
    List<ExtTimecardListResultData> daykeys = listData.getDateListKeys();
    int daykeysize = daykeys.size();
    for (int i = 0; i < daykeysize; i++) {
        tclistrd = daykeys.get(i);
        tclistrd.setWeekOvertime(container.getWeekOvertime(tclistrd));
        tclistrd.setStatutoryHoliday(container.isStatutoryOffDay(tclistrd));
        tclistrd.calculateWeekOvertime();

        String date = "";// 
        String day = ""; // 
        String service_form = system_name; // 
        String clock_in_time = "";// 
        String clock_out_time = "";// 
        String work_day = "0"; //  0 or 1
        String work_hour = "0";// 
        String overtime_day = "0";// 
        String overtime_hour = "0";// 
        String overtime_within_statutory_working_hour = "0";// 
        String off_day = "0";// 
        String off_hour = "0";// 
        String late_coming_day = "0";// ?
        String early_leaving_day = "0";// 
        String absent_day = "0";// 
        String paid_holiday = "0";// 
        String compensatory_holiday = "0";// 
        String other_day = "0";// ???
        String remark = "";// 
        String reason = "";// ?
        String official_off_day = "0", statutory_off_day = "0";
        String total_work_hour = "0";
        String midnight_work_hour = "0", midnight_overtime_hour = "0";
        String statutory_off_day_regular_work_hour = "0", statutory_off_day_overtime_hour = "0",
                statutory_off_day_midnight_work_hour = "0", statutory_off_day_regular_midnight_work_hour = "0",
                statutory_off_day_within_statutory_overtime_hour = "0";
        String off_day_regular_work_hour = "0", off_day_overtime_hour = "0", off_day_midnight_work_hour = "0",
                off_day_regular_midnight_work_hour = "0", off_day_within_statutory_overtime_hour = "0";
        String total_off_day_work_hour = "0", total_statutory_off_day_work_hour = "0";
        String total_midnight_work_hour = "0";
        String rest_hour = "0";
        String[] out_going = new String[EipTExtTimecard.OUTGOING_COMEBACK_PER_DAY];// 
        String[] come_back = new String[EipTExtTimecard.OUTGOING_COMEBACK_PER_DAY];// 

        if (tclistrd.getRd() == null) {

            // ExtTimecardResultData rd = tclistrd.getRd();

            date = tclistrd.getDateStr("yyyy/MM/dd");
            day = tclistrd.getDateStr("EE");
        } else {

            ExtTimecardResultData rd = tclistrd.getRd();

            // ExtTimecardSummaryResultData srd = tclistrd.get

            date = tclistrd.getDateStr("yyyy/MM/dd");
            day = tclistrd.getDateStr("EE");
            String type = rd.getType().toString();
            if (!rd.getIsNullClockInTime()) {
                clock_in_time = rd.getClockInTime("HH:mm");
                clock_out_time = rd.getClockOutTime("HH:mm");
                if (tclistrd.getWorkHour() != ExtTimecardListResultData.NO_DATA) {
                    work_day = "1";
                    work_hour = Float.toString(tclistrd.getWorkHour());
                } else {
                    work_hour = "0";
                }
                if (tclistrd.getOvertimeHourWithoutRestHour() > 0.0) {
                    overtime_day = "1";
                    overtime_hour = Float.toString(tclistrd.getOvertimeHourWithoutRestHour());
                } else {
                    overtime_hour = "0";
                }
                /**  */
                if (tclistrd.getWithinStatutoryOvertimeWorkHourWithoutOffday() > 0.0) {
                    overtime_within_statutory_working_hour = Float
                            .toString(tclistrd.getWithinStatutoryOvertimeWorkHourWithoutOffday());
                }
                if (tclistrd.getOffHour() > 0.0) {
                    off_day = "1";
                    // ???
                    if (container.isStatutoryOffDay(tclistrd)) {
                        total_statutory_off_day_work_hour = Float.toString(tclistrd.getTotalWorkHour());
                        statutory_off_day = "1";
                        statutory_off_day_regular_work_hour = Float.toString(tclistrd.getInworkHour());
                        statutory_off_day_overtime_hour = Float.toString(tclistrd.getOvertimeHour());
                        statutory_off_day_midnight_work_hour = Float
                                .toString(tclistrd.getMidnightOvertimeWorkHour());
                        statutory_off_day_regular_midnight_work_hour = Float
                                .toString(tclistrd.getMidnightRegularWorkHour());
                        if (tclistrd
                                .getWithinStatutoryOvertimeWorkHour() != ExtTimecardListResultData.NO_DATA) {
                            statutory_off_day_within_statutory_overtime_hour = Float
                                    .toString(tclistrd.getWithinStatutoryOvertimeWorkHour());
                        }
                    } else {
                        total_off_day_work_hour = Float.toString(tclistrd.getTotalWorkHour());
                        official_off_day = "1";
                        off_day_regular_work_hour = Float.toString(tclistrd.getInworkHour());
                        off_day_overtime_hour = Float.toString(tclistrd.getOvertimeHour());
                        off_day_midnight_work_hour = Float.toString(tclistrd.getMidnightOvertimeWorkHour());
                        off_day_regular_midnight_work_hour = Float
                                .toString(tclistrd.getMidnightRegularWorkHour());
                        if (tclistrd
                                .getWithinStatutoryOvertimeWorkHour() != ExtTimecardListResultData.NO_DATA) {
                            off_day_within_statutory_overtime_hour = Float
                                    .toString(tclistrd.getWithinStatutoryOvertimeWorkHour());
                        }
                    }
                    off_hour = Float.toString(tclistrd.getOffHour());
                } else {
                    off_hour = "0";
                    /**  */
                    if (tclistrd.getMidnightRegularWorkHour() != ExtTimecardListResultData.NO_DATA) {
                        midnight_work_hour = Float.toString(tclistrd.getMidnightRegularWorkHour());
                    }
                    if (tclistrd.getMidnightOvertimeWorkHour() != ExtTimecardListResultData.NO_DATA) {
                        midnight_overtime_hour = Float.toString(tclistrd.getMidnightOvertimeWorkHour());
                    }
                }
            }
            if (tclistrd.getMidnightWorkHour() > 0.0) {
                total_midnight_work_hour = Float.toString(tclistrd.getMidnightWorkHour());
            }
            if (tclistrd.getTotalWorkHour() > 0.0) {
                total_work_hour = Float.toString(tclistrd.getTotalWorkHour());
            }
            if (rd.getRefixFlag().getValue() == "1") {
                reason = rd.getReason().getValue();
            }
            if (rd.getRemarksFlg()) {
                remark = rd.getRemarks().getValue();
            }
            if (tclistrd.getRestHour() > 0.0) {
                rest_hour = Float.toString(tclistrd.getRestHour());
            }
            late_coming_day = tclistrd.isLateComing() ? "1" : "0";
            early_leaving_day = tclistrd.isEarlyLeaving() ? "1" : "0";
            absent_day = type.equals(EipTExtTimecard.TYPE_ABSENT) ? "1" : "0";
            paid_holiday = type.equals(EipTExtTimecard.TYPE_HOLIDAY) ? "1" : "0";
            compensatory_holiday = type.equals(EipTExtTimecard.TYPE_COMPENSATORY) ? "1" : "0";
            other_day = type.equals(EipTExtTimecard.TYPE_ETC) ? "1" : "0";

            List<Map<String, String>> list = tclistrd.getOutgoingComeback_xls();
            for (int j = 0; j < EipTExtTimecard.OUTGOING_COMEBACK_PER_DAY; j++) {
                Map<String, String> map = list.get(j);
                out_going[j] = map.get("outgoing");
                come_back[j] = map.get("comeback");
            }
        }

        String[] rows = { user_name, date, day, service_form, clock_in_time, clock_out_time, work_day,
                official_off_day, statutory_off_day, total_work_hour, work_hour,
                overtime_within_statutory_working_hour, overtime_hour, total_off_day_work_hour,
                total_statutory_off_day_work_hour, total_midnight_work_hour, rest_hour, late_coming_day,
                early_leaving_day, absent_day, paid_holiday, compensatory_holiday, other_day, reason, remark,
                out_going[0], come_back[0], out_going[1], come_back[1], out_going[2], come_back[2],
                out_going[3], come_back[3], out_going[4], come_back[4] };
        rowcount = rowcount + 1;
        addRow(sheet.createRow(rowcount), cell_enc_types, rows);
    }
    /*
     * rowcount = rowcount + 1; String NOTHING = null; String work_day =
     * "=SUM(G2:G" + rowcount + ")"; String work_hour = "=SUM(H2:H" + rowcount +
     * ")"; String overtime_day = "=SUM(I2:I" + rowcount + ")"; String
     * overtime_hour = "=SUM(J2:J" + rowcount + ")"; String off_day =
     * "=SUM(K2:K" + rowcount + ")"; String off_hour = "=SUM(L2:L" + rowcount +
     * ")"; String late_coming_day = "=SUM(M2:M" + rowcount + ")"; String
     * early_leaving_day = "=SUM(N2:N" + rowcount + ")"; String absent_day =
     * "=SUM(O2:O" + rowcount + ")"; String paid_holiday = "=SUM(P2:P" +
     * rowcount + ")"; String compensatory_holiday = "=SUM(Q2:Q" + rowcount +
     * ")"; String other_day = "=SUM(R2:R" + rowcount + ")"; String[] rows = {
     * NOTHING, NOTHING, NOTHING, NOTHING, NOTHING, NOTHING, work_day,
     * work_hour, overtime_day, overtime_hour, off_day, off_hour,
     * late_coming_day, early_leaving_day, absent_day, paid_holiday,
     * compensatory_holiday, other_day, };
     * 
     * addFooter(sheet.createRow(rowcount), cell_enc_types, rows);
     */

    // 
    int uid = ALEipUtils.getUserId(rundata);
    ALEventlogFactoryService.getInstance().getEventlogHandler().logXlsScreen(uid, "",
            ALEventlogConstants.PORTLET_TYPE_EXTTIMECARD);
}

From source file:com.aimluck.eip.modules.screens.ExtTimecardSummaryNewXlsExportScreen.java

License:Open Source License

private void setupTimecardSheet(RunData rundata, Context context, HSSFWorkbook wb) throws Exception {

    ExtTimecardSummaryListSelectData listData = new ExtTimecardSummaryListSelectData();
    listData.init(this, rundata, context);
    listData.setRowsNum(1000);/*from  w ww . j a  v a2  s.  c  o m*/
    listData.doViewList(this, rundata, context);
    listData.setuserList(target_group_name);

    String sheet_name = "";
    // ?
    String[] headers = { "???", "", "", "", "", "",
            "", "??", "?", "",
            "", "?", "?", "?",
            "", "?", "", "", "", "",
            "???", "" };
    // 01
    short[] cell_enc_types = { HSSFCell.ENCODING_UTF_16, HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC,
            HSSFCell.ENCODING_UTF_16, HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC,
            HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC,
            HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC,
            HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC,
            HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC,
            HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC,
            HSSFCell.CELL_TYPE_NUMERIC };
    HSSFSheet sheet = createHSSFSheet(wb, sheet_name, headers, cell_enc_types);

    int rowcount = 0;

    // ?
    HSSFCellStyle style_col = wb.createCellStyle();
    style_col.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
    style_col.setAlignment(HSSFCellStyle.ALIGN_JUSTIFY);

    ExtTimecardSummaryResultData tclistrd = null;
    List<ExtTimecardSummaryResultData> daykeys = listData.getGroupExtTimecards();
    int daykeysize = daykeys.size();
    for (int i = 0; i < daykeysize; i++) {
        tclistrd = daykeys.get(i);

        String user_name = tclistrd.getUserName();// ???
        String year = view_month.substring(0, 4); // 
        String month = view_month.substring(5); // 
        String service_form = tclistrd.getSystemName();// 
        // 
        String total_work_day = tclistrd.getTotalWorkDay().getValueAsString();
        // 
        String official_off_day = tclistrd.getOfficialOffDay().getValueAsString();
        // 
        String statutory_off_day = tclistrd.getStatutoryOffDay().getValueAsString();
        // ??
        String total_work_hour = tclistrd.getTotalWorkHour().getValueAsString();
        // ?
        String work_hour = tclistrd.getWorkHour().getValueAsString();
        // 
        String overtime_statutory_work_hour = tclistrd.getOvertimeWithinStatutoryWorkingHour()
                .getValueAsString();
        // 
        // String overtime_day = tclistrd.getOvertimeDay().getValueAsString();
        String overtime_hour = tclistrd.getOvertimeHour().getValueAsString();
        // ?
        String total_official_off_hour = tclistrd.getTotalOfficialOffHour().getValueAsString();
        // ?
        String total_statutory_off_hour = tclistrd.getTotalStatutoryOffHour().getValueAsString();
        // ?
        String midnight_work_hour = tclistrd.getTotalMidnightWorkHour().getValueAsString();
        // 
        String rest_hour = tclistrd.getRestHour().getValueAsString();
        // String off_day = tclistrd.getOffDay().getValueAsString();// 
        // String off_hour = tclistrd.getOffHour().getValueAsString();// 
        // ?
        String late_coming_day = tclistrd.getLateComingDay().getValueAsString();
        // 
        String early_leaving_day = tclistrd.getEarlyLeavingDay().getValueAsString();
        // 
        String absent_day = tclistrd.getAbsentDay().getValueAsString();
        // 
        String paid_holiday = tclistrd.getPaidHoliday().getValueAsString();
        // 
        String compensatory_holiday = tclistrd.getCompensatoryHoliday().getValueAsString();
        // ???
        String other_day = tclistrd.getOtherDay().getValueAsString();
        // 
        String noinput = tclistrd.getNoInput().getValueAsString();

        String[] rows = { user_name, year, month, service_form, total_work_day, official_off_day,
                statutory_off_day, total_work_hour, work_hour, overtime_statutory_work_hour, overtime_hour,
                total_official_off_hour, total_statutory_off_hour, midnight_work_hour, rest_hour,
                late_coming_day, early_leaving_day, absent_day, paid_holiday, compensatory_holiday, other_day,
                noinput };
        rowcount = rowcount + 1;
        addRow(sheet.createRow(rowcount), cell_enc_types, rows);
    }

    // 
    int uid = ALEipUtils.getUserId(rundata);
    ALEventlogFactoryService.getInstance().getEventlogHandler().logXlsScreen(uid, "",
            ALEventlogConstants.PORTLET_TYPE_EXTTIMECARD);
}

From source file:com.aimluck.eip.modules.screens.ExtTimecardSummaryXlsExportScreen.java

License:Open Source License

private void setupTimecardSheet(RunData rundata, Context context, HSSFWorkbook wb) throws Exception {

    ExtTimecardSummaryListSelectData listData = new ExtTimecardSummaryListSelectData();
    listData.init(this, rundata, context);
    listData.setRowsNum(1000);//from  w w w  . j  a v  a  2 s. com
    listData.doViewList(this, rundata, context);
    listData.setuserList(target_group_name);

    String sheet_name = "";
    // ?
    String[] headers = { "???", "", "", "", "", "", "",
            "", "", "", "?", "", "",
            "", "", "???", "" };
    // 01
    short[] cell_enc_types = { HSSFCell.ENCODING_UTF_16, HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC,
            HSSFCell.ENCODING_UTF_16, HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC,
            HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC,
            HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC,
            HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC,
            HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC };
    HSSFSheet sheet = createHSSFSheet(wb, sheet_name, headers, cell_enc_types);

    int rowcount = 0;

    // ?
    HSSFCellStyle style_col = wb.createCellStyle();
    style_col.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
    style_col.setAlignment(HSSFCellStyle.ALIGN_JUSTIFY);

    ExtTimecardSummaryResultData tclistrd = null;
    List<ExtTimecardSummaryResultData> daykeys = listData.getGroupExtTimecards();
    int daykeysize = daykeys.size();
    for (int i = 0; i < daykeysize; i++) {
        tclistrd = daykeys.get(i);

        String user_name = tclistrd.getUserName();// ???
        String year = view_month.substring(0, 4); // 
        String month = view_month.substring(5); // 
        String service_form = tclistrd.getSystemName();// 
        String work_day = tclistrd.getWorkDay().getValueAsString(); // 
        String work_hour = tclistrd.getWorkHour().getValueAsString();// 
        String overtime_day = tclistrd.getOvertimeDay().getValueAsString();// 
        String overtime_hour = tclistrd.getOvertimeHour().getValueAsString();// 
        String off_day = tclistrd.getOffDay().getValueAsString();// 
        String off_hour = tclistrd.getOffHour().getValueAsString();// 
        String late_coming_day = tclistrd.getLateComingDay().getValueAsString();// ?
        String early_leaving_day = tclistrd.getEarlyLeavingDay().getValueAsString();// 
        String absent_day = tclistrd.getAbsentDay().getValueAsString();// 
        String paid_holiday = tclistrd.getPaidHoliday().getValueAsString();// 
        String compensatory_holiday = tclistrd.getCompensatoryHoliday().getValueAsString();// 
        String other_day = tclistrd.getOtherDay().getValueAsString();// ???
        String noinput = tclistrd.getNoInput().getValueAsString();// 

        String[] rows = { user_name, year, month, service_form, work_day, work_hour, overtime_day,
                overtime_hour, off_day, off_hour, late_coming_day, early_leaving_day, absent_day, paid_holiday,
                compensatory_holiday, other_day, noinput };
        rowcount = rowcount + 1;
        addRow(sheet.createRow(rowcount), cell_enc_types, rows);
    }

    // 
    int uid = ALEipUtils.getUserId(rundata);
    ALEventlogFactoryService.getInstance().getEventlogHandler().logXlsScreen(uid, "",
            ALEventlogConstants.PORTLET_TYPE_EXTTIMECARD);
}

From source file:com.aimluck.eip.modules.screens.ExtTimecardXlsExportScreen.java

License:Open Source License

private void setupTimecardSheet(RunData rundata, Context context, HSSFWorkbook wb) throws Exception {

    ExtTimecardSelectData listData = new ExtTimecardSelectData();
    listData.initField();//w  ww.j  ava 2s  .c  om
    listData.setRowsNum(1000);
    listData.doViewList(this, rundata, context);

    String sheet_name = "";
    // ?
    String[] headers = { "???", "", "", "", "", "",
            "", "", "", "", "", "",
            "?", "", "", "", "", "???",
            "??", "", "", "", "", "",
            "", "", "", "", "" };
    // 01
    short[] cell_enc_types = { HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16,
            HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16,
            HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC,
            HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC,
            HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC,
            HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.CELL_TYPE_NUMERIC,
            HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16,
            HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16,
            HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16,
            HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16 };
    HSSFSheet sheet = createHSSFSheet(wb, sheet_name, headers, cell_enc_types);

    int rowcount = 0;

    // ?
    HSSFCellStyle style_col = wb.createCellStyle();
    style_col.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
    style_col.setAlignment(HSSFCellStyle.ALIGN_JUSTIFY);

    String user_name = ALEipUtils.getUserFullName(Integer.parseInt(listData.getTargetUserId()));// ???
    String system_name = ExtTimecardUtils
            .getEipTExtTimecardSystemByUserId(Integer.parseInt(listData.getTargetUserId())).getSystemName();

    ExtTimecardListResultData tclistrd = null;
    List<ExtTimecardListResultData> daykeys = listData.getDateListKeys();
    int daykeysize = daykeys.size();
    for (int i = 0; i < daykeysize; i++) {
        tclistrd = daykeys.get(i);

        String date = "";// 
        String day = ""; // 
        String service_form = system_name; // 
        String clock_in_time = "";// 
        String clock_out_time = "";// 
        String work_day = "0"; //  0 or 1
        String work_hour = "0";// 
        String overtime_day = "0";// 
        String overtime_hour = "0";// 
        String off_day = "0";// 
        String off_hour = "0";// 
        String late_coming_day = "0";// ?
        String early_leaving_day = "0";// 
        String absent_day = "0";// 
        String paid_holiday = "0";// 
        String compensatory_holiday = "0";// 
        String other_day = "0";// ???
        String remark = "";// ??
        String[] out_going = new String[EipTExtTimecard.OUTGOING_COMEBACK_PER_DAY];// 
        String[] come_back = new String[EipTExtTimecard.OUTGOING_COMEBACK_PER_DAY];// 

        if (tclistrd.getRd() == null) {

            // ExtTimecardResultData rd = tclistrd.getRd();

            date = tclistrd.getDateStr("yyyy/MM/dd");
            day = tclistrd.getDateStr("EE");
        } else {

            ExtTimecardResultData rd = tclistrd.getRd();

            // ExtTimecardSummaryResultData srd = tclistrd.get

            date = tclistrd.getDateStr("yyyy/MM/dd");
            day = tclistrd.getDateStr("EE");
            String type = rd.getType().toString();
            if (!rd.getIsNullClockInTime()) {
                clock_in_time = rd.getClockInTime("HH:mm");
                clock_out_time = rd.getClockOutTime("HH:mm");
                if (tclistrd.getWorkHour() > 0.0) {
                    work_day = "1";
                    work_hour = Float.toString(tclistrd.getWorkHour());
                } else {
                    work_hour = "0";
                }
                if (tclistrd.getOvertimeHourWithoutRestHour() > 0.0) {
                    overtime_day = "1";
                    overtime_hour = Float.toString(tclistrd.getOvertimeHourWithoutRestHour());
                } else {
                    overtime_hour = "0";
                }
                if (tclistrd.getOffHour() > 0.0) {
                    off_day = "1";
                    off_hour = Float.toString(tclistrd.getOffHour());
                } else {
                    off_hour = "0";
                }
            }
            if (rd.getRefixFlag().getValue() == "1") {
                remark = rd.getReason().getValue();
                if (rd.getReasonFlg() && rd.getRemarksFlg()) {
                    remark += "?";
                }
            }
            if (rd.getRemarksFlg()) {
                remark += rd.getRemarks().getValue();
            }
            late_coming_day = tclistrd.isLateComing() ? "1" : "0";
            early_leaving_day = tclistrd.isEarlyLeaving() ? "1" : "0";
            absent_day = type.equals(EipTExtTimecard.TYPE_ABSENT) ? "1" : "0";
            paid_holiday = type.equals(EipTExtTimecard.TYPE_HOLIDAY) ? "1" : "0";
            compensatory_holiday = type.equals(EipTExtTimecard.TYPE_COMPENSATORY) ? "1" : "0";
            other_day = type.equals(EipTExtTimecard.TYPE_ETC) ? "1" : "0";

            List<Map<String, String>> list = tclistrd.getOutgoingComeback_xls();
            for (int j = 0; j < EipTExtTimecard.OUTGOING_COMEBACK_PER_DAY; j++) {
                Map<String, String> map = list.get(j);
                out_going[j] = map.get("outgoing");
                come_back[j] = map.get("comeback");
            }
        }

        String[] rows = { user_name, date, day, service_form, clock_in_time, clock_out_time, work_day,
                work_hour, overtime_day, overtime_hour, off_day, off_hour, late_coming_day, early_leaving_day,
                absent_day, paid_holiday, compensatory_holiday, other_day, remark, out_going[0], come_back[0],
                out_going[1], come_back[1], out_going[2], come_back[2], out_going[3], come_back[3],
                out_going[4], come_back[4] };
        rowcount = rowcount + 1;
        addRow(sheet.createRow(rowcount), cell_enc_types, rows);
    }
    /*
     * rowcount = rowcount + 1; String NOTHING = null; String work_day =
     * "=SUM(G2:G" + rowcount + ")"; String work_hour = "=SUM(H2:H" + rowcount +
     * ")"; String overtime_day = "=SUM(I2:I" + rowcount + ")"; String
     * overtime_hour = "=SUM(J2:J" + rowcount + ")"; String off_day =
     * "=SUM(K2:K" + rowcount + ")"; String off_hour = "=SUM(L2:L" + rowcount +
     * ")"; String late_coming_day = "=SUM(M2:M" + rowcount + ")"; String
     * early_leaving_day = "=SUM(N2:N" + rowcount + ")"; String absent_day =
     * "=SUM(O2:O" + rowcount + ")"; String paid_holiday = "=SUM(P2:P" +
     * rowcount + ")"; String compensatory_holiday = "=SUM(Q2:Q" + rowcount +
     * ")"; String other_day = "=SUM(R2:R" + rowcount + ")"; String[] rows = {
     * NOTHING, NOTHING, NOTHING, NOTHING, NOTHING, NOTHING, work_day,
     * work_hour, overtime_day, overtime_hour, off_day, off_hour,
     * late_coming_day, early_leaving_day, absent_day, paid_holiday,
     * compensatory_holiday, other_day, };
     * 
     * addFooter(sheet.createRow(rowcount), cell_enc_types, rows);
     */

    // 
    int uid = ALEipUtils.getUserId(rundata);
    ALEventlogFactoryService.getInstance().getEventlogHandler().logXlsScreen(uid, "",
            ALEventlogConstants.PORTLET_TYPE_EXTTIMECARD);
}

From source file:com.aimluck.eip.modules.screens.TimecardXlsExportScreen.java

License:Open Source License

private void setupTimecardSheet(RunData rundata, Context context, HSSFWorkbook wb) throws Exception {

    TimecardSelectData listData = new TimecardSelectData();
    listData.initField();/*ww w  .j a va2 s. c  o m*/
    listData.setRowsNum(1000);
    listData.doViewList(this, rundata, context);

    String sheet_name = "";
    // ?
    String[] headers = { "", "?", "", "", "?" };
    // 01
    short[] cell_enc_types = { HSSFCell.ENCODING_UTF_16, HSSFCell.CELL_TYPE_NUMERIC, HSSFCell.ENCODING_UTF_16,
            HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16 };
    HSSFSheet sheet = createHSSFSheet(wb, sheet_name, headers, cell_enc_types);

    int rowcount = 0;

    // ?
    HSSFCellStyle style_col = wb.createCellStyle();
    style_col.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
    style_col.setAlignment(HSSFCellStyle.ALIGN_JUSTIFY);

    TimecardListResultData tclistrd = null;
    List<String> daykeys = listData.getDateListKeys();
    int daykeysize = daykeys.size();
    for (int i = 0; i < daykeysize; i++) {
        tclistrd = listData.getDateListValue(daykeys.get(i));
        List<TimecardResultData> viewlist = tclistrd.getViewList();
        int viewlistsize = viewlist.size();

        for (int j = 0; j < viewlistsize; j++) {
            TimecardResultData rd = viewlist.get(j);
            String workStr = null;
            if ("0".equals(rd.getWorkFlag().toString())) {
                workStr = "";
            } else {
                workStr = "";
            }

            String[] rows = { tclistrd.getDateStr(), tclistrd.getSummayTimes(), workStr, rd.getWorkDateStr(),
                    rd.getReason().toString() };

            rowcount = rowcount + 1;
            addRow(sheet.createRow(rowcount), cell_enc_types, rows);
        }
        sheet.addMergedRegion(new Region(rowcount - viewlistsize + 1, (short) 0, rowcount, (short) 0));
        HSSFRow row = sheet.getRow(rowcount - viewlistsize + 1);
        HSSFCell cell1 = row.getCell((short) 0);
        cell1.setCellStyle(style_col);

        sheet.addMergedRegion(new Region(rowcount - viewlistsize + 1, (short) 1, rowcount, (short) 1));
        HSSFCell cell2 = row.getCell((short) 1);
        cell2.setCellStyle(style_col);
    }

    int uid = ALEipUtils.getUserId(rundata);
    ALEventlogFactoryService.getInstance().getEventlogHandler().logXlsScreen(uid, "",
            ALEventlogConstants.PORTLET_TYPE_TIMECARD_XLS_SCREEN);
}

From source file:com.alibaba.differ.biz.TableExporter.java

License:Open Source License

public void export() throws IOException {
    fc.setFileFilter(new ExcelFileFilter());
    fc.setFileHidingEnabled(true);//from w ww. j  a  v a  2 s  . co m
    fc.setAcceptAllFileFilterUsed(false);
    int returnValue = fc.showSaveDialog(null);
    if (returnValue != JFileChooser.APPROVE_OPTION) {
        return;
    }
    File file = fc.getSelectedFile();
    if (file.exists()) {
        JOptionPane.showMessageDialog(null, "");
        return;
    }
    FileOutputStream fos = new FileOutputStream(file + ".xls");
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet hs = wb.createSheet();
    TableModel tm = table.getModel();
    int row = tm.getRowCount();
    int cloumn = tm.getColumnCount();
    HSSFCellStyle style = wb.createCellStyle();
    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
    style.setFillForegroundColor(HSSFColor.LIGHT_GREEN.index);
    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    HSSFFont font = wb.createFont();
    font.setFontHeightInPoints((short) 11);
    style.setFont(font);
    HSSFCellStyle style1 = wb.createCellStyle();
    style1.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    style1.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    style1.setBorderRight(HSSFCellStyle.BORDER_THIN);
    style1.setBorderTop(HSSFCellStyle.BORDER_THIN);
    style1.setFillForegroundColor(HSSFColor.ORANGE.index);
    style1.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    HSSFFont font1 = wb.createFont();
    font1.setFontHeightInPoints((short) 15);
    font1.setBoldweight((short) 700);
    style1.setFont(font);

    for (int i = 0; i < row + 1; i++) {
        HSSFRow hr = hs.createRow(i);
        for (int j = 0; j < cloumn; j++) {
            if (i == 0) {
                String value = tm.getColumnName(j);
                hs.setColumnWidth(j, UIConfig.EXCEL_COLUMN_WIDTH);
                HSSFRichTextString srts = new HSSFRichTextString(value);
                HSSFCell hc = hr.createCell((short) j);
                hc.setCellStyle(style1);
                hc.setCellValue(srts);
            } else {
                if (tm.getValueAt(i - 1, j) != null) {
                    String value = tm.getValueAt(i - 1, j).toString();
                    HSSFRichTextString srts = new HSSFRichTextString(value);
                    HSSFCell hc = hr.createCell((short) j);
                    hc.setCellStyle(style);

                    if (value.equals("") || value == null) {
                        hc.setCellValue(new HSSFRichTextString(""));
                    } else {
                        hc.setCellValue(srts);
                    }
                }
            }
        }
    }
    wb.write(fos);
    fos.close();
    JOptionPane.showMessageDialog(null, "Excel");
}

From source file:com.anphat.list.controller.ListStaffController.java

public File exportFile(List<StaffDTO> lstStaffInfo) {
    try {/*ww  w.j  a v  a2s  . c o  m*/
        FileOutputStream fileOut = new FileOutputStream(PATH_EXPORT + Constants.FILE_NAME.LIST_STAFF);
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet worksheet = workbook.createSheet("danhsachnhanvien");
        HSSFCellStyle cellStyle;
        HSSFCellStyle rowStyle;

        HSSFCellStyle cellStyleLeft = null;
        HSSFCellStyle cellStyleRight = null;
        //style left
        cellStyleLeft = workbook.createCellStyle();
        cellStyleLeft.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        //phai
        cellStyleRight = workbook.createCellStyle();
        cellStyleRight.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
        cellStyleRight.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        cellStyleRight.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        cellStyleRight.setBorderRight(HSSFCellStyle.BORDER_THIN);
        cellStyleRight.setBorderTop(HSSFCellStyle.BORDER_THIN);

        //                //header bang
        HSSFRow row5 = worksheet.createRow(0);

        HSSFCell cellA1 = row5.createCell(0);
        cellA1.setCellValue(BundleUtils.getString("STT"));
        cellStyle = workbook.createCellStyle();
        cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        cellStyle.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index);
        cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        cellStyle.setWrapText(true);
        //rowstyle
        rowStyle = workbook.createCellStyle();
        rowStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        rowStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        rowStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        rowStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        rowStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        rowStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        rowStyle.setFillForegroundColor(HSSFColor.WHITE.index);
        rowStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        rowStyle.setWrapText(true);

        cellA1.setCellStyle(cellStyle);

        HSSFCell cellB1 = row5.createCell(1);
        cellB1.setCellValue(BundleUtils.getString("cms.StaffInfo.code"));
        cellB1.setCellStyle(cellStyle);

        HSSFCell cellC1 = row5.createCell(2);
        cellC1.setCellValue(BundleUtils.getString("cms.StaffInfo.name"));
        cellC1.setCellStyle(cellStyle);
        HSSFCell cellD1 = row5.createCell(3);
        cellD1.setCellValue(BundleUtils.getString("cms.StaffInfo.email"));
        cellD1.setCellStyle(cellStyle);
        HSSFCell cellE1 = row5.createCell(4);
        cellE1.setCellValue(BundleUtils.getString("cms.StaffInfo.birthdate"));
        cellE1.setCellStyle(cellStyle);
        HSSFCell cellF1 = row5.createCell(5);
        cellF1.setCellValue(BundleUtils.getString("cms.StaffInfo.phoneNumber"));
        cellF1.setCellStyle(cellStyle);
        HSSFCell cellG1 = row5.createCell(6);
        cellG1.setCellValue(BundleUtils.getString("cms.StaffInfo.deptName"));
        cellG1.setCellStyle(cellStyle);
        HSSFCell cellH1 = row5.createCell(7);
        cellH1.setCellValue(BundleUtils.getString("cms.StaffInfo.staffType"));
        cellH1.setCellStyle(cellStyle);
        HSSFCell cellI1 = row5.createCell(8);
        cellI1.setCellValue(BundleUtils.getString("cms.StaffInfo.status"));
        cellI1.setCellStyle(cellStyle);
        //content bang
        if (!lstStaffInfo.isEmpty()) {
            int j = 0;
            for (StaffDTO staff : lstStaffInfo) {
                HSSFRow row = worksheet.createRow(j + 1);

                HSSFCell cellA = row.createCell(0);
                cellA.setCellValue(j + 1);
                cellA.setCellStyle(rowStyle);
                HSSFCell cellB = row.createCell(1);
                cellB.setCellValue((staff.getDeptId() == null) ? Constants.NULL : staff.getCode());
                cellB.setCellStyle(cellStyleLeft);
                HSSFCell cellC = row.createCell(2);
                cellC.setCellValue((staff.getCode() == null) ? Constants.NULL : staff.getName());
                cellC.setCellStyle(cellStyleLeft);
                HSSFCell cellD = row.createCell(3);
                cellD.setCellValue((staff.getName() == null) ? Constants.NULL : staff.getEmail());
                cellD.setCellStyle(cellStyleLeft);
                HSSFCell cellE = row.createCell(4);
                //                    cellE.setCellValue((staff.getEmail() == null) ? Constants.NULL : staff.getBirthDate());
                cellE.setCellStyle(cellStyleLeft);
                HSSFCell cellF = row.createCell(5);
                cellF.setCellValue((staff.getTelNumber() == null) ? Constants.NULL : staff.getTelNumber());
                cellF.setCellStyle(cellStyleLeft);
                HSSFCell cellG = row.createCell(6);
                //                    cellG.setCellValue((staff.getDeptName() == null) ? Constants.NULL : staff.getDeptName());
                cellG.setCellStyle(cellStyleLeft);
                HSSFCell cellH = row.createCell(7);
                cellH.setCellValue((staff.getStaffType() == null) ? Constants.NULL
                        : BundleUtils.getString(
                                "staff.type." + DataUtil.getStringEscapeHTML4(staff.getStaffType())));
                cellH.setCellStyle(cellStyleLeft);
                HSSFCell cellI = row.createCell(8);
                cellI.setCellValue((staff.getStatus() == null) ? Constants.NULL
                        : BundleUtils.getString(
                                "common.status." + DataUtil.getStringEscapeHTML4(staff.getStatus())));
                cellI.setCellStyle(cellStyleLeft);
                j++;
            }
            //Set Width
            for (int i = 0; i <= 0; i++) {
                worksheet.setColumnWidth(i, 2000);
            }
            for (int i = 1; i <= 7; i++) {
                worksheet.setColumnWidth(i, 5000);
            }
            for (int i = 8; i <= 10; i++) {
                worksheet.setColumnWidth(i, 3000);
            }
        }
        try {
            workbook.write(fileOut);
            fileOut.flush();
            fileOut.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    File file = new File(PATH_EXPORT + Constants.FILE_NAME.LIST_STAFF);
    return file;

}

From source file:com.app.ExcelView.java

License:Open Source License

/**
 * ?Excel/* w ww. java  2  s .  c  o  m*/
 * 
 * @param model
 *            ?
 * @param workbook
 *            workbook
 * @param request
 *            request
 * @param response
 *            response
 */
public void buildExcelDocument(Map<String, Object> model, HSSFWorkbook workbook, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    Assert.notEmpty(properties);
    HSSFSheet sheet;
    if (StringUtils.isNotEmpty(sheetName)) {
        sheet = workbook.createSheet(sheetName);
    } else {
        sheet = workbook.createSheet();
    }
    int rowNumber = 0;
    if (titles != null && titles.length > 0) {
        HSSFRow header = sheet.createRow(rowNumber);
        header.setHeight((short) 400);
        for (int i = 0; i < properties.length; i++) {
            HSSFCell cell = header.createCell(i);
            HSSFCellStyle cellStyle = workbook.createCellStyle();
            cellStyle.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index);
            cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
            cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
            HSSFFont font = workbook.createFont();
            font.setFontHeightInPoints((short) 11);
            font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            cellStyle.setFont(font);
            cell.setCellStyle(cellStyle);
            if (i == 0) {
                HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
                HSSFComment comment = patriarch
                        .createComment(new HSSFClientAnchor(0, 0, 0, 0, (short) 1, 1, (short) 4, 4));
                comment.setString(new HSSFRichTextString("P" + "o" + "w" + "e" + "r" + "e" + "d" + " " + "B"
                        + "y" + " " + "A" + "P" + "P" + "T" + "E" + "A" + "M"));
                cell.setCellComment(comment);
            }
            if (titles.length > i && titles[i] != null) {
                cell.setCellValue(titles[i]);
            } else {
                cell.setCellValue(properties[i]);
            }
            if (widths != null && widths.length > i && widths[i] != null) {
                sheet.setColumnWidth(i, widths[i]);
            } else {
                sheet.autoSizeColumn(i);
            }
        }
        rowNumber++;
    }
    if (data != null) {
        for (Object item : data) {
            HSSFRow row = sheet.createRow(rowNumber);
            for (int i = 0; i < properties.length; i++) {
                HSSFCell cell = row.createCell(i);
                if (converters != null && converters.length > i && converters[i] != null) {
                    Class<?> clazz = PropertyUtils.getPropertyType(item, properties[i]);
                    ConvertUtils.register(converters[i], clazz);
                    cell.setCellValue(BeanUtils.getProperty(item, properties[i]));
                    ConvertUtils.deregister(clazz);
                    if (clazz.equals(Date.class)) {
                        DateConverter dateConverter = new DateConverter();
                        dateConverter.setPattern(DEFAULT_DATE_PATTERN);
                        ConvertUtils.register(dateConverter, Date.class);
                    }
                } else {
                    cell.setCellValue(BeanUtils.getProperty(item, properties[i]));
                }
                if (rowNumber == 0 || rowNumber == 1) {
                    if (widths != null && widths.length > i && widths[i] != null) {
                        sheet.setColumnWidth(i, widths[i]);
                    } else {
                        sheet.autoSizeColumn(i);
                    }
                }
            }
            rowNumber++;
        }
    }
    if (contents != null && contents.length > 0) {
        rowNumber++;
        for (String content : contents) {
            HSSFRow row = sheet.createRow(rowNumber);
            HSSFCell cell = row.createCell(0);
            HSSFCellStyle cellStyle = workbook.createCellStyle();
            HSSFFont font = workbook.createFont();
            font.setColor(HSSFColor.GREY_50_PERCENT.index);
            cellStyle.setFont(font);
            cell.setCellStyle(cellStyle);
            cell.setCellValue(content);
            rowNumber++;
        }
    }
    response.setContentType("application/force-download");
    if (StringUtils.isNotEmpty(filename)) {
        response.setHeader("Content-disposition",
                "attachment; filename=" + URLEncoder.encode(filename, "UTF-8"));
    } else {
        response.setHeader("Content-disposition", "attachment");
    }
}

From source file:com.bdx.rainbow.spsy.service.impl.EnterpriseLicenseServiceImpl.java

/**
 *
 * @param title ??//from   w  w  w .  j  a v  a  2  s. c  o m
 * @param headers ??
 * @param resultLists ?
 * @param pattern ?,"yyyy-MM-dd"
 */
private HSSFWorkbook exportExcel(String title, String[] headers, List<DubboEnterpriseLicense> resultLists,
        String pattern) {
    if (resultLists == null) {
        return null;
    }
    if (pattern == null && StringUtils.isEmpty(pattern)) {
        pattern = "yyyy-MM-dd";
    }
    SimpleDateFormat sdf = new SimpleDateFormat(pattern);
    // 
    HSSFWorkbook workbook = new HSSFWorkbook();
    // ?
    HSSFSheet sheet = workbook.createSheet(title);
    // 15
    sheet.setDefaultColumnWidth((short) 15);
    // ??
    HSSFCellStyle style = workbook.createCellStyle();
    // ?
    style.setFillForegroundColor(HSSFColor.SKY_BLUE.index);
    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
    style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    // ?
    HSSFFont font = workbook.createFont();
    font.setColor(HSSFColor.VIOLET.index);
    font.setFontHeightInPoints((short) 12);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    // ??
    style.setFont(font);
    // ???
    HSSFCellStyle style2 = workbook.createCellStyle();
    style2.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);
    style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    style2.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    style2.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    style2.setBorderRight(HSSFCellStyle.BORDER_THIN);
    style2.setBorderTop(HSSFCellStyle.BORDER_THIN);
    style2.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    style2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
    // ??
    HSSFFont font2 = workbook.createFont();
    font2.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
    // ??
    style2.setFont(font2);
    // 
    HSSFRow row = sheet.createRow(0);
    for (short i = 0; i < headers.length; i++) {
        HSSFCell cell = row.createCell(i);
        cell.setCellStyle(style);
        HSSFRichTextString text = new HSSFRichTextString(headers[i]);
        cell.setCellValue(text);
    }
    // ?????
    for (int i = 0; i < resultLists.size(); i++) {
        row = sheet.createRow(i + 1);
        int index = 0;
        //                HSSFCell cell = row.createCell(j);
        //                row.createCell(index++).setCellStyle(style2);
        DubboEnterpriseLicense info = resultLists.get(i);
        row.createCell(index++).setCellValue(info.getEnterpriseName());
        row.createCell(index++).setCellValue(info.getOrganizationCode());
        row.createCell(index++).setCellValue(info.getLegalPerson());
        row.createCell(index++).setCellValue(info.getLegalPersonPhone());
        String type = info.getLicenseType();
        if ("001".equals(type)) {
            row.createCell(index++).setCellValue("");
        } else if ("002".equals(type)) {
            row.createCell(index++).setCellValue("??");
        } else if ("003".equals(type)) {
            row.createCell(index++).setCellValue("");
        } else if ("004".equals(type)) {
            row.createCell(index++).setCellValue("?");
        } else {
            row.createCell(index++).setCellValue(type);
        }

        row.createCell(index++).setCellValue(info.getLicenseCode());
        if (info.getLicenseTime() != null) {
            row.createCell(index++).setCellValue(sdf.format(info.getLicenseTime()));
        } else {
            row.createCell(index++).setCellValue("");
        }
        if (info.getInvalidDate() != null) {
            Long time = (System.currentTimeMillis() - info.getInvalidDate().getTime()) / (1000 * 3600 * 24);
            if (time > 0) {
                row.createCell(index++).setCellValue("");
            } else if (time <= 0) {
                row.createCell(index++).setCellValue("");
            } else {
                row.createCell(index++).setCellValue("1");
            }
        } else {
            row.createCell(index++).setCellValue("");
        }

    }
    return workbook;
}