Examples of HSSFSheet


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

   * @return
   * @throws Exception
   */
  public HSSFWorkbook toExcel(HSSFWorkbook wb, String sheetName, Collection<Object[]> datas,
      String propertyShowKeys) throws Exception {
    HSSFSheet sheet = wb.createSheet(sheetName);
    HSSFRow row = null;
    HSSFCell cell = null;

    /** **************** 取得传入的list列名称和显示名称 ********** */
    String[] pShowKeys = Tokenizer2StringArray(propertyShowKeys, ",");
    // 创建�?行(标题)
    row = sheet.createRow(0); // 建立新行
    // 显示标题列名
    for (int i = 0; i < pShowKeys.length; i++) {
      cell = row.createCell(i); // 建立新cell
      // cell.setEncoding(HSSFCell.ENCODING_UTF_16);
      cell.setCellValue(new HSSFRichTextString(pShowKeys[i]));
    }
    // 逐行取数
    int rowId = 1;// 数据行号(从2行开始填充数�?)
    for (Iterator<Object[]> iter = datas.iterator(); iter.hasNext(); rowId++) {
      row = sheet.createRow(rowId); // 建立新行
      Object[] objs = iter.next();
      // 生成每一�?
      for (int j = 0; j < objs.length; j++) {
        cell = row.createCell(j); // 建立新cell
        // cell.setEncoding(HSSFCell.ENCODING_UTF_16);
View Full Code Here

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

   * @throws Exception
   */
  public <T extends Object> HSSFWorkbook object2Excel(HSSFWorkbook wb, String sheetName,
      Collection<T> list, String propertyKeys, String propertyShowKeys, PropertyExtractor exporter)
      throws Exception {
    HSSFSheet sheet = wb.createSheet(sheetName);
    HSSFRow row = null;
    HSSFCell cell = null;
    Object cellVal = null;

    /** **************** 取得传入的list列名称和显示名称 ********** */
    String[] pKeys = Tokenizer2StringArray(propertyKeys, ",");
    String[] pShowKeys = Tokenizer2StringArray(propertyShowKeys, ",");
    /** *************** insert data to excel*************** */
    // 创建(标题)
    row = sheet.createRow(0); // 建立新行
    // 显示标题列名�?
    for (int i = 0; i < pShowKeys.length; i++) {
      cell = row.createCell(i); // 建立新cell
      // cell.setEncoding(HSSFCell.ENCODING_UTF_16);
      cell.setCellValue(new HSSFRichTextString(pShowKeys[i]));
    }
    // 逐行取数�?
    int rowId = 1;// 数据行号(从�?2行开始填充数�?)
    for (Iterator<T> iter = list.iterator(); iter.hasNext(); rowId++) {
      row = sheet.createRow(rowId); // 建立新行
      T obj = iter.next();
      // 生成每一
      for (int i = 0; i < pKeys.length; i++) {
        cell = row.createCell(i); // 建立新cell
        cellVal = exporter.getPropertyValue(obj, pKeys[i]);
View Full Code Here

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

      StringBuilder content = new StringBuilder(bis.available());
      POIFSFileSystem fs = new POIFSFileSystem(bis);
      HSSFWorkbook workbook = new HSSFWorkbook(fs);

      for (int sheetNumber = 0; sheetNumber < workbook.getNumberOfSheets(); sheetNumber++) {
        HSSFSheet sheet = workbook.getSheetAt(sheetNumber);
        if (sheet != null) {
          for (int rowNumber = sheet.getFirstRowNum(); rowNumber <= sheet.getLastRowNum(); rowNumber++) {
            HSSFRow row = sheet.getRow(rowNumber);
            if (row != null) {
              for (int cellNumber = row.getFirstCellNum(); cellNumber <= row.getLastCellNum(); cellNumber++) {
                HSSFCell cell = row.getCell(cellNumber);
                if (cell != null) {
                  // if (cell.getCellStyle().equals(HSSFCell.CELL_TYPE_NUMERIC))
View Full Code Here

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

        if (ptg instanceof Ref3DPtg)
        {
           
            Ref3DPtg ptg3D = (Ref3DPtg)ptg;
           
            HSSFSheet sheet = _workbook.getSheetAt(ptg3D.getExternSheetIndex() + 1 );     
            HSSFRow row     = sheet.getRow(ptg3D.getRow())
            HSSFCell cell   = row.getCell(ptg3D.getColumn());
           
            _currentSheetListener.newCell( formulaRec.getRow( ),
                    formulaRec.getColumn( ),
                                       "" + cell.getStringCellValue() );
View Full Code Here

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

        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 ) );
                    }
                }
            }
        }

View Full Code Here

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

    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);


    // more complex case - back link into wbA
    // [wbA]ASheet1!A2 references (among other things) [wbB]BSheet1!B2
    confirmFormula(wbA, 0, 1, 0, "[multibookFormulaB.xls]BSheet1!$B$2+2*A3");
    // [wbB]BSheet1!B2 references (among other things) [wbA]AnotherSheet!A1:B2
    confirmFormula(wbB, 0, 1, 1, "SUM([multibookFormulaA.xls]AnotherSheet!$A$1:$B$2)+B3");

    cell = aSheet1.getRow(1).getCell(0);
    confirmEvaluation(264, evaluatorA, cell);

    // change [wbB]BSheet1!B3 (from 50 to 60)
    HSSFCell cellB3 = bSheet1.getRow(2).getCell(1);
    cellB3.setCellValue(60);
    evaluatorB.notifyUpdateCell(cellB3);
    confirmEvaluation(274, evaluatorA, cell);

    // change [wbA]ASheet1!A3 (from 100 to 80)
View Full Code Here

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

   * 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;
    try {
View Full Code Here

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

  @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);
View Full Code Here

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

        String filename = "src/test/data/Excel/ExcelUtils/ALLT_TYPES.xls";

        // テスト対象のEXCELシートを取得
        InputStream is = new FileInputStream(filename);
        HSSFWorkbook workbook = new HSSFWorkbook(is);
        HSSFSheet sheet = workbook.getSheet(Constants.OUTPUT_DATA_SHEET_NAME);

        // テスト対象のExcelUtilsオブジェクトを生成
        ExcelUtils excelUtils =  new ExcelUtils(filename);

View Full Code Here

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

        // セルスタイルを作成
        configureColumnStyle();

        // 入力データのシートと出力データのシートを生成
        HSSFSheet inputSheet = createInputDataSheet(Constants.INPUT_DATA_SHEET_NAME);
        int inputSheetIndex = workbook.getSheetIndex(inputSheet);
        HSSFSheet outputSheet = workbook.cloneSheet(inputSheetIndex);
        int outputSheetIndex = workbook.getSheetIndex(outputSheet);
        workbook.setSheetName(outputSheetIndex, Constants.OUTPUT_DATA_SHEET_NAME);

        // テスト条件のシートを生成
        createTestConditionSheet(Constants.TEST_CONDITION_SHEET_NAME);
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.