Example usage for org.apache.poi.hssf.usermodel HSSFRow createCell

List of usage examples for org.apache.poi.hssf.usermodel HSSFRow createCell

Introduction

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

Prototype

@Override
public HSSFCell createCell(int column) 

Source Link

Document

Use this to create new cells within the row and return it.

Usage

From source file:com.yitong.app.service.judicial.dxzpjymx.JymxService.java

public File makeQzhqqExcel(List<Map> qzhqqList, String filePath) throws IOException {

    HSSFWorkbook wk = new HSSFWorkbook();
    HSSFSheet sheet = wk.createSheet("qzhqq");
    // //from  w  w w. ja v  a2  s  . c  om
    HSSFRow firstRow = sheet.createRow(0);
    int totalColNum = 27;
    //?
    HSSFCell[] firstCell = new HSSFCell[totalColNum];
    //??string
    String[] colNames = new String[totalColNum];

    colNames[0] = "?";
    colNames[1] = "?";
    colNames[2] = "???";
    colNames[3] = "??";
    colNames[4] = "?";
    colNames[5] = "";
    colNames[6] = "";
    colNames[7] = "??";
    colNames[8] = "?";
    colNames[9] = "";
    colNames[10] = "??";
    colNames[11] = "???";
    colNames[12] = "??";
    colNames[13] = "";
    colNames[14] = "";
    colNames[15] = "";
    colNames[16] = "";
    colNames[17] = "?";
    colNames[18] = "??";
    colNames[19] = "??";
    colNames[20] = "???";
    colNames[21] = "???";
    colNames[22] = "??";
    colNames[23] = "???";
    colNames[24] = "????";
    colNames[25] = "????";
    //??
    for (int i = 0; i < totalColNum; i++) {
        //?
        firstCell[i] = firstRow.createCell(i);
        //? ?? new HSSFRichTextString(colNames[i]) ?
        firstCell[i].setCellValue(new HSSFRichTextString(colNames[i]));
    }

    //???excel
    //j1 ?rs
    int j = 1;

    for (Map m : qzhqqList) {
        // 
        HSSFRow row = sheet.createRow(j);
        for (int i = 0; i < totalColNum; i++) {
            //??
            HSSFCell cell = row.createCell(i);
            //? ?new HSSFRichTextString()?? 
            //rs.getString(i+1)1??
            if (i == 0) {
                cell.setCellValue(new HSSFRichTextString((String) m.get("APPLICATIONID")));
            }
            if (i == 1) {
                cell.setCellValue(new HSSFRichTextString((String) m.get("TXCODE")));
            }
            if (i == 2) {
                cell.setCellValue(new HSSFRichTextString((String) m.get("MESSAGEFROM")));
            }
            if (i == 3) {
                cell.setCellValue(new HSSFRichTextString((String) m.get("TRANSSERIALNUMBER")));
            }
            if (i == 4) {
                cell.setCellValue(new HSSFRichTextString((String) m.get("CASENUMBER")));
            }
            if (i == 5) {
                cell.setCellValue(new HSSFRichTextString((String) m.get("CASETYPE")));
            }
            if (i == 6) {
                cell.setCellValue(new HSSFRichTextString(
                        "02".equals(((String) m.get("EMERGENCYLEVEL"))) ? "" : ""));
            }
            if (i == 7) {
                cell.setCellValue(new HSSFRichTextString((String) m.get("BANKNAME")));
            }
            if (i == 8) {
                cell.setCellValue(new HSSFRichTextString((String) m.get("BANKID")));
            }
            if (i == 9) {
                cell.setCellValue(new HSSFRichTextString(
                        "2".equals(((String) m.get("SUBJECTTYPE"))) ? "" : ""));
            }
            if (i == 10) {
                cell.setCellValue(new HSSFRichTextString((String) m.get("ACCOUNTCREDENTIALTYPE")));
            }
            if (i == 11) {
                cell.setCellValue(new HSSFRichTextString((String) m.get("ACCOUNTCREDENTIALNUMBER")));
            }
            if (i == 12) {
                cell.setCellValue(new HSSFRichTextString((String) m.get("ACCOUNTSUBJECTNAME")));
            }
            if (i == 13) {
                cell.setCellValue(new HSSFRichTextString(
                        "02".equals(((String) m.get("INQUIRYMODE"))) ? "?" : "?"));
            }
            if (i == 14) {
                cell.setCellValue(new HSSFRichTextString((String) m.get("REASON")));
            }
            if (i == 15) {
                cell.setCellValue(new HSSFRichTextString((String) m.get("REMARK")));
            }
            if (i == 16) {
                cell.setCellValue(new HSSFRichTextString((String) m.get("APPLICATIONTIME")));
            }
            if (i == 17) {
                cell.setCellValue(new HSSFRichTextString((String) m.get("APPLICATIONORGID")));
            }
            if (i == 18) {
                cell.setCellValue(new HSSFRichTextString((String) m.get("APPLICATIONORGNAME")));
            }

            if (i == 19) {
                cell.setCellValue(new HSSFRichTextString((String) m.get("OPERATORIDTYPE")));
            }

            if (i == 20) {
                cell.setCellValue(new HSSFRichTextString((String) m.get("OPERATORIDNUMBER")));
            }
            if (i == 21) {
                cell.setCellValue(new HSSFRichTextString((String) m.get("OPERATORNAME")));
            }
            if (i == 22) {
                cell.setCellValue(new HSSFRichTextString((String) m.get("OPERATORPHONENUMBER")));
            }
            if (i == 23) {
                cell.setCellValue(new HSSFRichTextString((String) m.get("INVESTIGATORIDTYPE")));
            }
            if (i == 24) {
                cell.setCellValue(new HSSFRichTextString((String) m.get("INVESTIGATORNAME")));
            }
            if (i == 25) {
                cell.setCellValue(new HSSFRichTextString((String) m.get("INVESTIGATORIDNUMBER")));
            }

        }
        //
        j++;
    }
    //?
    OutputStream out = new FileOutputStream(filePath);
    //?excel?
    wk.write(out);
    //?
    out.close();

    return new File(filePath);

}

