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

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

Introduction

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

Prototype

@Override
public HSSFDataFormat createDataFormat() 

Source Link

Document

Returns the instance of HSSFDataFormat for this workbook.

Usage

From source file:com.smi.travel.migration.MainMigrate.java

public static void ExportTaxinvoiceReport(List reptax) {
    UtilityExcelFunction excelFunction = new UtilityExcelFunction();
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("TaxInvoice");

    HSSFCellStyle styleC1 = wb.createCellStyle();
    // Set align Text
    HSSFCellStyle styleC21 = wb.createCellStyle();
    styleC21.setAlignment(styleC21.ALIGN_RIGHT);
    HSSFCellStyle styleC22 = wb.createCellStyle();
    styleC22.setAlignment(styleC22.ALIGN_LEFT);

    HSSFRow row1 = sheet.createRow(0);// ww  w .  j  av  a 2  s . c o m
    HSSFCell cellStart = row1.createCell(0);
    cellStart.setCellValue("Tax Invoice Report");
    styleC1.setFont(excelFunction.getHeaderFont(wb.createFont()));
    cellStart.setCellStyle(styleC1);
    sheet.addMergedRegion(CellRangeAddress.valueOf("A1:F1"));

    // Header Table
    HSSFCellStyle styleC3Center = wb.createCellStyle();
    styleC3Center.setFont(excelFunction.getHeaderTable(wb.createFont()));
    styleC3Center.setAlignment(styleC3Center.ALIGN_CENTER);
    styleC3Center.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    styleC3Center.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    styleC3Center.setBorderRight(HSSFCellStyle.BORDER_THIN);
    styleC3Center.setBorderTop(HSSFCellStyle.BORDER_THIN);

    HSSFRow row2 = sheet.createRow(2);
    HSSFCell cell20 = row2.createCell(0);
    cell20.setCellValue("ID");
    cell20.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(0);
    HSSFCell cell21 = row2.createCell(1);
    cell21.setCellValue("TAX ID");
    cell21.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(1);
    HSSFCell cell22 = row2.createCell(2);
    cell22.setCellValue("TAX NO");
    cell22.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(2);
    HSSFCell cell23 = row2.createCell(3);
    cell23.setCellValue("TAX DATE");
    cell23.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(3);
    HSSFCell cell24 = row2.createCell(4);
    cell24.setCellValue("CODE AP");
    cell24.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(4);
    HSSFCell cell25 = row2.createCell(5);
    cell25.setCellValue("DESCRIPTION");
    cell25.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(5);
    HSSFCell cell26 = row2.createCell(6);
    cell26.setCellValue("GROSS AMOUNT");
    cell26.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(6);
    HSSFCell cell27 = row2.createCell(7);
    cell27.setCellValue("VAT AMOUNT");
    cell27.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(7);
    HSSFCell cell28 = row2.createCell(8);
    cell28.setCellValue("AMOUNT");
    cell28.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(8);
    HSSFCell cell29 = row2.createCell(9);
    cell29.setCellValue("FLAG TYPE");
    cell29.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(9);
    HSSFCell cell30 = row2.createCell(10);
    cell30.setCellValue("INVOICE TYPE");
    cell30.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(10);
    HSSFCell cell31 = row2.createCell(11);
    cell31.setCellValue("TAX NO 1");
    cell31.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(11);
    HSSFCell cell32 = row2.createCell(12);
    cell32.setCellValue("BRANCH");
    cell32.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(12);
    HSSFCell cell33 = row2.createCell(13);
    cell33.setCellValue("BRANCH NO");
    cell33.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(13);

    int count = 3;

    HSSFDataFormat currency = wb.createDataFormat();
    HSSFCellStyle styleC23 = wb.createCellStyle();
    styleC23.setAlignment(styleC23.ALIGN_CENTER);
    styleC23.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    styleC23.setBorderRight(HSSFCellStyle.BORDER_THIN);
    HSSFCellStyle styleC24 = wb.createCellStyle();
    styleC24.setAlignment(styleC24.ALIGN_LEFT);
    styleC24.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    styleC24.setBorderRight(HSSFCellStyle.BORDER_THIN);
    HSSFCellStyle styleC25 = wb.createCellStyle();
    styleC25.setAlignment(styleC25.ALIGN_RIGHT);
    styleC25.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    styleC25.setBorderRight(HSSFCellStyle.BORDER_THIN);
    styleC25.setDataFormat(currency.getFormat("#,##0.00"));

    for (int i = 0; i < reptax.size(); i++) {
        ReportTaxInvoice data = (ReportTaxInvoice) reptax.get(i);
        HSSFRow row = sheet.createRow(count + i);
        HSSFCell cell0 = row.createCell(0);
        cell0.setCellValue(data.getId());
        cell0.setCellStyle(styleC23);
        HSSFCell cell1 = row.createCell(1);
        cell1.setCellValue(data.getTaxid());
        cell1.setCellStyle(styleC23);
        HSSFCell cell13 = row.createCell(2);
        cell13.setCellValue(data.getTaxno());
        cell13.setCellStyle(styleC23);
        HSSFCell cell2 = row.createCell(3);
        cell2.setCellValue(String.valueOf(data.getTaxdate()));
        cell2.setCellStyle(styleC23);
        HSSFCell cell3 = row.createCell(4);
        cell3.setCellValue(data.getCodeap());
        cell3.setCellStyle(styleC24);
        HSSFCell cell4 = row.createCell(5);
        cell4.setCellValue(data.getDescription().trim());
        cell4.setCellStyle(styleC24);
        HSSFCell cell5 = row.createCell(6);
        cell5.setCellValue(!"null".equalsIgnoreCase(String.valueOf(data.getGrossamount()))
                ? (data.getGrossamount()).doubleValue()
                : 0);
        cell5.setCellStyle(styleC25);
        HSSFCell cell6 = row.createCell(7);
        cell6.setCellValue(!"null".equalsIgnoreCase(String.valueOf(data.getVatamount()))
                ? (data.getVatamount()).doubleValue()
                : 0);
        cell6.setCellStyle(styleC25);
        HSSFCell cell7 = row.createCell(8);
        cell7.setCellValue(
                !"null".equalsIgnoreCase(String.valueOf(data.getAmount())) ? (data.getAmount()).doubleValue()
                        : 0);
        cell7.setCellStyle(styleC25);
        HSSFCell cell8 = row.createCell(9);
        cell8.setCellValue(data.getFlagtype());
        cell8.setCellStyle(styleC23);
        HSSFCell cell9 = row.createCell(10);
        cell9.setCellValue(data.getInvoicetype());
        cell9.setCellStyle(styleC24);
        HSSFCell cell10 = row.createCell(11);
        cell10.setCellValue(data.getTaxno1());
        cell10.setCellStyle(styleC24);
        HSSFCell cell11 = row.createCell(12);
        cell11.setCellValue(data.getBranch());
        cell11.setCellStyle(styleC24);
        HSSFCell cell12 = row.createCell(13);
        cell12.setCellValue(data.getBranchno());
        cell12.setCellStyle(styleC23);

    }
    for (int j = 0; j < 15; j++) {
        sheet.autoSizeColumn(j);
    }
    sheet.setColumnWidth(5, 256 * 40);//27
    exportFileExcel("TaxInvoiceReport", wb);
}

