Read Excel with macros using Java POI

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

I want to read the contents of an MS Excel file from
java, is it possible using JavaBeans-ActiveX bridge or
by any other java technologies, if possible, how ?Bridge2Java from IBM Alphaworks will do the trick for you.
You can get it from here:
http://www.alphaworks.ibm.com/aw.nsf/techs/bridge2java
Using it, you can do things like the following (taken and abbreviated from the samples provided with the package):
import Excel.*;
public class QuickExcel
    public static void main(java.lang.String[] args) {
        Application app;
        Workbooks wbs;
        Workbook wb;
        Worksheet sheet;
        Range rangeA1, rangeA2;
        try
            com.ibm.bridge2java.OleEnvironment.Initialize();
            app = new Application(); // Excel.Application !!! :-)
            app.set_Visible(true);
            wbs = app.get_Workbooks();
            wb = wbs.Add();
            sheet = new Worksheet(wb.get_ActiveSheet());
            rangeA1 = sheet.get_Range("A1");
            String out = new String("This is a test");
            rangeA1.set_Value(out);
            // Wait five seconds
            Thread.sleep(5000);
            // Close the workbook without saving
            wb.Close(new Boolean("false"));
            app.Quit();
        } catch (com.ibm.bridge2java.ComException e)
            System.out.println( "COM Exception:" );
            System.out.println( Long.toHexString((e.getHResult())) );
            System.out.println( e.getMessage() );
        } catch (Exception e)
            System.out.println("message: " + e.getMessage());
        } finally
            app = null;
            com.ibm.bridge2java.OleEnvironment.UnInitialize();
}