From source file:com.yitong.app.service.judicial.dxzpjymx.JymxService.java

public File makeQzhjgExcel(List<Map> qzhzhxxList, List<Map> qzhdjList, String filePath) throws IOException {
    HSSFWorkbook wk = new HSSFWorkbook();
    HSSFSheet sheet1 = wk.createSheet("zhxx");
    HSSFSheet sheet2 = wk.createSheet("djxx");
    // //from  ww w . j a  v a 2  s.c o m
    HSSFRow firstRow1 = sheet1.createRow(0);
    HSSFRow firstRow2 = sheet2.createRow(0);
    int totalColNum1 = 40;
    int totalColNum2 = 31;
    //?
    HSSFCell[] firstCell1 = new HSSFCell[totalColNum1];
    HSSFCell[] firstCell2 = new HSSFCell[totalColNum2];
    //??string
    String[] colNames1 = new String[totalColNum1];

    colNames1[0] = "??";
    colNames1[1] = "????";
    colNames1[2] = "??";
    colNames1[3] = "";
    colNames1[4] = "";
    colNames1[5] = "?";
    colNames1[6] = "";
    colNames1[7] = "";
    colNames1[8] = "";
    colNames1[9] = "";
    colNames1[10] = "??";
    colNames1[11] = "(?)??";
    colNames1[12] = "(?)";
    colNames1[13] = "?";
    colNames1[14] = "??";
    colNames1[15] = "";
    colNames1[16] = "?";
    colNames1[17] = "??";
    colNames1[18] = "?";

    String[] colNames2 = new String[totalColNum2];
    colNames2[0] = "?";
    colNames2[1] = "???? ";
    colNames2[2] = "??";
    colNames2[3] = "?";
    colNames2[4] = "??";
    colNames2[5] = "";
    colNames2[6] = "";
    colNames2[7] = "??";
    colNames2[8] = "??";
    colNames2[9] = "?";
    colNames2[10] = "";

    //??
    for (int i = 0; i < totalColNum1; i++) {
        //?
        firstCell1[i] = firstRow1.createCell(i);
        //? ?? new HSSFRichTextString(colNames[i]) ?
        firstCell1[i].setCellValue(new HSSFRichTextString(colNames1[i]));
    }

    //??
    for (int i = 0; i < totalColNum2; i++) {
        //?
        firstCell2[i] = firstRow2.createCell(i);
        //? ?? new HSSFRichTextString(colNames[i]) ?
        firstCell2[i].setCellValue(new HSSFRichTextString(colNames2[i]));
    }

    //???excel
    //j1 ?rs
    int j = 1;

    for (Map m1 : qzhzhxxList) {
        // 
        HSSFRow row = sheet1.createRow(j);
        for (int i = 0; i < totalColNum1; i++) {
            //??
            HSSFCell cell = row.createCell(i);
            //? ?new HSSFRichTextString()?? 
            //rs.getString(i+1)1??
            if (i == 0) {
                cell.setCellValue(new HSSFRichTextString((String) m1.get("TRANSSERIALNUMBER")));
            }
            if (i == 1) {
                cell.setCellValue(new HSSFRichTextString((String) m1.get("NEWTRANSSERIALNUMBER")));
            }
            if (i == 2) {
                cell.setCellValue(new HSSFRichTextString((String) m1.get("ACCOUNTNAME")));
            }
            if (i == 3) {
                cell.setCellValue(new HSSFRichTextString((String) m1.get("CARDNUMBER")));
            }
            if (i == 4) {
                cell.setCellValue(new HSSFRichTextString((String) m1.get("DEPOSITBANKBRANCH")));
            }
            if (i == 5) {
                cell.setCellValue(new HSSFRichTextString((String) m1.get("DEPOSITBANKBRANCHCODE")));
            }
            if (i == 6) {
                cell.setCellValue(new HSSFRichTextString((String) m1.get("ACCOUNTOPENTIME")));
            }
            if (i == 7) {
                cell.setCellValue(new HSSFRichTextString((String) m1.get("ACCOUNTCANCELLATIONTIME")));
            }
            if (i == 8) {
                cell.setCellValue(new HSSFRichTextString((String) m1.get("ACCOUNTCANCELLATIONBRANCH")));
            }
            if (i == 9) {
                cell.setCellValue(new HSSFRichTextString((String) m1.get("REMARK")));
            }
            if (i == 10) {
                cell.setCellValue(new HSSFRichTextString((String) m1.get("ACCOUNTNUMBER")));
            }
            if (i == 11) {
                cell.setCellValue(new HSSFRichTextString((String) m1.get("ACCOUNTSERIAL")));
            }
            if (i == 12) {

                cell.setCellValue(new HSSFRichTextString((String) m1.get("ACCOUNTTYPE")));
            }
            if (i == 13) {
                cell.setCellValue(new HSSFRichTextString((String) m1.get("ACCOUNTSTATUS")));
            }
            if (i == 14) {
                cell.setCellValue(new HSSFRichTextString((String) m1.get("CURRENCY")));
            }
            if (i == 15) {
                cell.setCellValue(new HSSFRichTextString((String) m1.get("CASHREMIT")));
            }
            if (i == 16) {
                cell.setCellValue(new HSSFRichTextString((String) m1.get("ACCOUNTBALANCE")));
            }
            if (i == 17) {
                cell.setCellValue(new HSSFRichTextString((String) m1.get("AVAILABLEBALANCE")));
            }
            if (i == 18) {
                cell.setCellValue(new HSSFRichTextString((String) m1.get("LASTTRANSACTIONTIME")));
            }

        }
        //
        j++;
    }

    int k = 1;

    for (Map m2 : qzhdjList) {
        // 
        HSSFRow row = sheet2.createRow(k);
        for (int i = 0; i < totalColNum2; i++) {
            //??
            HSSFCell cell = row.createCell(i);
            //? ?new HSSFRichTextString()?? 
            //rs.getString(i+1)1??
            if (i == 0) {
                cell.setCellValue(new HSSFRichTextString((String) m2.get("APPLICATIONID")));
            }
            if (i == 1) {
                cell.setCellValue(new HSSFRichTextString((String) m2.get("NEWTRANSSERIALNUMBER")));
            }
            if (i == 2) {
                cell.setCellValue(new HSSFRichTextString((String) m2.get("FREEZESERIAL")));
            }
            if (i == 3) {
                cell.setCellValue(new HSSFRichTextString((String) m2.get("ACCOUNTNUMBER")));
            }
            if (i == 4) {
                cell.setCellValue(new HSSFRichTextString((String) m2.get("CARDNUMBER")));
            }
            if (i == 5) {
                cell.setCellValue(new HSSFRichTextString((String) m2.get("FREEZESTARTTIME")));
            }
            if (i == 6) {
                cell.setCellValue(new HSSFRichTextString((String) m2.get("FREEZEENDTIME")));
            }
            if (i == 7) {
                cell.setCellValue(new HSSFRichTextString((String) m2.get("FREEZEDEPTNAME")));
            }
            if (i == 8) {
                cell.setCellValue(new HSSFRichTextString((String) m2.get("CURRENCY")));
            }
            if (i == 9) {
                cell.setCellValue(new HSSFRichTextString((String) m2.get("FREEZEBALANCE")));
            }
            if (i == 10) {
                cell.setCellValue(new HSSFRichTextString((String) m2.get("FREEZETYPE")));
            }

        }
        //
        k++;
    }
    //?
    OutputStream out = new FileOutputStream(filePath);
    //?excel?
    wk.write(out);
    //?
    out.close();

    return new File(filePath);
}