From source file:com.smi.travel.migration.MainMigrate.java

public static void ExportAgentReport(List repAgent) {
    UtilityExcelFunction excelFunction = new UtilityExcelFunction();
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("Agent");

    HSSFCellStyle styleC1 = wb.createCellStyle();
    // Set align Text
    HSSFCellStyle styleC21 = wb.createCellStyle();
    styleC21.setAlignment(styleC21.ALIGN_RIGHT);
    HSSFCellStyle styleC22 = wb.createCellStyle();
    styleC22.setAlignment(styleC22.ALIGN_LEFT);

    HSSFRow row1 = sheet.createRow(0);/* w w  w  .j a va 2  s.  c  o  m*/
    HSSFCell cellStart = row1.createCell(0);
    cellStart.setCellValue("Agent Report");
    styleC1.setFont(excelFunction.getHeaderFont(wb.createFont()));
    cellStart.setCellStyle(styleC1);
    sheet.addMergedRegion(CellRangeAddress.valueOf("A1:F1"));

    // Header Table
    HSSFCellStyle styleC3Center = wb.createCellStyle();
    styleC3Center.setFont(excelFunction.getHeaderTable(wb.createFont()));
    styleC3Center.setAlignment(styleC3Center.ALIGN_CENTER);
    styleC3Center.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    styleC3Center.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    styleC3Center.setBorderRight(HSSFCellStyle.BORDER_THIN);
    styleC3Center.setBorderTop(HSSFCellStyle.BORDER_THIN);

    HSSFRow row2 = sheet.createRow(2);
    HSSFCell cell20 = row2.createCell(0);
    cell20.setCellValue("ID");
    cell20.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(0);
    HSSFCell cell21 = row2.createCell(1);
    cell21.setCellValue("SYSTEM DATE");
    cell21.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(1);
    HSSFCell cell22 = row2.createCell(2);
    cell22.setCellValue("SYSTEM STAFF");
    cell22.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(2);
    HSSFCell cell23 = row2.createCell(3);
    cell23.setCellValue("CODE");
    cell23.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(3);
    HSSFCell cell24 = row2.createCell(4);
    cell24.setCellValue("NAME");
    cell24.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(4);
    HSSFCell cell25 = row2.createCell(5);
    cell25.setCellValue("ADDRESS");
    cell25.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(5);
    HSSFCell cell26 = row2.createCell(6);
    cell26.setCellValue("TEL");
    cell26.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(6);
    HSSFCell cell27 = row2.createCell(7);
    cell27.setCellValue("FAX");
    cell27.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(7);
    HSSFCell cell28 = row2.createCell(8);
    cell28.setCellValue("DESCRIPTION");
    cell28.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(8);
    HSSFCell cell29 = row2.createCell(9);
    cell29.setCellValue("NAME T");
    cell29.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(9);
    HSSFCell cell30 = row2.createCell(10);
    cell30.setCellValue("DESCRIPTION T");
    cell30.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(10);
    HSSFCell cell31 = row2.createCell(11);
    cell31.setCellValue("ADDRESS T");
    cell31.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(11);
    HSSFCell cell32 = row2.createCell(12);
    cell32.setCellValue("EMAIL");
    cell32.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(12);
    HSSFCell cell33 = row2.createCell(13);
    cell33.setCellValue("WEB");
    cell33.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(13);
    HSSFCell cell34 = row2.createCell(14);
    cell34.setCellValue("REMARKS");
    cell34.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(14);
    HSSFCell cell35 = row2.createCell(15);
    cell35.setCellValue("WARNING");
    cell35.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(15);
    HSSFCell cell36 = row2.createCell(16);
    cell36.setCellValue("REF ID");
    cell36.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(16);
    HSSFCell cell37 = row2.createCell(17);
    cell37.setCellValue("BRANCH");
    cell37.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(17);
    HSSFCell cell38 = row2.createCell(18);
    cell38.setCellValue("BRANCH NO");
    cell38.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(18);
    HSSFCell cell39 = row2.createCell(19);
    cell39.setCellValue("TAX NO");
    cell39.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(19);

    int count = 3;

    HSSFDataFormat currency = wb.createDataFormat();
    HSSFCellStyle styleC23 = wb.createCellStyle();
    styleC23.setAlignment(styleC23.ALIGN_CENTER);
    styleC23.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    styleC23.setBorderRight(HSSFCellStyle.BORDER_THIN);
    HSSFCellStyle styleC24 = wb.createCellStyle();
    styleC24.setAlignment(styleC24.ALIGN_LEFT);
    styleC24.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    styleC24.setBorderRight(HSSFCellStyle.BORDER_THIN);
    HSSFCellStyle styleC25 = wb.createCellStyle();
    styleC25.setAlignment(styleC25.ALIGN_RIGHT);
    styleC25.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    styleC25.setBorderRight(HSSFCellStyle.BORDER_THIN);
    styleC25.setDataFormat(currency.getFormat("#,##0.00"));

    for (int i = 0; i < repAgent.size(); i++) {
        ReportAgent data = (ReportAgent) repAgent.get(i);
        HSSFRow row = sheet.createRow(count + i);
        HSSFCell cell0 = row.createCell(0);
        cell0.setCellValue(data.getId());
        cell0.setCellStyle(styleC23);
        HSSFCell cell1 = row.createCell(1);
        cell1.setCellValue(String.valueOf(data.getSystemdate()));
        cell1.setCellStyle(styleC23);
        HSSFCell cell13 = row.createCell(2);
        cell13.setCellValue(data.getSystemstaff());
        cell13.setCellStyle(styleC24);
        HSSFCell cell2 = row.createCell(3);
        cell2.setCellValue(data.getCode());
        cell2.setCellStyle(styleC24);
        HSSFCell cell3 = row.createCell(4);
        cell3.setCellValue(data.getName());
        cell3.setCellStyle(styleC24);
        HSSFCell cell4 = row.createCell(5);
        cell4.setCellValue(data.getAddress().trim());
        cell4.setCellStyle(styleC24);
        HSSFCell cell5 = row.createCell(6);
        cell5.setCellValue(data.getTel());
        cell5.setCellStyle(styleC24);
        HSSFCell cell6 = row.createCell(7);
        cell6.setCellValue(data.getFax());
        cell6.setCellStyle(styleC24);
        HSSFCell cell7 = row.createCell(8);
        cell7.setCellValue(data.getDescription().trim());
        cell7.setCellStyle(styleC24);
        HSSFCell cell8 = row.createCell(9);
        cell8.setCellValue(data.getNameT());
        cell8.setCellStyle(styleC24);
        HSSFCell cell9 = row.createCell(10);
        cell9.setCellValue(data.getDescriptionT().trim());
        cell9.setCellStyle(styleC24);
        HSSFCell cell10 = row.createCell(11);
        cell10.setCellValue(data.getAddressT().trim());
        cell10.setCellStyle(styleC24);
        HSSFCell cell11 = row.createCell(12);
        cell11.setCellValue(data.getEmail());
        cell11.setCellStyle(styleC24);
        HSSFCell cell12 = row.createCell(13);
        cell12.setCellValue(data.getWeb());
        cell12.setCellStyle(styleC24);
        HSSFCell cell14 = row.createCell(14);
        cell14.setCellValue(data.getRemarks());
        cell14.setCellStyle(styleC24);
        HSSFCell cell15 = row.createCell(15);
        cell15.setCellValue(data.getWarning());
        cell15.setCellStyle(styleC24);
        HSSFCell cell16 = row.createCell(16);
        cell16.setCellValue(data.getRefid());
        cell16.setCellStyle(styleC24);
        HSSFCell cell17 = row.createCell(17);
        cell17.setCellValue(data.getBranch());
        cell17.setCellStyle(styleC24);
        HSSFCell cell18 = row.createCell(18);
        cell18.setCellValue(data.getBranchno());
        cell18.setCellStyle(styleC24);
        HSSFCell cell19 = row.createCell(19);
        cell19.setCellValue(data.getTaxno());
        cell19.setCellStyle(styleC23);
    }

    for (int j = 0; j < 20; j++) {
        sheet.autoSizeColumn(j);
    }

    for (int k = 4; k < 21; k++) {
        if (k != 6 && k != 7 && k != 12 && k != 13 && k < 16) {
            sheet.setColumnWidth(k, 256 * 35);//27
        } else {
            sheet.setColumnWidth(k, 256 * 20);//27
        }
    }
    exportFileExcel("AgentReport", wb);
}

