0 Replies Latest reply: Jan 24, 2007 5:58 AM by 807596 RSS

    Read Excel with macros using Java POI

    807596
      Hi,
      I'm very desperate... I have to do following things: read Excel file with macros. I can read xls without macros, but i haven't ideas what to do, so correctly read records with macros in xls.
      I use following method to listen for incoming records and handles them as required.
      public void processRecord(Record record)
      {
      switch (record.getSid())
      {
      // the BOFRecord can represent either the beginning of a sheet or the workbook
      case BOFRecord.sid:
      BOFRecord bof = (BOFRecord) record;
      if (bof.getType() == bof.TYPE_WORKBOOK)
      {
      System.out.println("Encountered workbook");
      // assigned to the class level member
      } else if (bof.getType() == bof.TYPE_WORKSHEET)
      {
      System.out.println("Encountered sheet reference");
      }
      break;
      case BoundSheetRecord.sid:
      BoundSheetRecord bsr = (BoundSheetRecord) record;
      System.out.println("New sheet named: " + bsr.getSheetname());
      break;
      case RowRecord.sid:
      RowRecord rowrec = (RowRecord) record;
      System.out.println("Row found, first column at "
      + rowrec.getFirstCol() + " last column at " + rowrec.getLastCol());
      break;
      case NumberRecord.sid:
      NumberRecord numrec = (NumberRecord) record;
      System.out.println("Cell found with value " + numrec.getValue()
      + " at row " + numrec.getRow() + " and column " + numrec.getColumn());
      break;
      // SSTRecords store a array of unique strings used in Excel.
      case SSTRecord.sid:
      sstrec = (SSTRecord) record;
      for (int k = 0; k < sstrec.getNumUniqueStrings(); k++)
      {
      System.out.println("String table value " + k + " = " + sstrec.getString(k));
      }
      break;
      case LabelSSTRecord.sid:
      LabelSSTRecord lrec = (LabelSSTRecord) record;
      System.out.println("String cell found with value "
      + sstrec.getString(lrec.getSSTIndex()));
      break;

      case FormulaRecord.sid:
      FormulaRecord fre = (FormulaRecord) record;
      System.out.println("Formula: "+ fre.getValue());
      break;
      }
      }


      I don't know, how check, that incoming record is joined with macro and I don't know how handle it.

      Is there possible to create Excel file with macros using POI?

      Please help me...

      Margaret