From source file:com.yyl.common.utils.excel.ExcelTools.java

public static void writeToXLS(ExcelRow heads, ExcelData data, String sheetName, ByteArrayOutputStream out)
        throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet1 = wb.createSheet(sheetName);
    HSSFRow row = sheet1.createRow(0);
    HSSFCellStyle style = wb.createCellStyle();
    style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    HSSFCell cell;/*from w w w .j a  v a  2  s .c o  m*/

    for (int i = 0; i < heads.size(); i++) {
        cell = row.createCell(i);
        cell.setCellValue(heads.get(i));
        cell.setCellStyle(style);
    }
    if (data != null && data.size() != 0) {
        for (int n = 0; n < data.size(); n++) {
            row = sheet1.createRow(n + 1);
            ExcelRow datarow = data.get(n);
            for (int m = 0; m < datarow.size(); m++) {
                cell = row.createCell(m);
                cell.setCellValue(datarow.get(m));
                cell.setCellStyle(style);
            }
        }
    }
    wb.write(out);
}

From source file:com.zb.app.common.file.ExcelUtils.java

License:Open Source License

/**
 * excelrow?T??title?T//from  w ww  .ja v  a  2  s .  c  o m
 * 
 * @param response
 * @param list
 * @param xlsName
 * @param headTitle
 * @return
 */