From source file:com.smi.travel.migration.MainMigrate.java

public static void ExportStaffReport(List repStaff) {
    UtilityExcelFunction excelFunction = new UtilityExcelFunction();
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("Staff");

    HSSFCellStyle styleC1 = wb.createCellStyle();
    // Set align Text
    HSSFCellStyle styleC21 = wb.createCellStyle();
    styleC21.setAlignment(styleC21.ALIGN_RIGHT);
    HSSFCellStyle styleC22 = wb.createCellStyle();
    styleC22.setAlignment(styleC22.ALIGN_LEFT);

    HSSFRow row1 = sheet.createRow(0);//from  w  ww  .j av a2s  .  c om
    HSSFCell cellStart = row1.createCell(0);
    cellStart.setCellValue("Staff Report");
    styleC1.setFont(excelFunction.getHeaderFont(wb.createFont()));
    cellStart.setCellStyle(styleC1);
    sheet.addMergedRegion(CellRangeAddress.valueOf("A1:F1"));

    // Header Table
    HSSFCellStyle styleC3Center = wb.createCellStyle();
    styleC3Center.setFont(excelFunction.getHeaderTable(wb.createFont()));
    styleC3Center.setAlignment(styleC3Center.ALIGN_CENTER);
    styleC3Center.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    styleC3Center.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    styleC3Center.setBorderRight(HSSFCellStyle.BORDER_THIN);
    styleC3Center.setBorderTop(HSSFCellStyle.BORDER_THIN);

    HSSFRow row2 = sheet.createRow(2);
    HSSFCell cell20 = row2.createCell(0);
    cell20.setCellValue("ID");
    cell20.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(0);
    HSSFCell cell21 = row2.createCell(1);
    cell21.setCellValue("SYSTEM DATE");
    cell21.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(1);
    HSSFCell cell22 = row2.createCell(2);
    cell22.setCellValue("SYSTEM STAFF");
    cell22.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(2);
    HSSFCell cell23 = row2.createCell(3);
    cell23.setCellValue("CODE");
    cell23.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(3);
    HSSFCell cell24 = row2.createCell(4);
    cell24.setCellValue("NAME");
    cell24.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(4);
    HSSFCell cell25 = row2.createCell(5);
    cell25.setCellValue("PASSWD");
    cell25.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(5);
    HSSFCell cell26 = row2.createCell(6);
    cell26.setCellValue("POSITION");
    cell26.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(6);
    HSSFCell cell27 = row2.createCell(7);
    cell27.setCellValue("DEPARTMENT ID");
    cell27.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(7);
    HSSFCell cell28 = row2.createCell(8);
    cell28.setCellValue("TEL");
    cell28.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(8);
    HSSFCell cell29 = row2.createCell(9);
    cell29.setCellValue("CAR");
    cell29.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(9);
    HSSFCell cell30 = row2.createCell(10);
    cell30.setCellValue("STATUS");
    cell30.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(10);
    HSSFCell cell31 = row2.createCell(11);
    cell31.setCellValue("SIGNATURE");
    cell31.setCellStyle(styleC3Center);
    sheet.autoSizeColumn(11);
    int count = 3;

    HSSFDataFormat currency = wb.createDataFormat();
    HSSFCellStyle styleC23 = wb.createCellStyle();
    styleC23.setAlignment(styleC23.ALIGN_CENTER);
    styleC23.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    styleC23.setBorderRight(HSSFCellStyle.BORDER_THIN);
    HSSFCellStyle styleC24 = wb.createCellStyle();
    styleC24.setAlignment(styleC24.ALIGN_LEFT);
    styleC24.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    styleC24.setBorderRight(HSSFCellStyle.BORDER_THIN);
    HSSFCellStyle styleC25 = wb.createCellStyle();
    styleC25.setAlignment(styleC25.ALIGN_RIGHT);
    styleC25.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    styleC25.setBorderRight(HSSFCellStyle.BORDER_THIN);
    styleC25.setDataFormat(currency.getFormat("#,##0.00"));

    for (int i = 0; i < repStaff.size(); i++) {
        ReportStaff data = (ReportStaff) repStaff.get(i);
        HSSFRow row = sheet.createRow(count + i);
        HSSFCell cell0 = row.createCell(0);
        cell0.setCellValue(data.getId());
        cell0.setCellStyle(styleC23);
        HSSFCell cell1 = row.createCell(1);
        cell1.setCellValue(String.valueOf(data.getSystemdate()));
        cell1.setCellStyle(styleC23);
        HSSFCell cell13 = row.createCell(2);
        cell13.setCellValue(data.getSystemstaff());
        cell13.setCellStyle(styleC24);
        HSSFCell cell2 = row.createCell(3);
        cell2.setCellValue(data.getCode());
        cell2.setCellStyle(styleC24);
        HSSFCell cell3 = row.createCell(4);
        cell3.setCellValue(data.getName());
        cell3.setCellStyle(styleC24);
        HSSFCell cell4 = row.createCell(5);
        cell4.setCellValue(data.getPasswd());
        cell4.setCellStyle(styleC24);
        HSSFCell cell5 = row.createCell(6);
        cell5.setCellValue(data.getPosition());
        cell5.setCellStyle(styleC24);
        HSSFCell cell6 = row.createCell(7);
        cell6.setCellValue(data.getDepartmentid());
        cell6.setCellStyle(styleC24);
        HSSFCell cell7 = row.createCell(8);
        cell7.setCellValue(data.getTel());
        cell7.setCellStyle(styleC24);
        HSSFCell cell8 = row.createCell(9);
        cell8.setCellValue(data.getCar());
        cell8.setCellStyle(styleC24);
        HSSFCell cell9 = row.createCell(10);
        cell9.setCellValue(data.getStatus());
        cell9.setCellStyle(styleC24);
        HSSFCell cell10 = row.createCell(11);
        cell10.setCellValue(data.getSignature());
        cell10.setCellStyle(styleC24);
    }
    for (int j = 0; j < 12; j++) {
        sheet.autoSizeColumn(j);
    }
    //        sheet.setColumnWidth(8, 256*40);//27
    //        sheet.setColumnWidth(10, 256*40);//27
    exportFileExcel("StaffReport", wb);
}

