Example usage for org.apache.poi.hssf.usermodel HSSFSheet createRow

List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet createRow

Introduction

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

Prototype

@Override
public HSSFRow createRow(int rownum) 

Source Link

Document

Create a new row within the sheet and return the high level representation

Usage

From source file:com.save.reports.ExportDataGridToExcel.java

public void workSheet() {
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("Sample sheet");

    int rownum = 1;
    for (Object itemId : getDataGrid().getContainerDataSource().getItemIds()) {
        Row row = sheet.createRow(rownum);
        int cellcount = 0;
        if ((rownum - 1) == 0) {
            Row rowHeader = sheet.createRow(rownum - 1);
            for (Object propertyId : getDataGrid().getContainerDataSource().getContainerPropertyIds()) {
                Cell cell = rowHeader.createCell(cellcount);
                cell.setCellValue(propertyId.toString().toUpperCase());
                sheet.autoSizeColumn(cellcount);
                cellcount++;/*from   www. j  a  va2  s. c o m*/
            }
        }

        Item item = getDataGrid().getContainerDataSource().getItem(itemId);
        int cellnum = 0;
        for (Object propertyId : item.getItemPropertyIds()) {
            Cell cell = row.createCell(cellnum);
            if (propertyId.equals("employee")) {
                cell.setCellValue(item.getItemProperty(propertyId).getValue().toString().toUpperCase());
            } else {
                cell.setCellValue((item.getItemProperty(propertyId).getValue() == null) ? " "
                        : item.getItemProperty(propertyId).getValue().toString());
            }

            sheet.autoSizeColumn(cellnum);
            cellnum++;
        }
        rownum++;
    }

    try {
        Date date = new Date();
        file = File.createTempFile("file-" + date.getTime(), ".xls");
        FileOutputStream fos = new FileOutputStream(file.getAbsolutePath());
        workbook.write(fos);
        fos.flush();
        fos.close();
    } catch (FileNotFoundException ex) {
        ErrorLoggedNotification.showErrorLoggedOnWindow(ex.toString(), this.getClass().getName());
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        ErrorLoggedNotification.showErrorLoggedOnWindow(ex.toString(), this.getClass().getName());
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.screenslicer.common.Spreadsheet.java

License:Open Source License

public static byte[] xls(List<List<String>> rows) {
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("Sheet 1");
    int curRow = 0;
    for (List<String> row : rows) {
        Row xlsRow = sheet.createRow(curRow);
        int curCell = 0;
        for (String cell : row) {
            Cell xlsCell = xlsRow.createCell(curCell);
            if (CommonUtil.isEmpty(cell)) {
                xlsCell.setCellValue("");
            } else if (CommonUtil.isUrl(cell)) {
                xlsCell.setCellFormula("HYPERLINK(\"" + cell + "\")");
            } else {
                xlsCell.setCellValue(cell);
            }//from w  w w. ja v a  2  s  .  com
            ++curCell;
        }
        ++curRow;
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        try {
            workbook.write(out);
        } catch (IOException e) {
            Log.exception(e);
        }
        return out.toByteArray();
    } finally {
        try {
            out.close();
        } catch (IOException e) {
            Log.exception(e);
        }
    }
}

From source file:com.seer.datacruncher.factories.streams.SchemaStreamsExcel.java

License:Open Source License

@Override
public byte[] getDownloadableStreams() {
    if (maxVertical == 0)
        return null;
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet s = wb.createSheet("Sheet 1");
    HSSFRow headerRow = s.createRow(0);
    HSSFCellStyle style = wb.createCellStyle();
    style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    for (int i = 0; i < maxVertical; i++) {
        Document doc = getNewDomDocument();
        plainListChilds(doc, i, schemaEnt.getIdSchema(), linkedFieldsPaths);
        NodeList childList = DomToOtherFormat.getRootNodeOfDocument(doc).getChildNodes();
        HSSFRow row = s.createRow(i + 1);
        for (int j = 0; j < childList.getLength(); j++) {
            Node child = childList.item(j);
            if (i == 0) {
                HSSFCell cell = headerRow.createCell(j);
                cell.setCellValue(child.getNodeName());
                cell.setCellStyle(style);
            }/*from   w w  w.  ja  va 2s.  co  m*/
            HSSFCell cell = row.createCell(j);
            cell.setCellValue(child.getTextContent());
        }
    }
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        wb.write(bos);
    } catch (IOException e) {
        log.error("IO Exception, excel generation", e);
    } finally {
        try {
            bos.close();
        } catch (IOException e) {
            log.error("IO stream closure exception, excel generation", e);
        }
    }
    return bos.toByteArray();
}

From source file:com.seer.datacruncher.spring.DownloadStreamController.java

License:Open Source License

private byte[] getDataForXMLFile(long idSchema, String datastream) {

    Document document = null;/*from w ww  . j a  va  2s.c o m*/

    try {
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        document = docBuilder.parse(new InputSource(new StringReader(datastream)));

    } catch (Exception ex) {
        ex.printStackTrace();
    }

    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("Data");
    HSSFRow headerRow = sheet.createRow(0);

    List<SchemaFieldEntity> listFields = schemaFieldsDao.listSchemaFields(idSchema);

    int colCounter = 0;

    HSSFRow row = sheet.createRow(1);
    String tagValue;

    for (SchemaFieldEntity instance : listFields) {
        tagValue = document.getElementsByTagName(instance.getName()).item(0).getTextContent();
        headerRow.createCell(colCounter).setCellValue(instance.getName());
        row.createCell(colCounter++).setCellValue(tagValue);
    }

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        wb.write(bos);
        bos.close();
    } catch (Exception ioexception2) {

    }

    return bos.toByteArray();
}