public static <T> HSSFWorkbook defBuildExcel(List<T> list, String xlsName, String... headTitle) {

    return buildExcel(list, xlsName, new IExcel<T>() {

        @Override
        public void initHSSRow(List<T> list, HSSFSheet sheet) {
            HSSFCell cell;
            for (int j = 0; j < list.size(); j++) {
                T row = list.get(j);
                if (row == null) {
                    continue;
                }
                HSSFRow hssrow = sheet.createRow(j + 1);
                Map<String, String> fieldValMap = BeanUtils.getFieldValueMap(row);

                int i = 0;
                for (Entry<String, String> entry : fieldValMap.entrySet()) {
                    Object value = entry.getValue();
                    cell = hssrow.createCell(i++);
                    cell.setCellType(HSSFCell.CELL_TYPE_STRING);
                    cell.setCellValue(value == null ? StringUtils.EMPTY : value + StringUtils.EMPTY);
                }
            }
        }
    }, headTitle);
}

From source file:com.zdtx.ifms.specific.service.monitor.IpCamManager.java

@SuppressWarnings("unchecked")
public InputStream getExcel(String title) {
    List<Camera> data = new ArrayList<Camera>();
    Page<Camera> page_export = (Page<Camera>) Utils.getSession().getAttribute("page_export");
    DetachedCriteria criteria_export = (DetachedCriteria) Utils.getSession().getAttribute("criteria_export");
    List<Order> orderList_export = (List<Order>) Utils.getSession().getAttribute("orderList_export");
    page_export.setPageSize(page_export.getTotalCount());
    Page<Camera> pageResult = dao.getBatch(page_export, criteria_export.getExecutableCriteria(dao.getSession()),
            orderList_export);// w w  w  .j av a  2s  .  c  o m
    if (null != pageResult) {
        if (0 != pageResult.getResult().size()) {
            data = pageResult.getResult();

        }
    }
    ExportExcel ee = new ExportExcel() {

        @Override
        protected HSSFWorkbook disposeData(HSSFWorkbook wb, Object[] total, List<?> data) throws IOException {
            HSSFSheet sheet = wb.getSheetAt(0);
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
            HSSFRow rowss = sheet.createRow(0);
            rowss.setHeightInPoints(20);
            HSSFCell hssfCell = rowss.createCell(0);
            hssfCell = this.createCell(wb, hssfCell, total[0].toString());
            HSSFCellStyle style = this.createStyle(wb);
            HSSFRow row2 = sheet.createRow(1);
            HSSFCell cellrow01 = row2.createCell(0);
            cellrow01.setCellStyle(style);
            HSSFCell cellrow02 = row2.createCell(1);
            cellrow02.setCellStyle(style);
            HSSFCell cellrow03 = row2.createCell(2);
            cellrow03.setCellStyle(style);
            HSSFCell cellrow04 = row2.createCell(3);
            cellrow04.setCellStyle(style);
            HSSFCell cellrow05 = row2.createCell(4);
            cellrow05.setCellStyle(style);
            HSSFCell cellrow06 = row2.createCell(5);
            cellrow06.setCellStyle(style);
            HSSFCell cellrow07 = row2.createCell(6);
            cellrow07.setCellStyle(style);

            cellrow01.setCellValue("No.");
            cellrow02.setCellValue("Camera Name");
            cellrow03.setCellValue("Department");
            cellrow04.setCellValue("Camera Model");
            cellrow05.setCellValue("IP");
            cellrow06.setCellValue("Login Username");
            cellrow07.setCellValue("Login Password");

            if (null != data && 0 != data.size()) {

                for (int i = 0; i < data.size(); i++) {
                    Object[] o = (Object[]) data.get(i);
                    CamModel cm = (CamModel) o[0];
                    Camera a = (Camera) o[1];

                    HSSFRow row = sheet.createRow(i + 2);
                    HSSFCell cell001 = row.createCell(0);
                    cell001.setCellStyle(style);
                    cell001.setCellValue(i + 1);
                    HSSFCell cell002 = row.createCell(1);
                    cell002.setCellStyle(style);
                    cell002.setCellValue(a.getCameraName());
                    HSSFCell cell003 = row.createCell(2);
                    cell003.setCellStyle(style);
                    cell003.setCellValue(a.getDeptname());
                    HSSFCell cell004 = row.createCell(3);
                    cell004.setCellStyle(style);
                    cell004.setCellValue(cm.getModelName());

                    HSSFCell cell005 = row.createCell(4);
                    cell005.setCellStyle(style);
                    cell005.setCellValue(a.getIpAddress());

                    HSSFCell cell006 = row.createCell(5);
                    cell006.setCellStyle(style);
                    cell006.setCellValue(a.getAdminName());
                    HSSFCell cell007 = row.createCell(6);
                    cell007.setCellStyle(style);
                    cell007.setCellValue(a.getAdminPass());

                }
            }

            return wb;
        }
    };

    Object[] total = new Object[1];
    total[0] = title;
    String str = title;
    return ee.export(total, data, str);
}