From source file:com.softtek.mdm.web.admin.IndexController.java

private void exportExcel(String sheetName, String[] headNames, List<OrganizationModel> lists,
        HttpServletResponse response) {/*from  ww  w.jav a2  s  . co m*/

    OutputStream out = null;
    try {
        HSSFWorkbook workbook = new HSSFWorkbook(); //   
        HSSFSheet sheet = workbook.createSheet(sheetName); //   
        //   
        HSSFRow rowm = sheet.createRow(0);
        HSSFCell cellTiltle = rowm.createCell(0);
        //sheet??getColumnTopStyle()/getStyle()? - ?  - ?  
        HSSFCellStyle columnTopStyle = CommUtil.getColumnTopStyle(workbook);//??  
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, (headNames.length - 1)));
        cellTiltle.setCellStyle(columnTopStyle);
        cellTiltle.setCellValue(sheetName);
        //   
        int columnNum = headNames.length;
        HSSFRow rowRowName = sheet.createRow(2); // 2?()  
        // sheet?  
        for (int n = 0; n < columnNum; n++) {
            HSSFCell cellRowName = rowRowName.createCell(n); //?  
            cellRowName.setCellType(HSSFCell.CELL_TYPE_STRING); //??  
            HSSFRichTextString text = new HSSFRichTextString(headNames[n]);
            cellRowName.setCellValue(text); //?  
            cellRowName.setCellStyle(columnTopStyle); //??  
        }
        //?sheet?  
        HSSFDataFormat format = workbook.createDataFormat();
        short formatDate = format.getFormat("yyyy-MM-dd hh:mm:ss");
        for (int i = 0; i < lists.size(); i++) {
            HSSFRow row = sheet.createRow(i + 3);//  
            OrganizationModel obj = lists.get(i);//???  
            /*row.createCell(0).setCellValue(obj.getOrgType());*/
            row.createCell(0).setCellValue(obj.getName());
            row.createCell(1).setCellValue(obj.getCreateName());
            row.createCell(2).setCellValue(obj.getTotalUsers() == null ? 0 : obj.getTotalUsers());
            row.createCell(3).setCellValue(obj.getTotalDevices() == null ? 0 : obj.getTotalDevices());
            row.createCell(4).setCellValue(obj.getLicenseCount() == null ? 0 : obj.getLicenseCount());
            row.createCell(5).setCellValue(obj.getUseUsers() == null ? 0 : obj.getUseUsers());
            HSSFCell cell = row.createCell(6);
            cell.setCellValue(obj.getCreateTime());
            HSSFCellStyle cellStyle = workbook.createCellStyle();
            cellStyle.setDataFormat(formatDate);
            cell.setCellStyle(cellStyle);
        }
        //??  
        for (int colNum = 0; colNum < columnNum; colNum++) {
            int columnWidth = sheet.getColumnWidth(colNum) / 256;
            for (int rowNum = 0; rowNum < sheet.getLastRowNum(); rowNum++) {
                HSSFRow currentRow;
                //?  
                currentRow = (sheet.getRow(rowNum) == null) ? sheet.createRow(rowNum) : sheet.getRow(rowNum);
                if (currentRow.getCell(colNum) != null) {
                    HSSFCell currentCell = currentRow.getCell(colNum);
                    if (currentCell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
                        int length = currentCell.getStringCellValue().getBytes().length;
                        if (columnWidth < length) {
                            columnWidth = length;
                        }
                    }
                }
            }
            sheet.setColumnWidth(colNum, (colNum == 0) ? (columnWidth * 256) : ((columnWidth + 10) * 256));
        }
        if (workbook != null) {
            try {
                String fileName = "Excel-" + String.valueOf(System.currentTimeMillis()).substring(4, 13)
                        + ".xls";
                String headStr = "attachment; filename=\"" + fileName + "\"";
                response.setContentType("application/octet-stream");
                response.setHeader("Content-Disposition", headStr);
                out = response.getOutputStream();
                workbook.write(out);
            } catch (IOException e) {
                logger.error(e.getMessage());
            } finally {
                if (out != null) {
                    out.close();
                }
            }
        }
    } catch (Exception e) {
        logger.error(e.getMessage());
    }
}