From source file:com.Servlet.SaveServlet.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    empId = request.getParameter("employeeid");
    empName = request.getParameter("employeename");
    teamname = request.getParameter("projectteam");
    tcat = request.getParameter("trainingcategory");
    tname = request.getParameter("nameoftrainer");
    thours = request.getParameter("hoursoftraining");
    ttopic = request.getParameter("topic");
    sdate = request.getParameter("startdate");
    cdate = request.getParameter("completiondate");
    request.setAttribute("uname", empName);
    request.setAttribute("emId", empId);
    request.setAttribute("teName", teamname);

    try {//  w  ww  .j av a 2 s  .  c om

        FileInputStream file = new FileInputStream(new File("C:\\Users\\mc13082\\Desktop\\form\\new.xls"));

        HSSFWorkbook workbook = new HSSFWorkbook(file);

        HSSFSheet sheet = workbook.getSheetAt(0);

        Map<String, Object[]> data = new HashMap<>();
        //data.put("1", new Object[] {"Employee_Name", "Email"});
        data.put("2", new Object[] { empId, empName, teamname, tcat, tname, thours, ttopic, sdate, cdate });

        counter = sheet.getPhysicalNumberOfRows();
        Set<String> keyset = data.keySet();
        int rownum = counter;
        for (String key : keyset) {
            HSSFRow row = sheet.createRow(rownum++);
            Object[] objArr = data.get(key);
            int cellnum = 0;
            for (Object obj : objArr) {
                Cell cell = row.createCell(cellnum++);
                if (obj instanceof Date)
                    cell.setCellValue((Date) obj);
                else if (obj instanceof Boolean)
                    cell.setCellValue((Boolean) obj);
                else if (obj instanceof String)
                    cell.setCellValue((String) obj);
                else if (obj instanceof Double)
                    cell.setCellValue((Double) obj);
            }
        }

        file.close();
        FileOutputStream out = new FileOutputStream(new File("C:\\Users\\mc13082\\Desktop\\form\\new.xls"));
        workbook.write(out);
        out.close();

        System.out.println("Excel written successfully..");
        counter++;
        System.out.println(counter);

        RequestDispatcher rd = request.getRequestDispatcher("success.jsp");
        rd.forward(request, response);

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:com.servoy.extensions.plugins.excelxport.ExportSpecifyFilePanel.java

License:Open Source License

public static HSSFWorkbook populateWb(IFoundSet foundSet, String[] dataProviders, byte[] templateXLS,
        String[] outputColumnNames, String sheetName, int startRow, int startColumn) throws IOException {
    HSSFWorkbook hwb;/* ww w  .j  a  va 2s  . com*/
    if (templateXLS == null) {
        hwb = new HSSFWorkbook();
    } else {
        InputStream buff = new ByteArrayInputStream(templateXLS);
        hwb = new HSSFWorkbook(buff);
    }
    if (sheetName == null)
        sheetName = "Servoy Data";
    HSSFSheet sheet = hwb.getSheet(sheetName);
    if (sheet == null)
        sheet = hwb.createSheet(sheetName);
    sheet.setActive(true);

    if (outputColumnNames != null && outputColumnNames.length != dataProviders.length) {
        throw new RuntimeException(
                "The arrays 'output column names' and 'data provider ids' must have the same length."); //$NON-NLS-1$
    }
    String[] columnNames = outputColumnNames != null ? outputColumnNames : dataProviders;
    HSSFRow header = sheet.createRow((short) 0 + startRow);
    for (int k = 0; k < columnNames.length; k++) {
        HSSFCell cell = header.createCell((short) (k + startColumn));
        cell.setCellValue(columnNames[k]);
    }

    for (int i = 0; i < foundSet.getSize(); i++) {
        HSSFRow row = sheet.createRow((short) (i + 1 + startRow));
        IRecord s = foundSet.getRecord(i);
        for (int k = 0; k < dataProviders.length; k++) {
            HSSFCell cell = row.createCell((short) (k + startColumn));

            Object obj = s.getValue(dataProviders[k]);
            if (obj instanceof Date) {
                HSSFCellStyle cellStyle = hwb.createCellStyle();
                cellStyle.setDataFormat((short) 16);
                cell.setCellValue((Date) obj);
                cell.setCellStyle(cellStyle);
            } else if (obj instanceof String) {
                cell.setCellValue((String) obj);
            } else if (obj instanceof Number) {
                cell.setCellValue(((Number) obj).doubleValue());
            } else {
                cell.setCellValue(""); //$NON-NLS-1$
            }
        }
    }

    return hwb;
}

From source file:com.sevenorcas.openstyle.app.service.spreadsheet.SpreadSheetServiceImp.java

/**
 * Export sheet to workbook/*w  ww .  ja  v  a2s. c  o m*/
 * @param spreadSheet
 * @param workbook
 * @throws Exception
 */
private void exportSpreadSheet(List<SpreadSheet> sheets, HSSFWorkbook wb) throws Exception {

    for (SpreadSheet ss : sheets) {
        HSSFSheet sheet = wb.createSheet(ss.getSheetname());
        ss.setWorkBook(wb);
        ss.createFreezePane(sheet);

        /*-***************************************************************
          * Default column widths
          ****************************************************************/
        for (int column = 0; column <= ss.getLastColumn(); column++) {
            if (ss.getColumnWidth(column) != -1) {
                sheet.setColumnWidth(column, ss.getColumnWidth(column));
            }
        }

        /*-***************************************************************
         * Output row data
         ****************************************************************/
        for (int row = 0; row <= ss.getLastRow(); row++) {
            for (int column = 0; column <= ss.getLastColumn(); column++) {

                HSSFRow sheetRow = sheet.getRow(row);
                if (sheetRow == null) {
                    sheetRow = sheet.createRow(row);
                }

                HSSFCell cell = sheetRow.createCell(column);

                SpreadsheetCell cellX = ss.getCell(column, row);
                if (cellX != null) {

                    if (cellX.getCellRangeAddress() != null) {
                        sheet.addMergedRegion(cellX.getCellRangeAddress());
                    }

                    //Ex
                    HSSFCellStyle style = cellX.getCellStyle(wb);
                    cell.setCellStyle(style);

                    boolean set = ss.getColumnWidth(column) == -1;
                    if (set && cellX.isHeader() && cellX.getWidth() != null) {
                        sheet.setColumnWidth(column, cellX.getWidth());
                    }

                    cellX.setCellValue(cell, wb);
                } else {
                    HSSFCellStyle style = ss.getCellStyleDefault(wb, row, column);
                    cell.setCellStyle(style);
                }

            }
        }
    }
}

From source file:com.sfy.controller.SiteManageController.java

@RequestMapping(value = "/exportExcel", method = RequestMethod.POST)
public void exportExcelForPage(HttpServletRequest request, HttpServletResponse response) {
    SiteBaseInfo siteBaseInfo;/*from   w  ww .j  a  va2  s .  c  o  m*/
    OutputStream outputStream = null;
    try {
        response.setContentType("application/msexcel;charset=GBK");
        response.setHeader("Content-Disposition", "attachment;filename="
                .concat(String.valueOf(URLEncoder.encode("JDHMS-EXPORT-SITE.xls", "UTF-8"))));
        response.setHeader("Connection", "close");
        response.setHeader("Content-Type", "application/vnd.ms-excel");
        siteBaseInfo = assumeSiteBaseInfoEntity(request);
        siteBaseInfo.setErp(request.getParameter("loginUser"));
        siteBaseInfo = changeParamForMutilOrg(siteBaseInfo); //
        Result<List<SiteBaseInfo>> result = storeService.querySiteBaseInfoForPageByMultiOrg(siteBaseInfo);
        if (result.isSuccess()) {
            List<SiteBaseInfo> siteBaseInfoList = result.getResult();
            if (siteBaseInfoList.size() > 0) {
                /* ?? */
                List<String> querySyncList = new ArrayList<String>();
                for (SiteBaseInfo siteBaseInfoQuery : siteBaseInfoList) {
                    querySyncList.add(String.valueOf(siteBaseInfoQuery.getSiteNo()));
                }
                Map<String, List<SyncSiteInfoMq>> compositeMap = storeService
                        .queryBunchSyncSiteInfo(querySyncList);
                /* EXCEL */
                HSSFWorkbook workbook = new HSSFWorkbook();
                List<String> listCol = new ArrayList<String>();
                listCol.add("");
                listCol.add("??");
                listCol.add("??");
                listCol.add("?");
                listCol.add("");
                listCol.add("?");
                listCol.add("");
                listCol.add("");
                listCol.add("");
                listCol.add("?");
                listCol.add("??");
                listCol.add("?");
                listCol.add("");
                listCol.add("");
                listCol.add("?");
                listCol.add("");
                listCol.add("?");
                listCol.add("");
                listCol.add("");
                listCol.add("??");
                listCol.add("??");
                listCol.add("?");
                HSSFSheet sheet = workbook.createSheet();
                HSSFRow headRow = sheet.createRow(0);
                for (int j = 0; j < listCol.size(); j++) {
                    HSSFCell cell = headRow.createCell(j);
                    cell.setCellValue(listCol.get(j));
                }
                for (int i = 1; i <= siteBaseInfoList.size(); i++) {
                    HSSFRow row = sheet.createRow(i);
                    for (int j = 0; j < listCol.size(); j++) {
                        HSSFCell cell = row.createCell(j);
                        if (j == 0) {
                            cell.setCellValue(siteBaseInfoList.get(i - 1).getOrgName());
                        } else if (j == 1) {
                            cell.setCellValue(siteBaseInfoList.get(i - 1).getDistributeName());
                        } else if (j == 2) {
                            cell.setCellValue(siteBaseInfoList.get(i - 1).getSiteName());
                        } else if (j == 3) {
                            cell.setCellValue(siteBaseInfoList.get(i - 1).getBussinessSiteNo());
                        } else if (j == 4) {
                            cell.setCellValue(siteBaseInfoList.get(i - 1).getSiteType());
                        } else if (j == 5) {
                            cell.setCellValue(siteBaseInfoList.get(i - 1).getProvinceName());
                        } else if (j == 6) {
                            cell.setCellValue(siteBaseInfoList.get(i - 1).getCityName());
                        } else if (j == 7) {
                            cell.setCellValue(siteBaseInfoList.get(i - 1).getCountryName());
                        } else if (j == 8) {
                            cell.setCellValue(siteBaseInfoList.get(i - 1).getTownName());
                        } else if (j == 9) {
                            cell.setCellValue(siteBaseInfoList.get(i - 1).getAddress());
                        } else if (j == 10) {
                            cell.setCellValue(siteBaseInfoList.get(i - 1).getGpsLongitude());
                        } else if (j == 11) {
                            cell.setCellValue(siteBaseInfoList.get(i - 1).getGpsLatitude());
                        } else if (j == 12) {
                            cell.setCellValue(siteBaseInfoList.get(i - 1).getManagerName());
                        } else if (j == 13) {
                            cell.setCellValue(siteBaseInfoList.get(i - 1).getSiteManager());
                        } else if (j == 14) {
                            cell.setCellValue(siteBaseInfoList.get(i - 1).getJdAccount());
                        } else if (j == 15) {
                            cell.setCellValue(siteBaseInfoList.get(i - 1).getSiteLevel());
                        } else if (j == 16) {
                            cell.setCellValue(siteBaseInfoList.get(i - 1).getSiteStatus());
                        } else if (j == 17) {
                            Date openTime = siteBaseInfoList.get(i - 1).getOpenTime();
                            if (openTime != null) {
                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                                String formater = sdf.format(openTime);
                                cell.setCellValue(formater);
                            } else {
                                cell.setCellValue("");
                            }
                        } else if (j == 18) {
                            Date createTime = siteBaseInfoList.get(i - 1).getCreateTime();
                            if (createTime != null) {
                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                                String formater = sdf.format(createTime);
                                cell.setCellValue(formater);
                            } else {
                                cell.setCellValue("");
                            }
                        } else if (j == 19) {
                            cell.setCellValue(siteBaseInfoList.get(i - 1).getTelephone());
                        } else if (j == 20) {
                            if (compositeMap
                                    .containsKey(String.valueOf(siteBaseInfoList.get(i - 1).getSiteNo()))) {
                                List<SyncSiteInfoMq> syncSiteInfoMqList = compositeMap
                                        .get(String.valueOf(siteBaseInfoList.get(i - 1).getSiteNo()));
                                StringBuilder sb = new StringBuilder();
                                for (int ii = 0; ii < syncSiteInfoMqList.size(); ii++) {
                                    int systemSource = syncSiteInfoMqList.get(ii).getSystemSource();
                                    if (systemSource == 0) {
                                        sb.append(syncSiteInfoMqList.get(ii).getWebsiteNo());
                                        sb.append(",");
                                    }
                                }
                                String[] splitArray = sb.toString().split(",");
                                String str = "";
                                for (int jj = 0; jj < splitArray.length; jj++) {
                                    str = str + splitArray[jj];
                                    if (jj + 1 != splitArray.length) {
                                        str = str + ",";
                                    }
                                }
                                cell.setCellValue(str);
                            }
                        } else if (j == 21) {
                            if (compositeMap
                                    .containsKey(String.valueOf(siteBaseInfoList.get(i - 1).getSiteNo()))) {
                                List<SyncSiteInfoMq> syncSiteInfoMqList = compositeMap
                                        .get(String.valueOf(siteBaseInfoList.get(i - 1).getSiteNo()));
                                StringBuilder sb = new StringBuilder();
                                for (int ii = 0; ii < syncSiteInfoMqList.size(); ii++) {
                                    int systemSource = syncSiteInfoMqList.get(ii).getSystemSource();
                                    if (systemSource == 1) {
                                        sb.append(syncSiteInfoMqList.get(ii).getWebsiteNo());
                                        sb.append(",");
                                    }
                                }
                                String[] splitArray = sb.toString().split(",");
                                String str = "";
                                for (int jj = 0; jj < splitArray.length; jj++) {
                                    str = str + splitArray[jj];
                                    if (jj + 1 != splitArray.length) {
                                        str = str + ",";
                                    }
                                }
                                cell.setCellValue(str);
                            }
                        }
                    }
                }
                outputStream = response.getOutputStream();
                workbook.write(outputStream);
                /* EXCEL? */
            }
        }
    } catch (Exception e) {
        logger.error(e.toString());
    } finally {
        try {
            if (outputStream != null) {
                outputStream.flush();
                outputStream.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:com.simeosoft.util.XlsUtils.java

License:Open Source License

public static void addXlsWorksheet(HSSFWorkbook wb, String sheetName, ArrayList<ArrayList<Object>> data) {
    HSSFSheet s = wb.createSheet(sheetName);
    HSSFRow r = null;/*from w  w  w.j a va  2  s.  c  o  m*/
    HSSFCell c = null;
    int i = 0;
    HSSFDataFormat df = wb.createDataFormat();
    HSSFCellStyle cs = wb.createCellStyle();
    for (ArrayList<Object> record : data) {
        r = s.createRow(i);
        i++;
        short y = 0;
        /*
         * tipi dato previsti: null,String,Date,Integer,Time,Timestamp
         * - gli altri tipi restituiscono errore
         */
        for (Object obj : record) {
            c = r.createCell(y);
            y++;
            if (obj == null) {
                c.setCellValue("");
                continue;
            }
            if (obj instanceof String) {
                c.setCellValue((String) obj);
                continue;
            }
            // MODIF - java.util.Date o java.sql.Date?                
            if (obj instanceof java.sql.Date || obj instanceof java.sql.Timestamp
                    || obj instanceof java.sql.Time) {
                HSSFCellStyle csd = wb.createCellStyle();
                csd.setDataFormat(HSSFDataFormat.getBuiltinFormat("mm/dd/yyyy"));
                c.setCellValue((java.sql.Date) obj);
                c.setCellStyle(csd);
                continue;
            }
            if (obj instanceof Integer) {
                c.setCellValue(((Integer) obj).doubleValue());
                continue;
            }
            if (obj instanceof BigDecimal) {
                c.setCellValue(((BigDecimal) obj).doubleValue());
                cs.setDataFormat(df.getFormat("######0.0000"));
                c.setCellStyle(cs);
                continue;
            }
            // default - non previsto                
            c.setCellValue("ERRORE: TIPO NON PREVISTO: " + obj.getClass());
        }
    }
}

From source file:com.siva.javamultithreading.ExcelChunkSheetWriter.java

/**
 * Writting a excel workbook//from  w w w  .  j  av  a 2s  .  c om
 * @return
 * @throws Exception 
 */
@Override
public HSSFWorkbook call() throws Exception {
    System.out.println("Test...");
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("Sample sheet");

    Map<String, Object[]> data = new HashMap<String, Object[]>();
    //        data.put(this.start+"1-"+this.end, new Object[] {"Emp No.", "Name", "Salary"});
    //        for (int i = this.start; i < this.end; i++) {          
    //           data.put(i+"2-"+this.end, new Object[] {this.start+1d+this.end, "Siva"+i, 1500000d});
    //        }

    data.put(this.start + "1-" + this.end, new Object[] { "Id", "Name", "Comment" });
    for (DomainObject obj : list) {
        data.put(obj.getId(), new Object[] { obj.getId(), obj.getName(), obj.getComment() });
    }

    Set<String> keyset = data.keySet();
    int rownum = 0;
    for (String key : keyset) {
        Row row = sheet.createRow(rownum++);
        Object[] objArr = data.get(key);
        int cellnum = 0;
        for (Object obj : objArr) {
            Cell cell = row.createCell(cellnum++);
            if (obj instanceof Date)
                cell.setCellValue((Date) obj);
            else if (obj instanceof Boolean)
                cell.setCellValue((Boolean) obj);
            else if (obj instanceof String)
                cell.setCellValue((String) obj);
            else if (obj instanceof Double)
                cell.setCellValue((Double) obj);
        }
    }

    return workbook;
}