Example usage for org.apache.poi.ss.usermodel Workbook createSheet

List of usage examples for org.apache.poi.ss.usermodel Workbook createSheet

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Workbook createSheet.

Prototype

Sheet createSheet();

Source Link

Document

Create a Sheet for this Workbook, adds it to the sheets and returns the high level representation.

Usage

From source file:egovframework.rte.fdl.excel.EgovExcelServiceTest.java

License:Apache License

/**
 * [Flow #-6]  ?  :  ? ?(?, ? )? /* w  w  w. j  ava 2s . co m*/
 */
@Test
public void testModifyCellAttribute() throws Exception {

    try {
        LOGGER.debug("testModifyCellAttribute start....");

        StringBuffer sb = new StringBuffer();
        sb.append(fileLocation).append("/").append("testModifyCellAttribute.xls");

        if (EgovFileUtil.isExistsFile(sb.toString())) {
            EgovFileUtil.delete(new File(sb.toString()));

            LOGGER.debug("Delete file....{}", sb.toString());
        }

        Workbook wbTmp = new HSSFWorkbook();
        wbTmp.createSheet();

        //  ? ?
        excelService.createWorkbook(wbTmp, sb.toString());

        //  ? 
        Workbook wb = excelService.loadWorkbook(sb.toString());
        LOGGER.debug("testModifyCellAttribute after loadWorkbook....");

        Sheet sheet = wb.createSheet("cell test sheet2");
        //           sheet.setColumnWidth((short) 3, (short) 200);   // column Width

        CellStyle cs = wb.createCellStyle();
        Font font = wb.createFont();
        font.setFontHeight((short) 16);
        font.setBoldweight((short) 3);
        font.setFontName("fixedsys");

        cs.setFont(font);
        cs.setAlignment(CellStyle.ALIGN_RIGHT); // cell 
        cs.setWrapText(true);

        for (int i = 0; i < 100; i++) {
            Row row = sheet.createRow(i);
            //              row.setHeight((short)300); // row? height 

            for (int j = 0; j < 5; j++) {
                Cell cell = row.createCell(j);
                cell.setCellValue(new HSSFRichTextString("row " + i + ", cell " + j));
                cell.setCellStyle(cs);
            }
        }

        //  ? 
        FileOutputStream out = new FileOutputStream(sb.toString());
        wb.write(out);
        out.close();

        //////////////////////////////////////////////////////////////////////////
        // ?
        Workbook wbT = excelService.loadWorkbook(sb.toString());
        Sheet sheetT = wbT.getSheet("cell test sheet2");
        LOGGER.debug("getNumCellStyles : {}", wbT.getNumCellStyles());

        CellStyle cs1 = wbT.getCellStyleAt((short) (wbT.getNumCellStyles() - 1));

        Font fontT = ((HSSFCellStyle) cs1).getFont(wbT);
        LOGGER.debug("font getFontHeight : {}", fontT.getFontHeight());
        LOGGER.debug("font getBoldweight : {}", fontT.getBoldweight());
        LOGGER.debug("font getFontName : {}", fontT.getFontName());
        LOGGER.debug("getAlignment : {}", cs1.getAlignment());
        LOGGER.debug("getWrapText : {}", cs1.getWrapText());

        for (int i = 0; i < 100; i++) {
            Row row1 = sheetT.getRow(i);
            for (int j = 0; j < 5; j++) {
                Cell cell1 = row1.getCell(j);
                LOGGER.debug("row {}, cell {} : {}", i, j, cell1.getRichStringCellValue());
                assertEquals(16, fontT.getFontHeight());
                assertEquals(3, fontT.getBoldweight());
                assertEquals(CellStyle.ALIGN_RIGHT, cs1.getAlignment());
                assertTrue(cs1.getWrapText());
            }
        }

    } catch (Exception e) {
        LOGGER.error(e.toString());
        throw new Exception(e);
    } finally {
        LOGGER.debug("testModifyCellAttribute end....");
    }
}

From source file:egovframework.rte.fdl.excel.EgovExcelXSSFServiceTest.java

License:Apache License

/**
 * [Flow #-2]  ?  : ? ?  ? ?    ?/*from ww  w. j av a  2 s .  co  m*/
 */
