Examples of HSSFWorkbook


Examples of org.apache.poi.hssf.usermodel.HSSFWorkbook

   
    /**
     * CreateFreezePane column/row order check
     */
    public void test49381() throws Exception {
       Workbook[] wbs = new Workbook[] { new HSSFWorkbook(), new XSSFWorkbook() };
       int colSplit = 1;
       int rowSplit = 2;
       int leftmostColumn = 3;
       int topRow = 4;

View Full Code Here

Examples of org.apache.poi.hssf.usermodel.HSSFWorkbook

        Preferences coreStore = BrowserCorePlugin.getDefault().getPluginPreferences();
        String valueDelimiter = coreStore.getString( BrowserCoreConstants.PREFERENCE_FORMAT_XLS_VALUEDELIMITER );
        int binaryEncoding = coreStore.getInt( BrowserCoreConstants.PREFERENCE_FORMAT_XLS_BINARYENCODING );

        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet sheet = wb.createSheet( "Export" ); //$NON-NLS-1$

        // header
        HSSFRow headerRow = sheet.createRow( 0 );
        LinkedHashMap<String, Short> attributeNameMap = new LinkedHashMap<String, Short>();
        if ( this.exportDn )
        {
            short cellNum = ( short ) 0;
            attributeNameMap.put( "dn", new Short( cellNum ) ); //$NON-NLS-1$
            headerRow.createCell( cellNum ).setCellValue( "dn" ); //$NON-NLS-1$
        }

        // String[] exportAttributes =
        // this.searchParameter.getReturningAttributes();
        // exportAttributes = null;
        // for (int i = 0; exportAttributes != null && i <
        // exportAttributes.length; i++) {
        // short cellNum = (short)attributeNameMap.size();
        // attributeNameMap.put(exportAttributes[i], new Short(cellNum));
        // headerRow.createCell(cellNum).setCellValue(exportAttributes[i]);
        // }

        // max export
        if ( searchParameter.getCountLimit() < 1 || searchParameter.getCountLimit() > MAX_COUNT_LIMIT )
        {
            searchParameter.setCountLimit( MAX_COUNT_LIMIT );
        }

        // export
        try
        {
            int count = 0;
            exportToXls( browserConnection, searchParameter, sheet, headerRow, count, monitor, attributeNameMap,
                valueDelimiter, binaryEncoding, this.exportDn );
        }
        catch ( Exception e )
        {
            monitor.reportError( e );
        }

        // column width
        for ( int i = 0; i <= sheet.getLastRowNum(); i++ )
        {
            HSSFRow row = sheet.getRow( i );
            for ( short j = 0; row != null && j <= row.getLastCellNum(); j++ )
            {
                HSSFCell cell = row.getCell( j );
                if ( cell != null && cell.getCellType() == HSSFCell.CELL_TYPE_STRING )
                {
                    String value = cell.getStringCellValue();

                    if ( ( short ) ( value.length() * 256 * 1.1 ) > sheet.getColumnWidth( j ) )
                    {
                        sheet.setColumnWidth( j, ( short ) ( value.length() * 256 * 1.1 ) );
                    }
                }
            }
        }

        try
        {
            FileOutputStream fileOut = new FileOutputStream( exportXlsFilename );
            wb.write( fileOut );
            fileOut.close();
        }
        catch ( Exception e )
        {
            monitor.reportError( e );
View Full Code Here

Examples of org.apache.poi.hssf.usermodel.HSSFWorkbook

    assertEquals(42, ((NumberEval)result).getNumberValue(), 0.0);
  }


  public void testEvaluateMultipleWorkbooks() {
    HSSFWorkbook wbA = HSSFTestDataSamples.openSampleWorkbook("multibookFormulaA.xls");
    HSSFWorkbook wbB = HSSFTestDataSamples.openSampleWorkbook("multibookFormulaB.xls");

    HSSFFormulaEvaluator evaluatorA = new HSSFFormulaEvaluator(wbA);
    HSSFFormulaEvaluator evaluatorB = new HSSFFormulaEvaluator(wbB);

    // Hook up the workbook evaluators to enable evaluation of formulas across books
    String[] bookNames = { "multibookFormulaA.xls", "multibookFormulaB.xls", };
    HSSFFormulaEvaluator[] evaluators = { evaluatorA, evaluatorB, };
    HSSFFormulaEvaluator.setupEnvironment(bookNames, evaluators);

    HSSFCell cell;

    HSSFSheet aSheet1 = wbA.getSheetAt(0);
    HSSFSheet bSheet1 = wbB.getSheetAt(0);

    // Simple case - single link from wbA to wbB
    confirmFormula(wbA, 0, 0, 0, "[multibookFormulaB.xls]BSheet1!B1");
    cell = aSheet1.getRow(0).getCell(0);
    confirmEvaluation(35, evaluatorA, cell);
View Full Code Here

Examples of org.apache.poi.hssf.usermodel.HSSFWorkbook

  /**
   * This test makes sure that any {@link MissingArgEval} that propagates to
   * the result of a function gets translated to {@link BlankEval}.
   */
  public void testMissingArg() {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("Sheet1");
    HSSFRow row = sheet.createRow(0);
    HSSFCell cell = row.createCell(0);
    cell.setCellFormula("1+IF(1,,)");
    HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
    CellValue cv;
View Full Code Here

Examples of org.apache.poi.hssf.usermodel.HSSFWorkbook

  @Override
  public void processExport(OutputStream output) {

    try {
      HSSFWorkbook workbook = new HSSFWorkbook();
      HSSFSheet sheet = workbook.createSheet(exportConf.getFileName());
      Row row = null;
      Cell cell = null;
      int rowIndex = 0;
      int columnIndex;

      // Header
      if (exportConf.getIncludeHeader()) {

        for (HtmlRow htmlRow : table.getHeadRows()) {

          row = sheet.createRow(rowIndex++);
          columnIndex = 0;

          for (HtmlColumn column : htmlRow.getColumns(ReservedFormat.ALL, ReservedFormat.XLS)) {
            cell = row.createCell(columnIndex++);
            cell.setCellValue(column.getContent().toString());
          }
        }
      }

      // Body
      for (HtmlRow htmlRow : table.getBodyRows()) {

        row = sheet.createRow(rowIndex++);
        columnIndex = 0;

        for (HtmlColumn column : htmlRow.getColumns(ReservedFormat.ALL, ReservedFormat.XLS)) {
          cell = row.createCell(columnIndex++);
          cell.setCellValue(column.getContent().toString());
        }
      }

      // Column auto-sizing
      for (columnIndex = 0; columnIndex < table.getLastHeaderRow().getColumns(ReservedFormat.ALL, ReservedFormat.XLS).size(); columnIndex++) {
        if (exportConf.getAutoSize()) {
          sheet.autoSizeColumn(columnIndex);
        }
      }

      workbook.write(output);

    } catch (IOException e) {
      StringBuilder sb = new StringBuilder("Something went wrong during the XLS generation of the table '");
      sb.append(table.getOriginalId());
      sb.append("' and with the following export configuration: ");
View Full Code Here

Examples of org.apache.poi.hssf.usermodel.HSSFWorkbook

    private Workbook createWorkbook(URI document, InputStream is) throws IOException {
        final String documentURI = document.toString();
        if(documentURI.endsWith(".xlsx")) {
            return new XSSFWorkbook(is);
        } else if(documentURI.endsWith("xls")) {
            return new HSSFWorkbook(is);
        } else {
            throw new IllegalArgumentException("Unsupported extension for resource [" + documentURI + "]");
        }
    }
View Full Code Here

Examples of org.apache.poi.hssf.usermodel.HSSFWorkbook

        if (version == null) {
            throw new IllegalArgumentException("version must not be null"); //$NON-NLS-1$
        }
        switch (version) {
        case EXCEL97:
            return new HSSFWorkbook();
        case EXCEL2007:
            return new XSSFWorkbook();
        default:
            throw new IOException(MessageFormat.format(
                    "サポートしていないExcelワークブックの形式です: {0}",
View Full Code Here

Examples of org.apache.poi.hssf.usermodel.HSSFWorkbook

     */
    protected Workbook openWorkbook(File file) throws IOException {
        InputStream in = new FileInputStream(file);
        try {
            if (file.getName().endsWith(".xls")) {
                return new HSSFWorkbook(in);
            } else if (file.getName().endsWith(".xlsx")) {
                return new XSSFWorkbook(in);
            } else {
                throw new IOException(file.getPath());
            }
View Full Code Here

Examples of org.apache.poi.hssf.usermodel.HSSFWorkbook

    private Sheet sheet(String name) {
        InputStream in = getClass().getResourceAsStream(name);
        assertThat(name, in, not(nullValue()));
        try {
            Workbook book = new HSSFWorkbook(in);
            return book.getSheetAt(0);
        } catch (IOException e) {
            throw new AssertionError(e);
        } finally {
            try {
                in.close();
View Full Code Here

Examples of org.apache.poi.hssf.usermodel.HSSFWorkbook

        }
    }

    static Workbook openWorkbookFor(String path, InputStream input) throws IOException {
        if (isHssf(path)) {
            return new HSSFWorkbook(input);
        } else if (isXssf(path)) {
            return new XSSFWorkbook(input);
        } else {
            return new HSSFWorkbook(input);
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.