From source file:com.zdtx.ifms.specific.service.task.FuelMileageManager.java

@SuppressWarnings("unchecked")
public InputStream getData(Page<Mileageoil> page, List<Mileageoil> list, FuelMileageVo fmvo) {

    //Page<Mileageoil> pageResult = this.getBetch(page, fmvo);

    Page<Mileageoil> page_export = (Page<Mileageoil>) Struts2Util.getSession().getAttribute("page_export");
    DetachedCriteria criteria_export = (DetachedCriteria) Struts2Util.getSession()
            .getAttribute("criteria_export");
    List<Order> orderList_export = (List<Order>) Struts2Util.getSession().getAttribute("orderList_export");
    page_export.setPageSize(page_export.getTotalCount());
    Page<Mileageoil> pageResult = baseDao.getBatch(page_export,
            criteria_export.getExecutableCriteria(baseDao.getSession()), orderList_export);

    List<Mileageoil> data = new ArrayList<Mileageoil>();

    if (null != pageResult) {
        if (0 != pageResult.getResult().size()) {
            data = pageResult.getResult();
        }// ww w  . j  a v  a  2s  .c o m
    }
    ExportExcel ee = new ExportExcel() {

        @Override
        protected HSSFWorkbook disposeData(HSSFWorkbook wb, Object[] total, List<?> data) throws IOException {
            HSSFSheet sheet = wb.getSheetAt(0);
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
            HSSFRow rowss = sheet.createRow(0);
            rowss.setHeightInPoints(20);
            HSSFCell hssfCell = rowss.createCell(0);
            hssfCell = this.createCell(wb, hssfCell, "Fuel Mileage");
            HSSFCellStyle style = this.createStyle(wb);
            HSSFRow row2 = sheet.createRow(1);
            HSSFCell cellrow01 = row2.createCell(0);
            cellrow01.setCellStyle(style);
            HSSFCell cellrow02 = row2.createCell(1);
            cellrow02.setCellStyle(style);
            HSSFCell cellrow03 = row2.createCell(2);
            cellrow03.setCellStyle(style);
            HSSFCell cellrow04 = row2.createCell(3);
            cellrow04.setCellStyle(style);
            HSSFCell cellrow05 = row2.createCell(4);
            cellrow05.setCellStyle(style);
            HSSFCell cellrow06 = row2.createCell(5);
            cellrow06.setCellStyle(style);
            cellrow01.setCellValue("No.");
            cellrow02.setCellValue("Plate Number");
            cellrow03.setCellValue("Vehicle Type");
            cellrow04.setCellValue("Date");
            cellrow05.setCellValue("Mileage");
            cellrow06.setCellValue("Fuel consumption");
            if (null != data && 0 != data.size()) {
                for (int i = 0; i < data.size(); i++) {
                    HSSFRow row = sheet.createRow(i + 2);
                    Mileageoil o = (Mileageoil) data.get(i);
                    HSSFCell cell001 = row.createCell(0);
                    cell001.setCellStyle(style);
                    cell001.setCellValue(i + 1);
                    HSSFCell cell002 = row.createCell(1);
                    cell002.setCellStyle(style);
                    cell002.setCellValue(o.getVehiclename());
                    HSSFCell cell003 = row.createCell(2);
                    cell003.setCellStyle(style);
                    cell003.setCellValue(o.getTypename());
                    HSSFCell cell004 = row.createCell(3);
                    cell004.setCellStyle(style);
                    cell004.setCellValue(o.getRiqi());
                    HSSFCell cell005 = row.createCell(4);
                    cell005.setCellStyle(style);
                    cell005.setCellValue(o.getMileage() + "m");
                    HSSFCell cell006 = row.createCell(5);
                    cell006.setCellStyle(style);
                    cell006.setCellValue(o.getOilcost() == null ? "0" : o.getOilcost() + "L");

                }
            }
            return wb;
        }

    };

    Object[] total = new Object[1];
    total[0] = "";
    String str = "Fuel Mileage";
    return ee.export(total, data, str);
}

From source file:com.zdtx.ifms.specific.service.vehicle.VehicleListManager.java