@Test
public void testModifyCellContents() throws Exception {

    try {
        String content = "Use \n with word wrap on to create a new line";
        short rownum = 2;
        int cellnum = 2;

        LOGGER.debug("testModifyCellContents start....");

        StringBuffer sb = new StringBuffer();
        sb.append(fileLocation).append("/").append("testModifyCellContents.xlsx");

        if (!EgovFileUtil.isExistsFile(sb.toString())) {
            Workbook wbT = new XSSFWorkbook();
            wbT.createSheet();

            //  ? ?
            excelService.createWorkbook(wbT, sb.toString());
        }

        //  ? 
        XSSFWorkbook wb = null;
        wb = excelService.loadWorkbook(sb.toString(), wb);
        LOGGER.debug("testModifyCellContents after loadWorkbook....");

        Sheet sheet = wb.getSheetAt(0);
        Font f2 = wb.createFont();
        CellStyle cs = wb.createCellStyle();
        cs = wb.createCellStyle();

        cs.setFont(f2);
        //Word Wrap MUST be turned on
        cs.setWrapText(true);

        Row row = sheet.createRow(rownum);
        row.setHeight((short) 0x349);
        Cell cellx = row.createCell(cellnum);
        cellx.setCellType(XSSFCell.CELL_TYPE_STRING);
        cellx.setCellValue(new XSSFRichTextString(content));
        cellx.setCellStyle(cs);

        sheet.setColumnWidth(20, (int) ((50 * 8) / ((double) 1 / 20)));

        //excelService.writeWorkbook(wb);

        FileOutputStream outx = new FileOutputStream(sb.toString());
        wb.write(outx);
        outx.close();

        //  ? 
        Workbook wb1 = excelService.loadWorkbook(sb.toString(), new XSSFWorkbook());

        Sheet sheet1 = wb1.getSheetAt(0);
        Row row1 = sheet1.getRow(rownum);
        Cell cell1 = row1.getCell(cellnum);

        // ? ?  ?
        LOGGER.debug("cell ###{}###", cell1.getRichStringCellValue());
        LOGGER.debug("cont ###{}###", content);

        assertNotSame("TEST", cell1.getRichStringCellValue().toString());
        assertEquals(content, cell1.getRichStringCellValue().toString());

    } catch (Exception e) {
        LOGGER.error(e.toString());
        throw new Exception(e);
    } finally {
        LOGGER.debug("testModifyCellContents end....");
    }
}

From source file:egovframework.rte.fdl.excel.EgovExcelXSSFServiceTest.java

License:Apache License

/**
 * [Flow #-4]   ?  :  ? ? ?(Header, Footer)? 
 */// w w  w .ja  v a2 s  . c  om
@Test
public void testModifyDocAttribute() throws Exception {

    try {
        LOGGER.debug("testModifyDocAttribute start....");

        StringBuffer sb = new StringBuffer();
        sb.append(fileLocation).append("/").append("testModifyDocAttribute.xlsx");

        if (EgovFileUtil.isExistsFile(sb.toString())) {
            EgovFileUtil.delete(new File(sb.toString()));

            LOGGER.debug("Delete file....{}", sb.toString());
        }

        Workbook wbTmp = new XSSFWorkbook();
        wbTmp.createSheet();

        //  ? ?
        excelService.createWorkbook(wbTmp, sb.toString());

        //  ? 
        Workbook wb = excelService.loadWorkbook(sb.toString(), new XSSFWorkbook());
        LOGGER.debug("testModifyCellContents after loadWorkbook....");

        Sheet sheet = wb.createSheet("doc test sheet");

        Row row = sheet.createRow(1);
        Cell cell = row.createCell(1);
        cell.setCellValue(new XSSFRichTextString("Header/Footer Test"));

        // Header
        Header header = sheet.getHeader();
        header.setCenter("Center Header");
        header.setLeft("Left Header");
        header.setRight(XSSFOddHeader.stripFields("&IRight Stencil-Normal Italic font and size 16"));

        // Footer
        Footer footer = (XSSFOddFooter) sheet.getFooter();
        footer.setCenter(XSSFOddHeader.stripFields("Fixedsys"));
        LOGGER.debug("Style is ... {}", XSSFOddHeader.stripFields("Fixedsys"));
        footer.setLeft("Left Footer");
        footer.setRight("Right Footer");

        //  ? 
        FileOutputStream out = new FileOutputStream(sb.toString());
        wb.write(out);
        out.close();

        assertTrue(EgovFileUtil.isExistsFile(sb.toString()));

        //////////////////////////////////////////////////////////////////////////
        // ?
        Workbook wbT = excelService.loadWorkbook(sb.toString(), new XSSFWorkbook());
        Sheet sheetT = wbT.getSheet("doc test sheet");

        Header headerT = sheetT.getHeader();
        assertEquals("Center Header", headerT.getCenter());
        assertEquals("Left Header", headerT.getLeft());
        assertEquals(XSSFOddHeader.stripFields("Right Stencil-Normal Italic font and size 16"),
                headerT.getRight());

        Footer footerT = sheetT.getFooter();
        assertEquals("Right Footer", footerT.getRight());
        assertEquals("Left Footer", footerT.getLeft());
        assertEquals(XSSFOddHeader.stripFields("Fixedsys"), footerT.getCenter());

    } catch (Exception e) {
        LOGGER.error(e.toString());
        throw new Exception(e);
    } finally {
        LOGGER.debug("testModifyDocAttribute end....");
    }
}

