Package com.extentech.ExtenXLS

Examples of com.extentech.ExtenXLS.CellHandle


      newbytes= ByteTools.append(sxdbex.getRecord(), newbytes);
//System.out.println("SXDBEX: " + Arrays.toString(sxdbex.getRecord()));       
      // TODO: cells after row header cell ***should be*** the same type -- true in ALL cases??????
      if (ch.length>cols.length) { // have multiple rows
        for (int i= 0; i < cols.length; i++) {
          CellHandle c= ch[i+(cols.length)];
          int type= -1;
          if (c.isDate())
            type= 6;
          else
            type= c.getCellType();
          types[i]= type;
        }
      }
//TODO: ranges/grouping and formulas !!!!
//TODO: boolean vals?   
      for (int z= 0; z < rows.length; z++) {       
        for (int i= 0; i < cols.length; i++) {
          if (z==0) { // # SxFDB records==# COLUMNS==# Cache Fields
            SxFDB sxfdb= (SxFDB) SxFDB.getPrototype();
            sxfdb.setCacheItemsType(types[i]);
            sxfdb.setCacheField(ch[i].getStringVal())// row header values
            sxfdb.setNCacheItems(0);    // only set ACTUAL cache items when put cache field(s)on the pivot table (on row, page, column or data axis)           
            newbytes= ByteTools.append(sxfdb.getRecord(), newbytes);
//System.out.println("SXFDB: " + Arrays.toString(sxfdb.getRecord()));       
            SXFDBType sxfdbtype= (SXFDBType) SXFDBType.getPrototype();
            newbytes= ByteTools.append(sxfdbtype.getRecord(), newbytes);
//System.out.println("SXDFBTYPE: " + Arrays.toString(sxfdbtype.getRecord()));       
            continue;
          }
          cachefieldindexes[i][z-1]= (byte)i;
          // data cells== CACHE ITEMS
          CellHandle c= ch[z*(cols.length)+i];
// TODO: handle SxNil, SxErr, SxDtr
// TODO: handle SxFmla, SXName, SxPair, SxFormula         
          switch (types[i]) {
          case XLSConstants.TYPE_STRING:
            SXString sxstring= (SXString) SXString.getPrototype();
            sxstring.setCacheItem(c.getStringVal());
            newbytes= ByteTools.append(sxstring.getRecord(), newbytes);
//System.out.println("SXSTRING: " + Arrays.toString(sxstring.getRecord()));       
            break;
          case XLSConstants.TYPE_FP:
          case XLSConstants.TYPE_INT:
          case XLSConstants.TYPE_DOUBLE:
            SXNum sxnum= (SXNum) SXNum.getPrototype();
            sxnum.setNum(c.getDoubleVal());
            newbytes= ByteTools.append(sxnum.getRecord(), newbytes);
//System.out.println("SXNUM: " + Arrays.toString(sxnum.getRecord()));       
            break;
          case XLSConstants.TYPE_BOOLEAN:
            SXBool sxbool= (SXBool) SXBool.getPrototype();
            sxbool.setBool(c.getBooleanVal());
            newbytes= ByteTools.append(sxbool.getRecord(), newbytes);
//System.out.println("SXBOOL: " + Arrays.toString(sxbool.getRecord()));       
        //TYPE_FORMULA = 3,    SxFmla *(SxName *SXPair)
          case 6:
            // SXDtr
View Full Code Here


            myfmthandle2.setRightBorderLineStyle(FormatHandle.BORDER_DOUBLE);
         
            // ok, test not clobbering
            CellRange range4 = new CellRange(sheet, coords2, true);
           
            CellHandle cell0 = range4.getCells()[0];
          
            FormatHandle clobberfmt = cell0.getFormatHandle();
            clobberfmt.setCellBackgroundColor(Color.lightGray);
            clobberfmt.setUnderlined(true);
           
            cell0.setVal("hello world!");
           
           
    }catch(Exception ex) {
      Logger.logErr("testCellBorder failed:" + ex.toString());
    }
View Full Code Here

  public static void main(String[] args) {
    WorkBookHandle book = new WorkBookHandle();
    try{
      WorkSheetHandle sheet = book.getWorkSheet("Sheet1");
      CellHandle a1 = sheet.add("hello world","a1");
      sheet.setProtected(true);
        writeFile(book, "testPasswordProtect.xls");
            book.close();
        book = new WorkBookHandle(wd+"testPasswordProtect.xls");
            sheet = book.getWorkSheet("Sheet1");
View Full Code Here

       fmt1.setFontColor(FormatHandle.COLOR_YELLOW);
       fmt1.setBackgroundPattern(FormatHandle.PATTERN_HOR_STRIPES3);

      fmt1.setBorderLineStyle(FormatHandle.BORDER_MEDIUM_DASH_DOT_DOT);
      sheet.add("NEW CELL!","C5");
      CellHandle bordercell = sheet.getCell("C3");
   
      int i = bordercell.getFormatId();
      fmt1.addCell(bordercell);
      i = bordercell.getFormatId();
      System.out.println(i);
    }catch(Exception e){System.out.println(e);}
    testWrite(tbo, "testFormats_out.xls");
  }
View Full Code Here

    FormatHandle fmt2 = new FormatHandle(tbo);
    try{
      sheet = tbo.getWorkSheet(sheetname);

      // TEST BORDERS
      CellHandle bordercell = sheet.getCell("C3");
      int borderfmt = bordercell.getFormatId();
     
      sheet.add("MODDY BORDER", "A10");
      bordercell = sheet.getCell("A10");
      FormatHandle fmx = new FormatHandle(tbo);
      fmx.setBorderLineStyle(3);
      fmx.setBorderTopColor(FormatHandle.COLOR_LIGHT_BLUE);
      fmx.setBorderBottomColor(FormatHandle.COLOR_GREEN);
      fmx.setBorderLeftColor(FormatHandle.COLOR_YELLOW);
      fmx.setBorderRightColor(FormatHandle.COLOR_BLACK);
      fmx.addCell(sheet.add("Great new cell!!", "A1"));
      fmx.setFont("Courier",Font.BOLD,12);
      fmx.setForegroundColor(FormatHandle.COLOR_BRIGHT_GREEN);
      fmx.setBackgroundColor(FormatHandle.COLOR_BLUE);
      fmx.setFontColor(FormatHandle.COLOR_BLUE);
      fmx.setBackgroundPattern(FormatHandle.PATTERN_HOR_STRIPES3);

      CellHandle cell1 = null;
      sheet.setHeaderText("Extentech Inc.");
      sheet.setFooterText("Created by ExtenXLS:" + WorkBookHandle.getVersion());
      String addr = "";
      for(int i = 1;i<50;i++){
        addr = "h"+String.valueOf(i);
        sheet.add(new Long((long)3324.234 * i), addr);
        cell1 = sheet.getCell(addr);
        cell1.setFormatHandle(fmx);

        addr = "i"+String.valueOf(i);
        sheet.add("Hello World " + i, addr);
        cell1 = sheet.getCell(addr);
        cell1.setFormatHandle(fmt1);
      }               

      color = FormatHandle.COLOR_LIGHT_BLUE;
      patern = FormatHandle.PATTERN_LIGHT_DOTS;
      cell1 = sheet.getCell("H14");
      cell1.setFormatHandle(fmt2);
      cell1.setVal(44444);
      cell1.setForegroundColor(FormatHandle.COLOR_DARK_RED);
      cell1.setBackgroundColor(FormatHandle.COLOR_DARK_YELLOW);
      cell1.setBackgroundPattern(patern);
      cell1.setFontColor(color);
      cell1.setVal(555);    
      System.out.println("CELL FCOLOR: " + cell1.getForegroundColor());
      System.out.println("CELL FCOLOR: " + cell1.getBackgroundColor());
    }catch(Exception e){System.out.println(e);}
    testWrite(tbo, "testFormats1_out.xls");
     
   
    // FORMAT ID Sharing
    // the fastest, no fuss way to use formats
    // on multiple cells
   
        WorkSheetHandle sheet1 = null;
    try{
      sheet1 = tbo.getWorkSheet("Sheet1");
    }catch(Exception e){System.out.println(e);}
    sheet1.add("Eurostile Template Cell","A1");
    int SHAREDFORMAT = 0;
    CellHandle b = null;
    CellHandle a= null;
    try{
      b = sheet1.getCell("A1");
      b.setFont("Eurostile",Font.BOLD,14);
      // set format options
      b.setForegroundColor(30);
      b.setBackgroundColor(54);
      b.setBackgroundPattern(3);
     
      SHAREDFORMAT = b.getFormatId();
      for(int t = 1; t<=10;t++){
        sheet1.add(new Float(t*67.5),"E" + t);
        a = sheet1.getCell("E" + t);
        a.setFormatId(SHAREDFORMAT);
      }

      a.setFont("Tango",Font.BOLD,26);
      a.setFontColor(10);
      a.setFormatPattern("[h]:mm:ss");
      a.setURL("http://www.extentech.com/");
      a.setScript(2);
      sheet1.moveCell(a,"A10");
      a.getCol().setWidth(8000);
      tbo.copyWorkSheet(sheetname, sheetname + " Copy");
    }catch(Exception e){System.out.println(e);}
       
    // optimize String table by sharing dupe entries
    tbo.setDupeStringMode(WorkBookHandle.SHAREDUPES);
    tbo.setStringEncodingMode(WorkBookHandle.STRING_ENCODING_COMPRESSED);

    //iterate backgrounds
    for(int x = 0;x<32;x++){
        sheet1.add("Pattern# " + x, "F"+(x+1));
        sheet1.add("Text", "G"+(x+1));
      try{
        CellHandle c = sheet1.getCell("G"+(x+1));
        c.setBackgroundPattern(x);
        c.setFont("Tango",Font.BOLD,26);
        c.setFontColor(10);
      }catch(Exception e){System.out.println(e);}
    }

    //iterate colors
    for(int x = 0;x<64;x++){
      try{
        sheet1.add("Color# " + x, "C"+(x+1));
        sheet1.add(" ", "D"+(x+1));
        CellHandle c = sheet1.getCell("D"+(x+1));
        c.setBackgroundPattern(x);
        c.setBackgroundColor(x);
        c.setForegroundColor(x);
      }catch(Exception e){System.out.println(e);}
    }
       
    // remove a col and a row
    try{
View Full Code Here

          if (row.getOutlineLevel()!=0)
              writer.write( (" outlineLevel=\"" + row.getOutlineLevel() + "\"") );
          writer.write( ">" );
          writer.write( "\r\n" );
          // Cell element <c
          CellHandle ch[]= row.getCells();
          // iterate cells and output xml
          for (int j= 0; j<ch.length; j++) {
              int styleId= ch[j].getCell().getIxfe();     
              int dataType= ch[j].getCellType();                 
              if (ch[j].hasHyperlink()){   // save; hyperlinks go after sheetData
View Full Code Here

        while(ii.hasNext()) {
            String cellAddr= (String) ii.next();
            String s= (String) inlineStrs.get(cellAddr);
            int[] rc = ExcelTools.getRowColFromString(cellAddr);
            try{
                 CellHandle ch= bk.getCell(cellAddr);   // should have been added already
                 ch.setVal(s);
             }catch(Exception ex){;}
        }
    }
View Full Code Here

    /**
     * intercept Sheet adds and hand off to parse event listener as needed
     *
     */
    protected CellHandle sheetAdd(WorkSheetHandle sheet, Object val, Object cachedval, int r, int c, int fmtid){
        CellHandle ch= sheetAdd(sheet,val,r,c,fmtid);
        ((Formula)ch.getCell()).setCachedValue(cachedval);  
        return ch;
    }
View Full Code Here

                          cachedValue= new Double((String)cachedValue);
                      }
                  else if (type.equals("b"))
                      cachedValue= Boolean.valueOf((String)cachedValue);
                  // type e -- input calculation exception?
                  CellHandle ch= null// normal case but may be created * as a blank * if part of a merged cell range or dv ...
                  try{
                     sheet = bk.getWorkSheet(s[0]);  
                     ch= sheet.getCell(addr);   // if exists, grab it;                              
                  }catch(Exception ex){;}
                  if (fStr.equals("null")) { // when would this ever occur?
                     Logger.logWarn("OOXMLAdapter.parse: invalid formula encountered at " + addr);
                  }
                 
                  if (fType.equals("array")) {
                      /*
                       * For a multi-cell formula, the r attribute of the top-left cell
                       * of the range 1 of cells to which that formula applies
                         shall designate the range of cells to which that formula applies
                       */
                      int[] arrayref= null;
                      if (s[4]!=null) {   // if has the ref attribute means its the PARENT array formula
                          sheet.getMysheet().addParentArrayRef(s[1], s[4]);
                          arrayref= ExcelTools.getRangeRowCol(s[4]);
                      } else
                          arrayref= rc;
                      /* must enter array formulas for each cell in range denoted by array ref*/
                      for (int r= arrayref[0]; r <= arrayref[2]; r++) {
                          for (int c= arrayref[1]; c<=arrayref[3]; c++) {
                              try{
                                 ch= sheet.getCell(r, c);   // if exists, grab it;                              
                              }catch(Exception ex){;}
                               if(ch==null)
                                 ch= sheetAdd(sheet,"{" + fStr + "}",cachedValue, r,c,fmtid);
                               else {
                                 ch.setFormatId(fmtid); // if exists may be part of a merged cell range and therefore it's correct format id may NOT have been set; see mergedranges in parseSheetXML below
                                 ch.setFormula("{" + fStr + "}", cachedValue); // set cached value so don't have to recalculate; just sets cached value if formula is already set
                               }
                          }
                      }
                  } else if (fType.equals("datatable")) {
                      if(ch==null)
                        ch = sheetAdd(sheet,fStr,cachedValue,rc[0],rc[1],fmtid);
                      else {
                         ch.setFormatId(fmtid); // if exists may be part of a merged cell range and therefore it's correct format id may NOT have been set; see mergedranges in parseSheetXML below
                         ch.setFormula(fStr, cachedValue);      // set cached value so don't have to recalculate; just sets cached value if formula is already set
                      }
                  } else if (fType.equals("shared") && !s[3].equals("")) {        // meaning that if it's set as shared but doesn't have a shared index, make regular function -- is what excel 2007 does :) 
                      // Shared Formulas: there is the "master" shared formula which defines the formula + the range (=ref) of cells that the formula refers to
                      // For references to the shared formula, the si index denotes the shared formula it refers to
                      // one takes the master formula cell, compares with the current cell's address and increments the references in the master shared
                      // formula accordingly -- algorithm of comparison and movement can be tricky
                      Integer si = Integer.valueOf(s[3]);
                      if (!sharedFormulas.containsKey(si)) {
                          // represents the "master" formula of a shared formula, movement is based upon relationship of subsequent cells to this cell
                          if(ch==null)
                            ch = sheetAdd(sheet,fStr,cachedValue, rc[0],rc[1],fmtid);
                          else {
                             ch.setFormatId(fmtid); // if exists may be part of a merged cell range and therefore it's correct format id may NOT have been set; see mergedranges in parseSheetXML below
                             ch.setFormula(fStr, cachedValue)// set cached value so don't have to recalculate; just sets cached value if formula is already set
                          }                         
                          // see if it's a 3d range
                          int[] range= ExcelTools.getRangeCoords(s[3]);
                          range[0]-=1;  range[2]-=1;
                          Stack expressionStack= cloneStack(ch.getFormulaHandle().getFormulaRec().getExpression());
                          sharedFormulas.put(si, new Object[] {expressionStack, rc, range});
                      } else { // found shared formula- means already created; must get original and "move" based on position of this - the child - shared formula
                          Object[] o= (Object[])sharedFormulas.get(si);
                          Stack ss= cloneStack((Stack) o[0]);
                          int[] rcOrig= ((int[])o[1]);                                       
                          Formula.incrementSharedFormula(ss, rc[0]-rcOrig[0], rc[1]-rcOrig[1], (int[])o[2]);
                         
                          if(ch==null) { 
                                ch= sheetAdd(sheet,"=0", null, rc[0],rc[1],fmtid); // add a basic formula; will be "overwritten" by expression, set below
                                ch.setFormula(ss, cachedValue); // must set child shared formulas via expression rather than via formula string as original formula string must be incremented
                          } else {
                              ch.setFormula(ss, cachedValue);   // must set child shared formulas via expression rather than via formula string as original formula string must be incremented
                              ch.setFormatId(fmtid); // if exists may be part of a merged cell range and therefore it's correct format id may NOT have been set; see mergedranges in parseSheetXML below
                          }                           
                      }                              
                  } else {// it's a regular function                                
                      if(ch==null)                  
                          // use parser-aware method
                          ch= sheetAdd(sheet,fStr,cachedValue,rc[0],rc[1],fmtid);  
                      else {
                         ch.setFormatId(fmtid); // if exists most likely is part of a merged cell range and therefore it's correct format id may NOT have been set; see mergedranges in parseSheetXML below
                         ch.setFormula(fStr, cachedValue);      // set cached value so don't have to recalculate; just sets cached value if formula is already set
                      }
                    
                  }                                
                  if (s[6]!=null && ch!=null){  // for formulas such as =TODAY
                      BiffRec br = ch.getCell();
                      if(br instanceof Formula)
                         ch.getFormulaHandle().setCalcAlways(true);
                  }
              } catch (FunctionNotSupportedException e) {
                     Logger.logErr("OOXMLAdapter.parse: failed setting formula " + s[1] + " to cell " + s[0] + ": " + e.toString());                             
              } catch (Exception e) {
                  Logger.logErr("OOXMLAdapter.parse: failed setting formula " + s[1] + " to cell " + s[0] + ": " + e.toString());                                
View Full Code Here

TOP

Related Classes of com.extentech.ExtenXLS.CellHandle

Copyright © 2018 www.massapicom. 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.