From source file:com.taobao.itest.dbunit.dataset.excel.XlsDataSetWriter.java

License:Open Source License

protected static HSSFCellStyle createDateCellStyle(HSSFWorkbook workbook) {
    HSSFDataFormat format = workbook.createDataFormat();
    short dateFormatCode = format.getFormat(DATE_FORMAT_AS_NUMBER_DBUNIT);
    HSSFCellStyle dateCellStyle = workbook.createCellStyle();
    dateCellStyle.setDataFormat(dateFormatCode);
    return dateCellStyle;
}

From source file:com.taobao.itest.dbunit.dataset.excel.XlsDataSetWriter.java

License:Open Source License

protected void setNumericCell(HSSFCell cell, BigDecimal value, HSSFWorkbook workbook) {
    if (logger.isDebugEnabled())
        logger.debug("setNumericCell(cell={}, value={}, workbook={}) - start",
                new Object[] { cell, value, workbook });

    cell.setCellValue(((BigDecimal) value).doubleValue());

    HSSFDataFormat df = workbook.createDataFormat();
    int scale = ((BigDecimal) value).scale();
    short format;
    if (scale <= 0) {
        format = df.getFormat("####");
    } else {//w w  w  .j  a  v  a 2  s  . c  o  m
        String zeros = createZeros(((BigDecimal) value).scale());
        format = df.getFormat("####." + zeros);
    }
    if (logger.isDebugEnabled())
        logger.debug("Using format '{}' for value '{}'.", String.valueOf(format), value);

    HSSFCellStyle cellStyleNumber = workbook.createCellStyle();
    cellStyleNumber.setDataFormat(format);
    cell.setCellStyle(cellStyleNumber);
}

From source file:de.maklerpoint.office.Schnittstellen.Excel.ExportExcelXLS.java

License:Open Source License

/**
 * create a library of cell styles/*from   www .  j  ava  2 s.  co  m*/
 */