From source file:egovframework.rte.fdl.excel.EgovExcelXSSFServiceTest.java

License:Apache License

/**
 * [Flow #-5]    :  ?? ?  ? ?  //from w  ww. ja v a2s  . c  o  m
 */
@Test
public void testGetCellContents() throws Exception {

    try {
        LOGGER.debug("testGetCellContents start....");

        StringBuffer sb = new StringBuffer();
        sb.append(fileLocation).append("/").append("testGetCellContents.xlsx");

        if (EgovFileUtil.isExistsFile(sb.toString())) {
            EgovFileUtil.delete(new File(sb.toString()));

            LOGGER.debug("Delete file....{}", sb.toString());
        }

        Workbook wbTmp = new XSSFWorkbook();
        wbTmp.createSheet();

        //  ? ?
        excelService.createWorkbook(wbTmp, sb.toString());

        //  ? 
        Workbook wb = excelService.loadWorkbook(sb.toString(), new XSSFWorkbook());
        LOGGER.debug("testGetCellContents after loadWorkbook....");

        Sheet sheet = wb.createSheet("cell test sheet");

        CellStyle cs = wb.createCellStyle();
        cs = wb.createCellStyle();
        cs.setWrapText(true);

        for (int i = 0; i < 100; i++) {
            Row row = sheet.createRow(i);
            for (int j = 0; j < 5; j++) {
                Cell cell = row.createCell(j);
                cell.setCellValue(new XSSFRichTextString("row " + i + ", cell " + j));
                cell.setCellStyle(cs);
            }
        }

        //  ? 
        FileOutputStream out = new FileOutputStream(sb.toString());
        wb.write(out);
        out.close();

        //////////////////////////////////////////////////////////////////////////
        // ?
        Workbook wbT = excelService.loadWorkbook(sb.toString(), new XSSFWorkbook());
        Sheet sheetT = wbT.getSheet("cell test sheet");

        for (int i = 0; i < 100; i++) {
            Row row1 = sheetT.getRow(i);
            for (int j = 0; j < 5; j++) {
                Cell cell1 = row1.getCell(j);
                LOGGER.debug("row {}, cell : {}", i, j, cell1.getRichStringCellValue());
                assertEquals("row " + i + ", cell " + j, cell1.getRichStringCellValue().toString());
            }
        }

    } catch (Exception e) {
        LOGGER.error(e.toString());
        throw new Exception(e);
    } finally {
        LOGGER.debug("testGetCellContents end....");
    }
}

From source file:egovframework.rte.fdl.excel.EgovExcelXSSFServiceTest.java

License:Apache License

/**
 * [Flow #-6]  ?  :  ? ?(?, ? )? //  ww  w.  j a va 2  s. c o  m
 */