@SuppressWarnings("unchecked")
public InputStream getExcel(String title) {
    List<VehcileView> data = new ArrayList<VehcileView>();
    Page<VehcileView> page_export = (Page<VehcileView>) Utils.getSession().getAttribute("page_export");
    DetachedCriteria criteria_export = (DetachedCriteria) Utils.getSession().getAttribute("criteria_export");
    List<Order> orderList_export = (List<Order>) Utils.getSession().getAttribute("orderList_export");
    page_export.setPageSize(page_export.getTotalCount());
    Page<VehcileView> pageResult = baseDao.getBatch(page_export,
            criteria_export.getExecutableCriteria(baseDao.getSession()), orderList_export);
    if (null != pageResult) {
        if (0 != pageResult.getResult().size()) {
            data = pageResult.getResult();

        }//w w  w  . j  a  v a 2 s.co  m
    }
    ExportExcel ee = new ExportExcel() {

        @Override
        protected HSSFWorkbook disposeData(HSSFWorkbook wb, Object[] total, List<?> data) throws IOException {
            HSSFSheet sheet = wb.getSheetAt(0);
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
            HSSFRow rowss = sheet.createRow(0);
            rowss.setHeightInPoints(20);
            HSSFCell hssfCell = rowss.createCell(0);
            hssfCell = this.createCell(wb, hssfCell, total[0].toString());
            HSSFCellStyle style = this.createStyle(wb);
            HSSFRow row2 = sheet.createRow(1);
            HSSFCell cellrow01 = row2.createCell(0);
            cellrow01.setCellStyle(style);
            HSSFCell cellrow02 = row2.createCell(1);
            cellrow02.setCellStyle(style);
            HSSFCell cellrow03 = row2.createCell(2);
            cellrow03.setCellStyle(style);
            HSSFCell cellrow04 = row2.createCell(3);
            cellrow04.setCellStyle(style);
            HSSFCell cellrow05 = row2.createCell(4);
            cellrow05.setCellStyle(style);
            HSSFCell cellrow06 = row2.createCell(5);
            cellrow06.setCellStyle(style);
            HSSFCell cellrow07 = row2.createCell(6);
            cellrow07.setCellStyle(style);
            HSSFCell cellrow08 = row2.createCell(7);
            cellrow08.setCellStyle(style);
            HSSFCell cellrow09 = row2.createCell(8);
            cellrow09.setCellStyle(style);
            HSSFCell cellrow10 = row2.createCell(9);
            cellrow10.setCellStyle(style);

            cellrow01.setCellValue("No.");
            cellrow02.setCellValue("Plate Number");
            cellrow03.setCellValue("Fleet");
            cellrow04.setCellValue("Department");

            cellrow05.setCellValue("Device");
            cellrow06.setCellValue("Vehicle Type");
            cellrow07.setCellValue("Vehicle Brand");
            cellrow08.setCellValue("Key Code");
            cellrow09.setCellValue("IP");
            cellrow10.setCellValue("Description");

            if (null != data && 0 != data.size()) {

                for (int i = 0; i < data.size(); i++) {
                    VehcileView a = (VehcileView) data.get(i);

                    HSSFRow row = sheet.createRow(i + 2);
                    HSSFCell cell001 = row.createCell(0);
                    cell001.setCellStyle(style);
                    cell001.setCellValue(i + 1);
                    HSSFCell cell002 = row.createCell(1);
                    cell002.setCellStyle(style);
                    cell002.setCellValue(a.getVehiclename());
                    HSSFCell cell003 = row.createCell(2);
                    cell003.setCellStyle(style);
                    cell003.setCellValue(a.getFleetname());
                    HSSFCell cell004 = row.createCell(3);
                    cell004.setCellStyle(style);
                    cell004.setCellValue(a.getDeptname());

                    HSSFCell cell005 = row.createCell(4);
                    cell005.setCellStyle(style);
                    cell005.setCellValue(a.getDevicename());

                    HSSFCell cell006 = row.createCell(5);
                    cell006.setCellStyle(style);
                    cell006.setCellValue(a.getTypename());

                    HSSFCell cell007 = row.createCell(6);
                    cell007.setCellStyle(style);
                    cell007.setCellValue(a.getBrandname());

                    HSSFCell cell008 = row.createCell(7);
                    cell008.setCellStyle(style);
                    cell008.setCellValue(a.getKeycode());

                    HSSFCell cell009 = row.createCell(8);
                    cell009.setCellStyle(style);
                    cell009.setCellValue(a.getCctvip());

                    HSSFCell cell010 = row.createCell(9);
                    cell010.setCellStyle(style);
                    cell010.setCellValue(a.getDescription());

                }
            }

            return wb;
        }
    };

    Object[] total = new Object[1];
    total[0] = title;
    String str = title;
    return ee.export(total, data, str);
}

From source file:com.zhu.action.CarAction.java