Similar Messages

  • Read Excel sheet contents using java/javabeans

    I want to read the contents of an MS Excel file from java, is it possible using JavaBeans-ActiveX bridge or by any other java technologies, if possible, how ?

    I want to read the contents of an MS Excel file from
    java, is it possible using JavaBeans-ActiveX bridge or
    by any other java technologies, if possible, how ?Bridge2Java from IBM Alphaworks will do the trick for you.
    You can get it from here:
    http://www.alphaworks.ibm.com/aw.nsf/techs/bridge2java
    Using it, you can do things like the following (taken and abbreviated from the samples provided with the package):
    import Excel.*;
    public class QuickExcel
        public static void main(java.lang.String[] args) {
            Application app;
            Workbooks wbs;
            Workbook wb;
            Worksheet sheet;
            Range rangeA1, rangeA2;
            try
                com.ibm.bridge2java.OleEnvironment.Initialize();
                app = new Application(); // Excel.Application !!! :-)
                app.set_Visible(true);
                wbs = app.get_Workbooks();
                wb = wbs.Add();
                sheet = new Worksheet(wb.get_ActiveSheet());
                rangeA1 = sheet.get_Range("A1");
                String out = new String("This is a test");
                rangeA1.set_Value(out);
                // Wait five seconds
                Thread.sleep(5000);
                // Close the workbook without saving
                wb.Close(new Boolean("false"));
                app.Quit();
            } catch (com.ibm.bridge2java.ComException e)
                System.out.println( "COM Exception:" );
                System.out.println( Long.toHexString((e.getHResult())) );
                System.out.println( e.getMessage() );
            } catch (Exception e)
                System.out.println("message: " + e.getMessage());
            } finally
                app = null;
                com.ibm.bridge2java.OleEnvironment.UnInitialize();
    }

  • Merge LiveCycle Form with XML using JAVA

    Hello.
    I am trying to find out how to merge non-interactive form with XML (using JAVA) so the users can see the final output form with the data filled in.
    What are my choices..?
    So far, I have created the interactive forms as template using LiveCycle 8 and wrote ASP.NET code to extract data and store it in SQL database when the user fill out and submit the form.
    It works great but another agency wants to access the form as well.
    They told us that they will create the XML themselves from the database, so they just need to combine the form with XML to display it (non-interactive form).
    They want to use JAVA but I am not sure how to do that...
    Any suggestion?

    Assuming that you start with XML in an org.w3c.dom.Document that stores the XML data. Before you can merge it into a form, you have to convert it to a com.adobe.idp.Document object. TO convert a org.w3c.dom.Document to a com.adobe.idp.Document object -- use the following Java code:
    private Document convertDataSource(org.w3c.dom.Document myDOM)
    byte[] mybytes = null;
    try
    //Create a Java Transformer object
    TransformerFactory transFact = TransformerFactory.newInstance();
    Transformer transForm = transFact.newTransformer();
    //Create a Java ByteArrayOutputStream object
    ByteArrayOutputStream myOutStream = new ByteArrayOutputStream();
    //Create a Java Source object
    javax.xml.transform.dom.DOMSource myInput = new DOMSource(myDOM);
    //Create a Java Result object
    javax.xml.transform.stream.StreamResult myOutput = new StreamResult(myOutStream);
    //Populate the Java ByteArrayOutputStream object
    transForm.transform(myInput,myOutput);
    // Get the size of the ByteArrayOutputStream buffer
    int myByteSize = myOutStream.size();
    //Allocate myByteSize to the byte array
    mybytes = new byte[myByteSize];
    //Copy the content to the byte array
    mybytes = myOutStream.toByteArray();
    catch (Exception e) {
    System.out.println("The following exception occurred: "+e.getMessage());
    //Create a com.adobe.idp.Document object and copy the
    //contents of the byte array
    Document myDocument = new Document(mybytes);
    return myDocument;
    THen you can merge myDocument into the Form using renderPDFFOrm:
    FormsResult formOut = formsClient.renderPDFForm(
    formName, //formQuery
    myDocument, //inDataDoc
    pdfFormRenderSpec, //PDFFormRenderSpec
    uriValues, //urlSpec
    fileAttachments //attachments
    Hope this helps!

  • How to include Logs/log4j in SOA with out using java embedding activity

    Hi,
    I have a requirement where I need to log the values of a particular variable and need to store it in a new log file. Is there any way to log the details with out using java embedding activity.
    Thanks,

    You can try this.
    http://veejai24.blogspot.co.uk/2008/04/simple-way-to-implement-log4j-in-your.html
    Thanks,
    Vijay

  • How to read a text file using Java

    Guys,
    Good day!
    Please help me how to read a text file using Java and create/convert that text file into XML.
    Thanks and God Bless.
    Regards,
    I-Talk

         public void fileRead(){
                 File aFile =new File("myFile.txt");
             BufferedReader input = null;
             try {
               input = new BufferedReader( new FileReader(aFile) );
               String line = null;
               while (( line = input.readLine()) != null){
             catch (FileNotFoundException ex) {
               ex.printStackTrace();
             catch (IOException ex){
               ex.printStackTrace();
         }This code is to read a text file. But there is no such thing that will convert your text file to xml file. You have to have a defined XML format. Then you can read your data from text files and insert them inside your xml text. Or you may like to read xml tags from text files and insert your own data. The file format of .txt and .xml is far too different.
    cheers
    Mohammed Jubaer Arif.

  • How to read azure storage data using JAVA with REST API

    Hi,
    We have a cloud service in our lab. We have enabled diagnostics
    in cloud services. So WADPerformanceCounterTable was created in storage account. Now , We want to read the WADPerformanceTable using
    JAVA with REST API. Is there any way to collect these details. please give me any
    sample code to connect azure storage using table service REST API.
    Thanks & Regards
    Rathidevi

    Hi,
    Please have a look at this article:
    https://convective.wordpress.com/2010/08/18/examples-of-the-windows-azure-storage-services-rest-api/, it demonstrate how to use table service Rest API, it also give us the code, hope this helps. Of course, the
    MSDN article could also help us coding.
    Best Regards,
    Jambor
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Password protected Excel file generation using Java

    Hi,
    I want to create password protected excel file using Java. So when you manually open this file it should prompt for password.
    There are APIs but they are licensed and are for trial period. I want solution which is free.
    I need this solution urgently..
    :-)

    Swati.S wrote:
    Hi Administrator,
    Moderator. Administrators post with the Sun logo.
    I'm sorry I wasnt aware that we cannot have off forum communication. Can you please communicate how I can spread this message taht solution for this is available.If you like, you can post the code here or on [SDN Share|http://sdnshare.sun.com/]. Apart from that, there's no shortage of blog sites.

  • Programmaticaly attachement with outlook using java

    Hi All,
    I used this code                   Runtime.getRuntime().exec(
                   new String[] {"rundll32", "url.dll,FileProtocolHandler",
                   "mailto:" + "&subject=" + "testmail" + "&attachment="+"\"" + "C:\\test.txt" + "\""}, null
    Once execute, it will open outlook express along with subject, but without attachment.
    I want to send the attachment programmatically using java..
    If anybody come across this issues, share your ideas...
    Edited by: SARAV_RS on Dec 28, 2008 11:09 PM

    First thing, it's not only for Outlook or windows. I need to check which email application is being using
    like outlook,Thunderbird,.
    The file is attached programmatic to the corresponding mail application. Those files are
    getting from server side (databases).
    In jsp,
    <a href="mailto:?subject=Pictures from PhotoAlbum&cc= &body=This is the body text&attachment="c:\test.txt'">Email</a><br>{code}
    mailto function works only in client side as of my knowledge. We can't use attachment.
    Give me any suggestions.
    Edited by: SARAV_RS on Dec 29, 2008 3:21 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Executing Microsoft access macros using java

    Hi Everyone,
    I hava an application in microsoft access,in which many macros which extract data are there.I want to know is there anyway that I can execute the macro written in microsoft access using java.
    Can anyone please answer the above.
    Regards,
    Rakesh.

    rakbha wrote:
    I hava an application in microsoft access,in which many macros which extract data are there.I want to know is there anyway that I can execute the macro written in microsoft access using java.
    I am rather certain that that is not possible via the ODBC driver and thus not possible via JDBC.
    There is certainly an OS API that will allow that but accessing those is not a standard part of the Java API so it would require a JNI solution (yours or someone else's) or an application that allows that access.

  • BPM 11g integration with UCM11g using Java Enbedded acitivity

    Hi Friends,
    Can anyone throw some idea how to integration with BPM11g and UCM11g
    We need to have a java code using Java Enbedded acitivity.
    1) How to Connect to UCM 11g using java code any sample Java Embedded Code( we are connecting through RIDC)
    2) How to Fetch the document from UCM using RIDC.
    3) How to Close the Connection.
    Hi friends,
    My requirement was Using BPEL JAva Embedded Acitivity need to connect UCM by RIDC. Got SCAC exception. I could solve this today 3/12/2012... refer below link
    Re: SCAC-50012 Got this exception when using BPEL Java Embedded Activity
    But I have the actual thing.. as per my post..
    Now I need to fetch the doc i.e.,
    In UCM we have pdf documents i need to Download that document and show it in ADF UI using Java Embedded Activity.
    Ie., Using Java Code I need to Download and Decode the PDF file using Java Embedded Activity after Connection with UCM. Save as a file in Local Machine then I need to Encode ads PDF and Show it to ADF UI.
    Please experts its Quite Urgent!!
    ThankQ!!
    Regards,
    Pavan
    Edited by: BPM Fresher on Dec 3, 2012 8:12 PM

    Hi experts...
    Any solution for this.. Can any one help me on this...
    Regards,
    Pavan

  • How to read HardDisk Serial number using java

    In my project the requirement is how to read the hard dish serial number using java library. Please do let me now if u get any help or any information regarding this issue. This is urgent for me

    In my project the requirement is how to read the hard
    dish serial number using java library. Please do let
    me now if u get any help or any information regarding
    this issue. This is urgent for meThat's a pretty goofy 'requirement' for a Java application, which is supposedly meant to do platform-independent things, to do something very platform-specific that it has no business doing in the first place.

  • Reading/writing PDF files using JAVA

    how to read/write a PDF file using java,
    while i read a pdf file using BUfferedReader class it gives a list of char. which is not readable.
    how to convert those files to readable format.?
    is there any special class for doin that.?
    plz explain..?

    is there any special class for doin that.?Yes, I'm sure Google knows a few libraries that ca do that.

  • Reading word doc contents using java

    hi
    can u tell me how to read the word doc contents using java and print it
    sameer

    HDF (Horrible Document Format)
    HDF is our port of the Microsoft Word 97 file format to pure Java. It supports read and write capability. Please see the HDF project page for more information. This component is in the early stages of design. Jump in!
    LOL :)

  • Generating reports in .doc format (Word Document) using Java POI - HWPF

    Hi
    Can anybody help me how to generate the report in .doc format using POI API?
    Please share the sample code, if you have.
    Thanks in Advance
    Dhilip

    Hi,
    I dont think that your requirement has to do with ADF capabilities.
    You want to edit a word document with JAVA. For that reason, you will need an API, as the suggestions above.
    You can do it without ADF and by using standard JAVA and the API of your choice. a static void main will do for that matter.
    ADF comes into the game when you want to handle the document with your ADF application.
    This means that you either want to get your new data to be placed on your doc from BC or any other DataControl or you want to do something else with ADF..
    My guess is that you want to get data from ADF into your Doc.
    You could create an API on handling your Doc and then use it into your ADF application.
    Regards,
    Dimitris.

  • Error with TaskSearchFilter using Java APIs in custom component

    I have created a custom Java component for use in LC Process Mgr.
    Upon invoke of process containing component, component fails with the following message:
    2011-02-28 16:28:31,260 ERROR [com.adobe.workflow.AWS] Cannot coerce object: [email protected]41 of type: com.adobe.idp.taskmanager.dsc.client.query.TaskSearchFilter to type: class com.adobe.idp.taskmanager.dsc.client.query.TaskSearchFilter
    Code is pretty basic:
            ServiceClientFactory myFactory = ServiceClientFactory.createInstance();
            TaskManagerQueryService queryManager = TaskManagerClientFactory.getQueryManager(myFactory);
            TaskSearchFilter filter = new TaskSearchFilter();
            filter.addCondition(TaskSearchingConstants.pSTATUS, Operator.EQUALS, "3");
            List<TaskRow> result = queryManager.taskSearch(filter);
    Error seems to occur with the creation of the List. This code works ok when run as standalone file in either Eclipse or Netbeans but not within the component.
    All necessary JARs are included and are listed in the class-path in component.xml.
    Does anyone have any ideas?
    Thanks,
    David

    Looks like a class loader issue.  Usually this is caused by having the a class (TaskSearchFilte) in your component that on the server.   In other words there are two copies of the TaskSearchFilte class - yours and the one already in LiveCycle - and they are in conflict.
    If that's the case, the solution is simple:
    remove the jar files containing the TaskSearchFilte (and any other LiveCycle clients) from your component's jar file.  You may need them in the build path, so your code can compile - but you don't need them in the final component jar.
    remove the references to these jar files from the component.xml file's class-path entry
    add an import-packages section to your component.xml file.  This will not reference the jar files, but the package names themselves.  For example:
    <import-packages>    
         <package version="1.0">com.adobe.idp.taskmanager.dsc.client.query.TaskSearchFilter</package>
         <!--  add more as needed -->
    </import-packages>

Maybe you are looking for

  • Error message the disk could not be written to or read from.

    Every time I try to synchronize my shuffle,I get the message that attempting to (I forget what it said exactly) failed, the disk could not be written to or read from. To synchronize it I have to reset the shuffle using the reset utility and then only

  • Confirmation Quantity issue while creating Sales order using BAPI

    Hi SDN, Can anyone of you help mein the below issue: I have a program to create a sales order using upload file. for this i use "BAPI_SALESORDER_CREATEFROMDAT2" & for changing existing "BAPI_SALESORDER_CHANGE". Now If the upload file contains the Sam

  • Itunes 7 quits at the end of each song.

    I just upgraded to itunes 7 from the last version. If I let a song play through, itunes will crash at the end of the song. It does not crash if I switch the songs myself. This problem did not occur with other versions of itunes

  • Boris Title 3D Can't adjust effect options

    Hi, I've been using Title 3D for titles in my project and it was working fine up until yesterday. Now when I try to adjust shadow size, opacity, etc it won't work. I highlight the text, and when I use the sliders nothing happens. Same with outline. I

  • Ant run right on eclipse but on prompt dosen't run

    Hi All I need run this build.xml on prompt. I have this build.xml on eclipse compiling right, but if i run on promp it dosen't run. I'm executing so: ant, where the build.xml is. Following the build.xml. <project name="HelloWorld" >     <property nam