@Test
public void testModifyCellAttribute() throws Exception {

    try {
        LOGGER.debug("testModifyCellAttribute start....");

        StringBuffer sb = new StringBuffer();
        sb.append(fileLocation).append("/").append("testModifyCellAttribute.xlsx");

        if (EgovFileUtil.isExistsFile(sb.toString())) {
            EgovFileUtil.delete(new File(sb.toString()));

            LOGGER.debug("Delete file....{}", sb.toString());
        }

        Workbook wbTmp = new XSSFWorkbook();
        wbTmp.createSheet();

        //  ? ?
        excelService.createWorkbook(wbTmp, sb.toString());

        //  ? 
        XSSFWorkbook wb = excelService.loadWorkbook(sb.toString(), new XSSFWorkbook());
        LOGGER.debug("testModifyCellAttribute after loadWorkbook....");

        Sheet sheet = wb.createSheet("cell test sheet2");
        sheet.setColumnWidth((short) 3, (short) 200); // column Width

        CellStyle cs = wb.createCellStyle();
        XSSFFont font = wb.createFont();
        font.setFontHeight(16);
        font.setBoldweight((short) 3);
        font.setFontName("fixedsys");

        cs.setFont(font);
        cs.setAlignment(XSSFCellStyle.ALIGN_RIGHT); // cell 
        cs.setWrapText(true);

        for (int i = 0; i < 100; i++) {
            Row row = sheet.createRow(i);
            row.setHeight((short) 300); // row? height 

            for (int j = 0; j < 5; j++) {
                Cell cell = row.createCell(j);
                cell.setCellValue(new XSSFRichTextString("row " + i + ", cell " + j));
                cell.setCellStyle(cs);
            }
        }

        //  ? 
        FileOutputStream out = new FileOutputStream(sb.toString());
        wb.write(out);
        out.close();

        //////////////////////////////////////////////////////////////////////////
        // ?
        XSSFWorkbook wbT = excelService.loadWorkbook(sb.toString(), new XSSFWorkbook());
        Sheet sheetT = wbT.getSheet("cell test sheet2");
        LOGGER.debug("getNumCellStyles : {}", wbT.getNumCellStyles());

        XSSFCellStyle cs1 = (XSSFCellStyle) wbT.getCellStyleAt((short) (wbT.getNumCellStyles() - 1));

        XSSFFont fontT = cs1.getFont();
        LOGGER.debug("font getFontHeight : {}", fontT.getFontHeight());
        LOGGER.debug("font getBoldweight : {}", fontT.getBoldweight());
        LOGGER.debug("font getFontName : {}", fontT.getFontName());
        LOGGER.debug("getAlignment : {}", cs1.getAlignment());
        LOGGER.debug("getWrapText : {}", cs1.getWrapText());

        for (int i = 0; i < 100; i++) {
            Row row1 = sheetT.getRow(i);
            for (int j = 0; j < 5; j++) {
                Cell cell1 = row1.getCell(j);
                LOGGER.debug("row {}, cell {} : {}", i, j, cell1.getRichStringCellValue());
                assertEquals(320, fontT.getFontHeight());
                assertEquals(400, fontT.getBoldweight());
                LOGGER.debug("fontT.getBoldweight()? ? 400? ?");

                assertEquals(XSSFCellStyle.ALIGN_RIGHT, cs1.getAlignment());
                assertTrue(cs1.getWrapText());
            }
        }

    } catch (Exception e) {
        LOGGER.error(e.toString());
        throw new Exception(e);
    } finally {
        LOGGER.debug("testModifyCellAttribute end....");
    }
}

From source file:eu.esdihumboldt.hale.io.xls.writer.XLSAlignmentMappingWriter.java

License:Open Source License