private static Map<String, HSSFCellStyle> createStyles(HSSFWorkbook wb) {
    Map<String, HSSFCellStyle> styles = new HashMap<String, HSSFCellStyle>();
    HSSFDataFormat df = wb.createDataFormat();

    HSSFCellStyle style;
    HSSFFont headerFont = wb.createFont();
    headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = createBorderedStyle(wb);
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(headerFont);
    styles.put("header", style);

    style = createBorderedStyle(wb);
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(headerFont);
    style.setDataFormat(df.getFormat("dd.MM.yyyy"));
    styles.put("header_date", style);

    HSSFFont font1 = wb.createFont();
    font1.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = createBorderedStyle(wb);
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setFont(font1);
    styles.put("cell_b", style);

    style = createBorderedStyle(wb);
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setFont(font1);
    styles.put("cell_b_centered", style);

    style = createBorderedStyle(wb);
    style.setAlignment(CellStyle.ALIGN_RIGHT);
    style.setFont(font1);
    style.setDataFormat(df.getFormat("dd.MM.yyyy"));
    styles.put("cell_b_date", style);

    style = createBorderedStyle(wb);
    style.setAlignment(CellStyle.ALIGN_RIGHT);
    style.setFont(font1);
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setDataFormat(df.getFormat("dd.MM.yyyy"));
    styles.put("cell_g", style);

    HSSFFont font2 = wb.createFont();
    font2.setColor(IndexedColors.BLUE.getIndex());
    font2.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = createBorderedStyle(wb);
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setFont(font2);
    styles.put("cell_bb", style);

    style = createBorderedStyle(wb);
    style.setAlignment(CellStyle.ALIGN_RIGHT);
    style.setFont(font1);
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setDataFormat(df.getFormat("dd.MM.yyyy"));
    styles.put("cell_bg", style);

    HSSFFont font3 = wb.createFont();
    font3.setFontHeightInPoints((short) 14);
    font3.setColor(IndexedColors.DARK_BLUE.getIndex());
    font3.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = createBorderedStyle(wb);
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setFont(font3);
    style.setWrapText(true);
    styles.put("cell_h", style);

    style = createBorderedStyle(wb);
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setWrapText(true);
    styles.put("cell_normal", style);

    style = createBorderedStyle(wb);
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setWrapText(true);
    styles.put("cell_normal_centered", style);

    style = createBorderedStyle(wb);
    style.setAlignment(CellStyle.ALIGN_RIGHT);
    style.setWrapText(true);
    style.setDataFormat(df.getFormat("dd.MM.yyyy"));
    styles.put("cell_normal_date", style);

    style = createBorderedStyle(wb);
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setIndention((short) 1);
    style.setWrapText(true);
    styles.put("cell_indented", style);

    style = createBorderedStyle(wb);
    style.setFillForegroundColor(IndexedColors.BLUE.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    styles.put("cell_blue", style);

    return styles;
}

From source file:eu.scape_project.pc.tika.cli.MergeReports.java

License:Apache License

private static boolean writeXLS(String outputFilePath) throws Exception {

    int rowCounter = 1; //Start in row 1 (which is the 2nd row). Row 0 holds the description.
    FileOutputStream fileOut = new FileOutputStream(outputFilePath);
    HSSFWorkbook workbook = new HSSFWorkbook();

    HSSFSheet worksheet = workbook.createSheet("Type Report");

    HSSFCellStyle myCellStyle = workbook.createCellStyle();
    myCellStyle.setAlignment(CellStyle.ALIGN_CENTER);

    HSSFCellStyle myCellStylePercent = workbook.createCellStyle();
    HSSFDataFormat df = workbook.createDataFormat();
    myCellStylePercent.setDataFormat(df.getFormat("0.00%"));
    myCellStylePercent.setAlignment(CellStyle.ALIGN_CENTER);

    HSSFRow myHeaderRow = worksheet.createRow(0);
    HSSFCell myHeaderCell0 = myHeaderRow.createCell(0);
    HSSFCell myHeaderCell1 = myHeaderRow.createCell(1);
    HSSFCell myHeaderCell2 = myHeaderRow.createCell(2);

    myHeaderCell0.setCellValue("TYPE");
    myHeaderCell1.setCellValue("COUNT");
    myHeaderCell2.setCellValue("PERCENTAGE");
    myHeaderCell0.setCellStyle(myCellStyle);
    myHeaderCell1.setCellStyle(myCellStyle);
    myHeaderCell2.setCellStyle(myCellStyle);

    Iterator it = myCollection.keySet().iterator();
    while (it.hasNext()) {
        String typeKey = it.next().toString();
        float typeValue = myCollection.get(typeKey);
        float myPerc = typeValue / countAllGoodItems;
        //System.out.println("    ***: " + typeKey + "#" + (int) typeValue + "#" + myPerc);

        HSSFRow myRow = worksheet.createRow(rowCounter);
        HSSFCell myCell0 = myRow.createCell(0);
        HSSFCell myCell1 = myRow.createCell(1);
        HSSFCell myCell2 = myRow.createCell(2);

        myCell0.setCellValue(typeKey);//from   w  ww . java2s  . c o m
        myCell1.setCellValue(typeValue);
        myCell2.setCellValue(myPerc);

        myCell1.setCellStyle(myCellStyle);
        myCell2.setCellStyle(myCellStyle);

        myCell2.setCellStyle(myCellStylePercent);

        rowCounter++;

    }

    workbook.write(fileOut);
    fileOut.flush();
    fileOut.close();

    return true;
}

From source file:excel.FileExcel.java

public File excel_create_kirim_barang(ArrayList<ItemReadyData> ItemsReadyData, Date currentdate) {
    if (ItemsReadyData.size() != 0) {
        DateFormat time = new SimpleDateFormat("hhmm");
        String fileName = "Kirim_" + fmt.format(currentdate) + "_" + time.format(currentdate) + "_konter_"
                + ItemsReadyData.get(0).kode_konter + ".xls";
        File ExcelKirimBarang = new File(fileName);
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet();

        // set page
        sheet.getPrintSetup().setLandscape(true);

        //Set Header Information 
        Header headerPage = sheet.getHeader();
        headerPage.setCenter(HeaderFooter.page());
        headerPage.setRight(fileName);/*from  w  w  w  .  j av  a 2 s .  c  om*/

        //Set Footer Information with Page Numbers
        Footer footerPage = sheet.getFooter();
        footerPage.setCenter("Page " + HeaderFooter.page() + " of " + HeaderFooter.numPages());

        // prepare variable to edit the xls
        HSSFRow header;
        HSSFCell cell;
        HSSFCellStyle titlestyle = workbook.createCellStyle();
        HSSFCellStyle headerstyle = workbook.createCellStyle();
        HSSFCellStyle datastyle = workbook.createCellStyle();
        HSSFFont boldfont = workbook.createFont();
        HSSFFont normalfont = workbook.createFont();

        // create the title 
        header = sheet.createRow(1);
        cell = header.createCell(1);
        boldfont.setBoldweight(Font.BOLDWEIGHT_BOLD);
        titlestyle.setFont(boldfont);
        titlestyle.setAlignment(CellStyle.ALIGN_CENTER);
        titlestyle.setBorderTop(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderBottom(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderLeft(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderRight(HSSFCellStyle.BORDER_NONE);
        cell.setCellStyle(titlestyle);
        cell.setCellValue("TABEL KIRIM BARANG");
        sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 9));

        // create file info
        // create file info
        header = sheet.createRow(3);
        cell = header.createCell(2);
        cell.setCellValue("Tanggal : ");
        cell = header.createCell(3);
        cell.setCellValue(fmt.format(currentdate));

        header = sheet.createRow(4);
        cell = header.createCell(2);
        cell.setCellValue("Konter : ");
        cell = header.createCell(3);
        cell.setCellValue(ItemsReadyData.get(0).kode_konter);

        // create the header
        headerstyle.setFont(boldfont);
        headerstyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
        header = sheet.createRow(7);
        cell = header.createCell(1);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Kode Barang");
        cell = header.createCell(2);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Jumlah");
        cell = header.createCell(3);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Nama Barang");
        cell = header.createCell(4);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Kategori");
        cell = header.createCell(5);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Harga TPG");
        cell = header.createCell(6);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Discount");
        cell = header.createCell(7);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Harga Net");
        cell = header.createCell(8);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Total TPG");
        cell = header.createCell(9);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Total Net");

        normalfont.setBoldweight(Font.BOLDWEIGHT_NORMAL);
        datastyle.setFont(normalfont);
        HSSFDataFormat df = workbook.createDataFormat();
        datastyle.setDataFormat(df.getFormat("#,###"));
        datastyle.setAlignment(CellStyle.ALIGN_RIGHT);
        datastyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderRight(HSSFCellStyle.BORDER_THIN);

        double net = 0;
        double total_tpg = 0;
        double total_net = 0;
        double sum_total_tpg = 0;
        double sum_total_net = 0;
        int j;

        // fill the data
        for (j = 0; j < ItemsReadyData.size(); j++) {
            net = (double) ItemsReadyData.get(j).harga_tpg
                    * (100.0 - (double) ItemsReadyData.get(j).disc_member) / 100.0;
            total_tpg = (double) ItemsReadyData.get(j).harga_tpg * (double) ItemsReadyData.get(j).jumlah_barang;
            total_net = (double) net * (double) ItemsReadyData.get(j).jumlah_barang;
            sum_total_tpg += total_tpg;
            sum_total_net += total_net;

            header = sheet.createRow(8 + j);
            cell = header.createCell(1);
            cell.setCellStyle(datastyle);
            cell.setCellValue(ItemsReadyData.get(j).kode_barang);
            cell = header.createCell(2);
            cell.setCellStyle(datastyle);
            cell.setCellValue(ItemsReadyData.get(j).jumlah_barang);
            cell = header.createCell(3);
            cell.setCellStyle(datastyle);
            cell.setCellValue(ItemsReadyData.get(j).nama_barang);
            cell = header.createCell(4);
            cell.setCellStyle(datastyle);
            cell.setCellValue(ItemsReadyData.get(j).kategori);
            cell = header.createCell(5);
            cell.setCellStyle(datastyle);
            cell.setCellValue(ItemsReadyData.get(j).harga_tpg);
            cell = header.createCell(6);
            cell.setCellStyle(datastyle);
            cell.setCellValue(ItemsReadyData.get(j).disc_member);
            cell = header.createCell(7);
            cell.setCellStyle(datastyle);
            cell.setCellValue(net);
            cell = header.createCell(8);
            cell.setCellStyle(datastyle);
            cell.setCellValue(total_tpg);
            cell = header.createCell(9);
            cell.setCellStyle(datastyle);
            cell.setCellValue(total_net);
        }

        sheet.autoSizeColumn(1);
        sheet.autoSizeColumn(2);
        sheet.autoSizeColumn(3);
        sheet.autoSizeColumn(4);
        sheet.autoSizeColumn(5);
        sheet.autoSizeColumn(6);
        sheet.autoSizeColumn(7);
        sheet.autoSizeColumn(8);
        sheet.autoSizeColumn(9);

        datastyle.setFont(boldfont);
        header = sheet.createRow(j + 8);
        cell = header.createCell(7);
        cell.setCellStyle(datastyle);
        cell.setCellValue("TOTAL");
        cell = header.createCell(8);
        cell.setCellStyle(datastyle);
        cell.setCellValue(sum_total_tpg);
        cell = header.createCell(9);
        cell.setCellStyle(datastyle);
        cell.setCellValue(sum_total_net);

        try {
            FileOutputStream out = new FileOutputStream(ExcelKirimBarang);
            workbook.write(out);
            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            ExcelKirimBarang = null;
        } catch (IOException e) {
            e.printStackTrace();
            ExcelKirimBarang = null;
        }
        return ExcelKirimBarang;
    } else {
        return null;
    }
}

From source file:excel.FileExcel.java

public File excel_create_cari_gudang(ArrayList<CariGudangReportData> CariGudang, Date waktuprint) {
    // find number of counter, save in Counter Index
    if (!CariGudang.isEmpty()) {
        DateFormat time = new SimpleDateFormat("hhmm");
        String fileName = "CariGudang_" + fmt.format(waktuprint) + "_" + time.format(waktuprint) + ".xls";
        File FileCariGudang = new File(fileName);

        HSSFWorkbook workbook;
        HSSFSheet sheet;//from www .j a va  2 s .  c om

        workbook = new HSSFWorkbook();
        sheet = workbook.createSheet();

        // set page
        HSSFPrintSetup ps = sheet.getPrintSetup();
        ps.setLandscape(true);
        ps.setFitHeight((short) 1);
        ps.setFitWidth((short) 1);
        sheet.setFitToPage(true);

        //Set Header Information 
        Header headerPage = sheet.getHeader();
        headerPage.setCenter(HeaderFooter.page());
        headerPage.setRight(fileName);

        //Set Footer Information with Page Numbers
        Footer footerPage = sheet.getFooter();
        footerPage.setCenter("Page " + HeaderFooter.page() + " of " + HeaderFooter.numPages());

        // prepare variable to edit the xls
        HSSFRow header;
        HSSFCell cell;
        HSSFCellStyle titlestyle = workbook.createCellStyle();
        HSSFCellStyle headerstyle = workbook.createCellStyle();
        HSSFCellStyle datastyle = workbook.createCellStyle();
        HSSFFont boldfont = workbook.createFont();
        HSSFFont normalfont = workbook.createFont();

        // create the title 
        header = sheet.createRow(1);
        cell = header.createCell(1);
        boldfont.setBoldweight(Font.BOLDWEIGHT_BOLD);
        titlestyle.setFont(boldfont);
        titlestyle.setAlignment(CellStyle.ALIGN_CENTER);
        titlestyle.setBorderTop(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderBottom(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderLeft(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderRight(HSSFCellStyle.BORDER_NONE);
        cell.setCellStyle(titlestyle);
        cell.setCellValue("TABEL CARI GUDANG");
        sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 4));

        // create file info
        header = sheet.createRow(4);
        cell = header.createCell(1);
        cell.setCellValue("Tanggal : ");
        cell = header.createCell(2);
        cell.setCellValue(fmt.format(waktuprint));

        header = sheet.createRow(5);
        cell = header.createCell(1);
        cell.setCellValue("Jam : ");
        cell = header.createCell(2);
        cell.setCellValue(time.format(waktuprint));

        // create the header
        headerstyle.setFont(boldfont);
        headerstyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
        header = sheet.createRow(7);
        cell = header.createCell(1);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Kode Order");
        cell = header.createCell(2);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Kode Konter");
        cell = header.createCell(3);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Kode Barang");
        cell = header.createCell(4);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Jumlah");
        cell = header.createCell(5);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Nama Barang");
        cell = header.createCell(6);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Kategori");
        cell = header.createCell(7);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("HargaTPG");
        cell = header.createCell(8);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Disc");
        cell = header.createCell(9);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Harga Net");
        cell = header.createCell(10);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Total Net");

        normalfont.setBoldweight(Font.BOLDWEIGHT_NORMAL);
        datastyle.setFont(normalfont);
        HSSFDataFormat df = workbook.createDataFormat();
        datastyle.setDataFormat(df.getFormat("#,###"));
        datastyle.setAlignment(CellStyle.ALIGN_RIGHT);
        datastyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderRight(HSSFCellStyle.BORDER_THIN);

        int row_num = 0;

        double net = 0;
        double total_tpg = 0;
        double total_net = 0;
        double sum_total_tpg = 0;
        double sum_total_net = 0;

        int j;
        for (j = 0; j < CariGudang.size(); j++) {
            net = (double) CariGudang.get(j).harga_tpg * (100.0 - (double) CariGudang.get(j).disc) / 100.0;
            total_net = (double) net * (double) CariGudang.get(j).jumlah;
            sum_total_tpg += total_tpg;
            sum_total_net += total_net;

            header = sheet.createRow(8 + row_num);
            cell = header.createCell(1);
            cell.setCellStyle(datastyle);
            cell.setCellValue(CariGudang.get(j).kode_order);
            cell = header.createCell(2);
            cell.setCellStyle(datastyle);
            cell.setCellValue(CariGudang.get(j).kode_konter);
            cell = header.createCell(3);
            cell.setCellStyle(datastyle);
            cell.setCellValue(CariGudang.get(j).kode_barang);
            cell = header.createCell(4);
            cell.setCellStyle(datastyle);
            cell.setCellValue(CariGudang.get(j).jumlah);
            cell = header.createCell(5);
            cell.setCellStyle(datastyle);
            cell.setCellValue(CariGudang.get(j).nama_barang);
            cell = header.createCell(6);
            cell.setCellStyle(datastyle);
            cell.setCellValue(CariGudang.get(j).kategori);
            cell = header.createCell(7);
            cell.setCellStyle(datastyle);
            cell.setCellValue(CariGudang.get(j).harga_tpg);
            cell = header.createCell(8);
            cell.setCellStyle(datastyle);
            cell.setCellValue(CariGudang.get(j).disc);
            cell = header.createCell(9);
            cell.setCellStyle(datastyle);
            cell.setCellValue(net);
            cell = header.createCell(10);
            cell.setCellStyle(datastyle);
            cell.setCellValue(total_net);
            row_num++;
        }

        datastyle.setFont(boldfont);
        header = sheet.createRow(j + 8);
        cell = header.createCell(9);
        cell.setCellStyle(datastyle);
        cell.setCellValue("TOTAL");
        cell = header.createCell(10);
        cell.setCellStyle(datastyle);
        cell.setCellValue(sum_total_net);

        sheet.autoSizeColumn(1);
        sheet.autoSizeColumn(2);
        sheet.autoSizeColumn(3);
        sheet.autoSizeColumn(4);
        sheet.autoSizeColumn(5);
        sheet.autoSizeColumn(6);
        sheet.autoSizeColumn(7);
        sheet.autoSizeColumn(8);
        sheet.autoSizeColumn(9);
        sheet.autoSizeColumn(10);

        try {
            FileOutputStream out = new FileOutputStream(FileCariGudang);
            workbook.write(out);
            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            FileCariGudang = null;
        } catch (IOException e) {
            e.printStackTrace();
            FileCariGudang = null;
        }
        return FileCariGudang;
    } else {
        return null;
    }
}