public void exportpeople(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) {/*from  ww w  .ja  v  a2s  .com*/
    CarForm carForm = (CarForm) form;

    // webbookExcel
    HSSFWorkbook wb = new HSSFWorkbook();
    // webbooksheet,Excelsheet
    HSSFSheet sheet = wb.createSheet("?");
    // sheet0,??poiExcel?short
    HSSFRow row = sheet.createRow((int) 0);
    // ? 
    HSSFCellStyle style = wb.createCellStyle();
    style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // ?
    HSSFCell cell = row.createCell(0);
    cell.setCellValue("??");
    cell.setCellStyle(style);
    cell = row.createCell(1);
    cell.setCellValue("???");
    cell.setCellStyle(style);
    // ? ??
    OrderService orderService = new OrderService();
    List<Orderinfo> list = orderService.getOrderCarDetail(carForm.getId());
    System.out.println(list.size());
    for (int i = 0; i < list.size(); i++) {
        row = sheet.createRow(i + 1);
        Orderinfo order = (Orderinfo) list.get(i);
        // ?
        row.createCell(0).setCellValue(order.getN1());
        row.createCell(1).setCellValue(order.getI1());
        row = sheet.createRow(i + list.size() + 1);
        row.createCell(0).setCellValue(order.getN2());
        row.createCell(1).setCellValue(order.getI2());
        row = sheet.createRow(i + list.size() + list.size() + 1);
        row.createCell(0).setCellValue(order.getN3());
        row.createCell(1).setCellValue(order.getI3());
        row = sheet.createRow(i + list.size() + list.size() + list.size() + 1);
        row.createCell(0).setCellValue(order.getN4());
        row.createCell(1).setCellValue(order.getI4());
        row = sheet.createRow(i + list.size() + list.size() + list.size() + list.size() + 1);
        row.createCell(0).setCellValue(order.getN5());
        row.createCell(1).setCellValue(order.getI5());
        row = sheet.createRow(i + list.size() + list.size() + list.size() + list.size() + list.size() + 1);
        row.createCell(0).setCellValue(order.getN6());
        row.createCell(1).setCellValue(order.getI6());
        row = sheet.createRow(
                i + list.size() + list.size() + list.size() + list.size() + list.size() + list.size() + 1);
        row.createCell(0).setCellValue(order.getN7());
        row.createCell(1).setCellValue(order.getI7());
        row = sheet.createRow(i + list.size() + list.size() + list.size() + list.size() + list.size()
                + list.size() + list.size() + 1);
        row.createCell(0).setCellValue(order.getN8());
        row.createCell(1).setCellValue(order.getI8());
        row = sheet.createRow(i + list.size() + list.size() + list.size() + list.size() + list.size()
                + list.size() + list.size() + list.size() + 1);
        row.createCell(0).setCellValue(order.getN9());
        row.createCell(1).setCellValue(order.getI9());
        row = sheet.createRow(i + list.size() + list.size() + list.size() + list.size() + list.size()
                + list.size() + list.size() + list.size() + list.size() + 1);
        row.createCell(0).setCellValue(order.getN10());
        row.createCell(1).setCellValue(order.getI10());
    }
    // ?
    String filePath = "";
    Date dt = new Date();
    DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
    String date = df.format(dt).toString();
    filePath = "/Users/Nemo/Documents/carpeople" + date + ".xls";
    File file = new File(filePath);

    try {
        // FileOutputStream fout = new FileOutputStream(
        // "/Users/Nemo/Documents/carpeople.xls");
        // wb.write(fout);
        // fout.close();
        OutputStream out = new FileOutputStream(file);
        wb.write(out);
        out.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
    int key = 0;
    int MaxRowNum = 0, MaxCellNum = 0;
    try {
        FileInputStream in = new FileInputStream(filePath);
        POIFSFileSystem fs = new POIFSFileSystem(in);
        HSSFWorkbook workbook = new HSSFWorkbook(fs);
        FileOutputStream out = new FileOutputStream("/Users/Nemo/Documents/carpeople" + date + ".xls");
        int number = workbook.getNumberOfSheets();
        for (int i = 0; i < number; i++) { // ?sheet
            sheet = workbook.getSheetAt(i); // 14
            System.out.println("" + sheet.getSheetName() + " ? "
                    + (sheet.getLastRowNum() + 1));
            MaxRowNum = 0;
            for (int k = 0; k <= sheet.getLastRowNum(); k++) {
                HSSFRow hRow = sheet.getRow(k);
                // System.out.println((k + 1) + "");
                if (isBlankRow(hRow)) // 
                {
                    int m = 0;
                    for (m = k + 1; m <= sheet.getLastRowNum(); m++) {
                        HSSFRow nhRow = sheet.getRow(m);
                        if (!isBlankRow(nhRow)) {
                            // System.out.println("?" + (m + 1));
                            sheet.shiftRows(m, sheet.getLastRowNum(), k - m);
                            break;
                        }
                    }
                    if (m > sheet.getLastRowNum())
                        break; // ?
                } else { // ?
                    MaxRowNum++;
                    if (MaxCellNum < hRow.getLastCellNum())
                        MaxCellNum = hRow.getLastCellNum();
                }
            }
            workbook.setPrintArea(i, 0, MaxCellNum, 0, MaxRowNum);
            System.out
                    .println("?? " + sheet.getSheetName() + "  " + MaxRowNum);
        }
        workbook.write(out);
        in.close();
        out.close();
    } catch (IOException e) {
        System.out.println(key + " " + e.getMessage() + " ");
        e.printStackTrace();

    }

    System.out.println("??");

}

From source file:com.zhu.action.CarAction.java

public void export(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) {/*ww w . j a  v  a  2s. co m*/
    // webbookExcel
    HSSFWorkbook wb = new HSSFWorkbook();
    // webbooksheet,Excelsheet
    HSSFSheet sheet = wb.createSheet("?");
    // sheet0,??poiExcel?short
    HSSFRow row = sheet.createRow((int) 0);
    // ? 
    HSSFCellStyle style = wb.createCellStyle();
    style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // ?
    HSSFCell cell = row.createCell(0);
    cell.setCellValue("id");
    cell.setCellStyle(style);
    cell = row.createCell(1);
    cell.setCellValue("?");
    cell.setCellStyle(style);
    cell = row.createCell(2);
    cell.setCellValue("");
    cell.setCellStyle(style);
    cell = row.createCell(3);
    cell.setCellValue("");
    cell.setCellStyle(style);
    cell = row.createCell(4);
    cell.setCellValue("");
    cell.setCellStyle(style);
    cell = row.createCell(5);
    cell.setCellValue("");
    cell.setCellStyle(style);
    cell = row.createCell(6);
    cell.setCellValue("");
    cell.setCellStyle(style);
    cell = row.createCell(7);
    cell.setCellValue("?");
    cell.setCellStyle(style);
    cell = row.createCell(8);
    cell.setCellValue("?");
    cell.setCellStyle(style);
    // ? ??
    CarService carService = new CarService();
    List<Car> list = carService.getCar();

    for (int i = 0; i < list.size(); i++) {
        row = sheet.createRow((int) i + 1);
        Car car = (Car) list.get(i);
        // ?
        row.createCell(0).setCellValue(car.getId());
        row.createCell(1).setCellValue(car.getCarid());
        row.createCell(2).setCellValue(car.getLicense());
        row.createCell(3).setCellValue(car.getNumber());
        row.createCell(4).setCellValue(car.getPeople());
        row.createCell(5).setCellValue(car.getRoute());
        row.createCell(6).setCellValue(car.getStartdate());
        row.createCell(7).setCellValue(car.getEnddate());
        if (car.getStatus() == 0) {
            row.createCell(8).setCellValue("");
        } else if (car.getStatus() == 1) {
            row.createCell(8).setCellValue("");
        } else {
            row.createCell(8).setCellValue("");
        }
        // cell = row.createCell((short) 3);
    }
    // ?
    String filePath = "";
    Date dt = new Date();
    DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
    String date = df.format(dt).toString();
    filePath = "/Users/Nemo/Documents/car" + date + ".xls";
    File file = new File(filePath);
    try {
        FileOutputStream fout = new FileOutputStream(file);
        wb.write(fout);
        fout.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Congruential.MultiplierConstant.java

public void calcNumbers(String x0, String constanteante, String _cant, String d) {
    int cant = Integer.parseInt(_cant), largonum = 0, corte = 0;
    String y = "", nextx0 = "", random = "";

    try {/*from  w w w . j a  va 2  s .  c  om*/
        if (archivoXLS.exists()) {
            archivoXLS.delete();
        }
        archivoXLS.createNewFile();
        Workbook libro = new HSSFWorkbook();

        FileOutputStream archivo = new FileOutputStream(archivoXLS);
        Sheet hoja = libro.createSheet("Mi hoja de trabajo 1");

        HSSFRow fila = (HSSFRow) hoja.createRow(0);
        Cell celda = fila.createCell(0);
        celda.setCellValue("y");
        celda = fila.createCell(1);
        celda.setCellValue("x");
        celda = fila.createCell(2);
        celda.setCellValue("r");

        for (int i = 0; i < cant; i++) {
            y = "" + Integer.parseInt(constanteante) * Integer.parseInt(x0);
            largonum = y.length();

            corte = largonum - Integer.parseInt(d);

            if (corte % 2 != 0) {
                y = "0" + y;
                corte++;
            }
            corte = corte / 2;
            nextx0 = y.substring(corte, y.length());

            x0 = nextx0.substring(0, nextx0.length() - corte);
            random = "0." + x0;

            fila = (HSSFRow) hoja.createRow(i + 1);
            celda = fila.createCell(0);
            celda.setCellValue(y);
            celda = fila.createCell(1);
            celda.setCellValue(x0);
            celda = fila.createCell(2);
            celda.setCellValue(random);
        }

        libro.write(archivo);
        archivo.close();
    } catch (IOException e) {
    }
}