@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter)
        throws IOProviderConfigurationException, IOException {

    super.execute(progress, reporter);

    Workbook workbook;
    // write xls file
    if (getContentType().getId().equals("eu.esdihumboldt.hale.io.xls.xls")) {
        workbook = new HSSFWorkbook();
    }/*  w ww .jav  a 2s .  c om*/
    // write xlsx file
    else if (getContentType().getId().equals("eu.esdihumboldt.hale.io.xls.xlsx")) {
        workbook = new XSSFWorkbook();
    } else {
        reporter.error(new IOMessageImpl("Content type is invalid!", null));
        reporter.setSuccess(false);
        return reporter;
    }

    Sheet sheet = workbook.createSheet();
    workbook.setSheetName(0, "Mapping table");
    Row row = null;
    Cell cell = null;

    // create cell style of the header
    CellStyle headerStyle = XLSCellStyles.getHeaderStyle(workbook);

    // create cell style
    CellStyle cellStyle = XLSCellStyles.getNormalStyle(workbook, false);

    // create highlight style for type cells
    CellStyle highlightStyle = XLSCellStyles.getHighlightedStyle(workbook, false);

    // create disabled style
    CellStyle disabledStyle = XLSCellStyles.getNormalStyle(workbook, true);

    // create disabled highlight style
    CellStyle disabledTypeStyle = XLSCellStyles.getHighlightedStyle(workbook, true);

    List<Map<CellType, CellInformation>> mapping = getMappingList();

    // determine if cells are organized by type cell
    boolean byTypeCell = isByTypeCell();

    int rownum = 0;

    // write header
    row = sheet.createRow(rownum++);
    for (int i = 0; i < getMappingHeader().size(); i++) {
        cell = row.createCell(i);
        cell.setCellValue(getMappingHeader().get(i));
        cell.setCellStyle(headerStyle);
    }

    // write all mappings
    for (Map<CellType, CellInformation> entry : mapping) {

        boolean disabled = false;
        if (getParameter(TRANSFORMATION_AND_DISABLED_FOR).as(Boolean.class)) {
            List<String> transformationDisabled = entry.get(CellType.TRANSFORMATION_AND_DISABLED).getText();
            disabled = !transformationDisabled.isEmpty()
                    && !transformationDisabled.contains(TransformationMode.active.displayName());
        }

        // create a row
        row = sheet.createRow(rownum);

        CellStyle rowStyle = cellStyle;

        String targetProp = getCellValue(entry, CellType.TARGET_PROPERTIES);
        boolean isTypeCell = targetProp == null || targetProp.isEmpty();

        if (isTypeCell && byTypeCell) {
            // organized by type cells and this is a type cell

            if (disabled) {
                // disabled type cell
                rowStyle = disabledTypeStyle;
            } else {
                // normal type cell
                rowStyle = highlightStyle;
            }
        } else if (disabled) {
            // disabled property cell
            rowStyle = disabledStyle;
        }

        List<CellType> celltypes = getCellTypes();
        for (int i = 0; i < celltypes.size(); i++) {
            cell = row.createCell(i);
            cell.setCellValue(getCellValue(entry, celltypes.get(i)));
            cell.setCellStyle(rowStyle);
        }
        rownum++;
    }

    // could be integrated in configuration page
    //      int maxColWidth = calculateWidth(getParameter(MAX_COLUMN_WIDTH).as(Integer.class));
    int maxColWidth = calculateWidth(maxWidth);
    // autosize all columns
    for (int i = 0; i < getMappingHeader().size(); i++) {
        sheet.autoSizeColumn(i);
        if (sheet.getColumnWidth(i) > maxColWidth)
            sheet.setColumnWidth(i, maxColWidth);
    }

    // write file
    FileOutputStream out = new FileOutputStream(getTarget().getLocation().getPath());
    workbook.write(out);
    out.close();

    reporter.setSuccess(true);
    return reporter;
}

From source file:eu.esdihumboldt.hale.io.xls.writer.XLSLookupTableWriter.java

License:Open Source License

/**
 * @see eu.esdihumboldt.hale.common.core.io.impl.AbstractIOProvider#execute(eu.esdihumboldt.hale.common.core.io.ProgressIndicator,
 *      eu.esdihumboldt.hale.common.core.io.report.IOReporter)
 *//*  w w  w .ja va2s.com*/
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter)
        throws IOProviderConfigurationException, IOException {

    Workbook workbook;
    // write xls file
    if (getContentType().getId().equals("eu.esdihumboldt.hale.io.xls.xls")) {
        workbook = new HSSFWorkbook();
    }
    // write xlsx file
    else if (getContentType().getId().equals("eu.esdihumboldt.hale.io.xls.xlsx")) {
        workbook = new XSSFWorkbook();
    } else {
        reporter.error(new IOMessageImpl("Content type is invalid!", null));
        reporter.setSuccess(false);
        return reporter;
    }

    Sheet sheet = workbook.createSheet();
    workbook.setSheetName(0, "Lookup table");
    Row row = null;
    Cell cell = null;
    DataFormat df = workbook.createDataFormat();

    // create cell style of the header
    CellStyle headerStyle = workbook.createCellStyle();
    Font headerFont = workbook.createFont();
    // use bold font
    headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    headerStyle.setFont(headerFont);
    // set a medium border
    headerStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);
    // set cell data format to text
    headerStyle.setDataFormat(df.getFormat("@"));

    // create cell style
    CellStyle rowStyle = workbook.createCellStyle();
    // set thin border around the cell
    rowStyle.setBorderBottom(CellStyle.BORDER_THIN);
    rowStyle.setBorderLeft(CellStyle.BORDER_THIN);
    rowStyle.setBorderRight(CellStyle.BORDER_THIN);
    // set cell data format to text
    rowStyle.setDataFormat(df.getFormat("@"));
    // display multiple lines
    rowStyle.setWrapText(true);

    Map<Value, Value> table = getLookupTable().getTable().asMap();

    int rownum = 0;

    // write header
    row = sheet.createRow(rownum++);
    cell = row.createCell(0);
    cell.setCellValue(getParameter(LookupTableExportConstants.PARAM_SOURCE_COLUMN).as(String.class));
    cell.setCellStyle(headerStyle);

    cell = row.createCell(1);
    cell.setCellValue(getParameter(LookupTableExportConstants.PARAM_TARGET_COLUMN).as(String.class));
    cell.setCellStyle(headerStyle);

    for (Value key : table.keySet()) {
        // create a row
        row = sheet.createRow(rownum);

        cell = row.createCell(0);
        cell.setCellValue(key.as(String.class));
        cell.setCellStyle(rowStyle);

        Value entry = table.get(key);
        cell = row.createCell(1);
        cell.setCellValue(entry.as(String.class));
        cell.setCellStyle(rowStyle);
        rownum++;
    }

    // write file
    FileOutputStream out = new FileOutputStream(getTarget().getLocation().getPath());
    workbook.write(out);
    out.close();

    reporter.setSuccess(true);
    return reporter;
}

From source file:fft.FFT.java

License:Open Source License

public static void main(String[] args) throws IOException {

    InputStream myxls = new FileInputStream("/Users/huangge/Documents/workspace/fft/src/BxDec99.xls");
    HSSFWorkbook wb = new HSSFWorkbook(myxls);
    HSSFSheet sheet = wb.getSheetAt(0);// w w  w.j a  v a 2 s . c  om
    int rowStart = Math.min(15, sheet.getFirstRowNum());
    int rowEnd = Math.max(1400, sheet.getLastRowNum());
    Row r_for_rowCount = sheet.getRow(0);
    int lastColumn = Math.min(r_for_rowCount.getLastCellNum(), 1000);

    double[][] res = new double[lastColumn - 1][rowEnd];
    Workbook wb_out = new HSSFWorkbook(); // or new XSSFWorkbook();
    Sheet sheet_out = wb_out.createSheet();
    int count = 0;
    for (int j = 1; j < lastColumn; j++) {//make res matrix
        count = 0;
        for (int i = 1; i <= rowEnd; i++) {
            Row r = sheet.getRow(i);
            Cell c = r.getCell(3, Row.RETURN_BLANK_AS_NULL);
            if (c == null || c.getCellType() == Cell.CELL_TYPE_BLANK) {
                break;
            } else if (c.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                res[j - 1][i - 1] = c.getNumericCellValue();
                count++;
            }
        }
    }

    int N = count;
    int nextPowTwo = 1;
    while (nextPowTwo < N) {
        nextPowTwo += nextPowTwo;
    }
    N = nextPowTwo;
    FFT fft = new FFT(N);
    double[] window = fft.getWindow();
    double[] re = new double[N];
    Arrays.fill(re, 0);
    ;
    double[] im = new double[N];

    for (int i = 0; i < re.length / 2; i++) {//initial sheet
        Row row_cre = sheet_out.createRow(i);
        for (int k = 0; k < lastColumn - 1; k++) {
            Cell cell = row_cre.createCell((short) (k));
        }
    }

    for (int j = 1; j < lastColumn; j++) {//make result sheet
        for (int i = 0; i < count; i++) {
            re[i] = res[j - 1][i];
            im[i] = 0;
        }
        beforeAfter(fft, re, im);
        for (int i = 0; i < re.length / 2; i++) {
            Row row_out = sheet_out.getRow(i);
            Cell cell = row_out.getCell((short) (j - 1));
            cell.setCellValue(Math.abs(re[i]));
        }

    }

    FileOutputStream fileOut//write file
            = new FileOutputStream("/Users/huangge/Documents/workspace/fft/src/workbook.xls");
    wb_out.write(fileOut);
    fileOut.close();

    long time = System.currentTimeMillis();
    double iter = 10;
    for (int i = 0; i < iter; i++)
        // fft.fft(re,im);
        time = System.currentTimeMillis() - time;
    System.out.println("Averaged " + (time / iter) + "ms per iteration");
}

From source file:FormatConvert.exceloperation.ExcelOperation.java

public static void SeperatorExcel2sheet(String excelfile, String targetdir) {
    try {//  w w w  .j  a  v  a 2s . co m
        FileInputStream is = (new FileInputStream(excelfile));
        if (excelfile.endsWith(".xlsx")) {
            XSSFWorkbook wb = new XSSFWorkbook(is);
            int sheetnub = wb.getNumberOfSheets();
            for (int i = 0; i < sheetnub; i++) {
                XSSFSheet sheet = wb.getSheetAt(i);
                if (sheet.toString() != null) {
                    Workbook wb2 = new XSSFWorkbook();
                    XSSFSheet tempsheet = (XSSFSheet) wb2.createSheet();
                    Util.copySheets(tempsheet, sheet, true);
                    //tempsheet=wb.cloneSheet(i);
                    //tempsheet = sheet;
                    String temfile = targetdir + "\\" + sheet.getSheetName() + ".xlsx";
                    FileOutputStream fileOut = new FileOutputStream(temfile);
                    wb2.write(fileOut);
                    fileOut.close();
                }
            }
        } else {
            HSSFWorkbook wb = new HSSFWorkbook(is);
            int sheetnub = wb.getNumberOfSheets();
            for (int i = 0; i < sheetnub; i++) {
                HSSFSheet sheet = wb.getSheetAt(i);
                if (sheet.toString() != null) {
                    Workbook wb2 = new HSSFWorkbook();
                    HSSFSheet tempsheet = (HSSFSheet) wb2.createSheet();
                    Util.copySheets(tempsheet, sheet, true);
                    //tempsheet=wb.cloneSheet(i);
                    //tempsheet = sheet;
                    String temfile = targetdir + "\\" + sheet.getSheetName() + ".xlsx";
                    FileOutputStream fileOut = new FileOutputStream(temfile);
                    wb2.write(fileOut);
                    fileOut.close();
                }
            }
        }

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

From source file:gr.open.loglevelsmanager.loglevel.LogLevelExporter.java

License:Open Source License

public static Workbook generateExcel(long groupId, boolean first, boolean showTypes,
        LinkedHashMap<String, String> dataHeaders) throws SystemException {

    Workbook book = new HSSFWorkbook();
    Sheet sheet = book.createSheet();

    int itRow = 0;
    int itCell = 0;
    Row row = null;/*from   w  w  w . j a va  2  s. com*/
    Cell cell = null;

    row = sheet.createRow(itRow);
    itRow++;
    if (showTypes) {
        Row row2 = sheet.createRow(itRow);
        itRow++;
        Cell cell2 = null;
        for (String key : dataHeaders.keySet()) {
            // Head
            cell = row.createCell(itCell);
            cell.setCellValue(key);
            // Types
            cell2 = row2.createCell(itCell);
            cell2.setCellValue(dataHeaders.get(key));
            itCell++;
        }
    } else {
        for (String key : dataHeaders.keySet()) {
            // Head
            cell = row.createCell(itCell);
            cell.setCellValue(key);
            itCell++;
        }
    }

    List<LogLevel> listEntities = LogLevelLocalServiceUtil.findAllInGroup(groupId);
    if (first) {
        if (listEntities.size() > 0) {
            row = sheet.createRow(itRow);
            LogLevel entity = listEntities.get(0);
            row = generateRow(entity, row);
            itRow++;
        }
    } else {
        for (LogLevel entity : listEntities) {
            row = sheet.createRow(itRow);
            row = generateRow(entity, row);
            itRow++;
        }
    }

    // Autosize columns
    for (int x = 0; x < (itCell + 1); x++) {
        sheet.autoSizeColumn(x);
    }
    return book;
}