Example using low level API POI for generating Excel??

Hi
is anyone know good URL that teaches generating Excel using low level API using Apache POI?
The reason is because i want to set the password for either workbook/sheet in high level API but it cant be done.
the only thing can be done using High level API is protect sheet without password.
Any idea?
Thanks

There is quite a good pack of documentation that ships with HSSF. To answer your question, I have just gone to the how to page and copied the example below, hope it helps.
short rownum;
// create a new file
FileOutputStream out = new FileOutputStream("workbook.xls");
// create a new workbook
HSSFWorkbook wb = new HSSFWorkbook();
// create a new sheet
HSSFSheet s = wb.createSheet();
// declare a row object reference
HSSFRow r = null;
// declare a cell object reference
HSSFCell c = null;
// create 3 cell styles
HSSFCellStyle cs = wb.createCellStyle();
HSSFCellStyle cs2 = wb.createCellStyle();
HSSFCellStyle cs3 = wb.createCellStyle();
HSSFDataFormat df = wb.createDataFormat();
// create 2 fonts objects
HSSFFont f = wb.createFont();
HSSFFont f2 = wb.createFont();
//set font 1 to 12 point type
f.setFontHeightInPoints((short) 12);
//make it blue
f.setColor( (short)0xc );
// make it bold
//arial is the default font
f.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
//set font 2 to 10 point type
f2.setFontHeightInPoints((short) 10);
//make it red
f2.setColor( (short)HSSFFont.COLOR_RED );
//make it bold
f2.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
f2.setStrikeout( true );
//set cell stlye
cs.setFont(f);
//set the cell format
cs.setDataFormat(df.getFormat("#,##0.0"));
//set a thin border
cs2.setBorderBottom(cs2.BORDER_THIN);
//fill w fg fill color
cs2.setFillPattern((short) HSSFCellStyle.SOLID_FOREGROUND);
//set the cell format to text see HSSFDataFormat for a full list
cs2.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
// set the font
cs2.setFont(f2);
// set the sheet name in Unicode
wb.setSheetName(0, "\u0422\u0435\u0441\u0442\u043E\u0432\u0430\u044F " +
                   "\u0421\u0442\u0440\u0430\u043D\u0438\u0447\u043A\u0430",
                HSSFWorkbook.ENCODING_UTF_16 );
// in case of compressed Unicode
// wb.setSheetName(0, "HSSF Test", HSSFWorkbook.ENCODING_COMPRESSED_UNICODE );
// create a sheet with 30 rows (0-29)
for (rownum = (short) 0; rownum < 30; rownum++)
    // create a row
    r = s.createRow(rownum);
    // on every other row
    if ((rownum % 2) == 0)
        // make the row height bigger  (in twips - 1/20 of a point)
        r.setHeight((short) 0x249);
    //r.setRowNum(( short ) rownum);
    // create 10 cells (0-9) (the += 2 becomes apparent later
    for (short cellnum = (short) 0; cellnum < 10; cellnum += 2)
        // create a numeric cell
        c = r.createCell(cellnum);
        // do some goofy math to demonstrate decimals
        c.setCellValue(rownum * 10000 + cellnum
                + (((double) rownum / 1000)
                + ((double) cellnum / 10000)));
        String cellValue;
        // create a string cell (see why += 2 in the
        c = r.createCell((short) (cellnum + 1));
        // on every other row
        if ((rownum % 2) == 0)
            // set this cell to the first cell style we defined
            c.setCellStyle(cs);
            // set the cell's string value to "Test"
            c.setEncoding( HSSFCell.ENCODING_COMPRESSED_UNICODE );
            c.setCellValue( "Test" );
        else
            c.setCellStyle(cs2);
            // set the cell's string value to "\u0422\u0435\u0441\u0442"
            c.setEncoding( HSSFCell.ENCODING_UTF_16 );
            c.setCellValue( "\u0422\u0435\u0441\u0442" );
        // make this column a bit wider
        s.setColumnWidth((short) (cellnum + 1), (short) ((50 * 8) / ((double) 1 / 20)));
//draw a thick black border on the row at the bottom using BLANKS
// advance 2 rows
rownum++;
rownum++;
r = s.createRow(rownum);
// define the third style to be the default
// except with a thick black border at the bottom
cs3.setBorderBottom(cs3.BORDER_THICK);
//create 50 cells
for (short cellnum = (short) 0; cellnum < 50; cellnum++)
    //create a blank type cell (no value)
    c = r.createCell(cellnum);
    // set it to the thick black border style
    c.setCellStyle(cs3);
//end draw thick black border
// demonstrate adding/naming and deleting a sheet
// create a sheet, set its title then delete it
s = wb.createSheet();
wb.setSheetName(1, "DeletedSheet");
wb.removeSheetAt(1);
//end deleted sheet
// write the workbook to the output stream
// close our file (don't blow out our file handles
wb.write(out);
out.close();

Similar Messages

  • HIgh Level API's Vs Low Level API's

    Hi,
    Is it advisable to use High Level API's or Low Level API's for developing a Mobile Application?
    What will be the advantages/disadvantages of using High Level API's over Low Level API's or vice versa?
    Kindly advise.

    Is it advisable to use High Level API's or Low Level API's for developing a Mobile Application?What have you used so far?
    What will be the advantages/disadvantages of using High Level API's over Low Level API's or vice versa?What are your own thoughts on this?
    {color:#0000ff}http://catb.org/~esr/faqs/smart-questions.html{color}
    db

  • Can I use textfield in an application with low level api?

    Hello !
    I am developing a mobile application using the low level api.
    I have to use it, because I do a lot of coloring.
    But I want to use high level textfields as well. Is there any way
    to include them in my application without using forms?
    Does any one know, why J2ME designer's have limited the access
    to the TextField's paint()-method? That's why I cannot inherit
    from TextField and overwrite the paint() as I would like to do.
    Thanks.

    Unfortunately no. You cannot mix both high and low level on the same screen. You'll probably have to draw it out yourself and capture user input, unless you're willing to use textboxes.
    Or.. i suppose you can try using customItems for all your "coloring" instead?

  • Can we use EDID4 instead of EDIDD for generating IDOC

    Hi Abap-Experts,
                           My question is can we use EDID4 instead of EDIDD for generating IDOC. I have declared internal table for idoc data using EDIDD...but can i use instead EDID4 for the same as well as in FM('MASTER_IDOC_DISTRIBUTE'). I have tried to use but it was giving me runtime error
       DATA : ls_edidd  TYPE edidd .
      DATA : it_edidd TYPE TABLE OF edidd .
    LOOP AT it_cust INTO wa_cust .
        lv_segnum = lv_segnum + 1 .
        ls_edidd-segnum = lv_segnum .
        ls_edidd-segnam = 'Z1ZZ_CUST' .
        ls_edidd-hlevel = '1' .
        ls_edidd-sdata = wa_cust .
    CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
        EXPORTING
          master_idoc_control                  = ls_edidc
      OBJ_TYPE                             = ''
      CHNUM                                = ''
        TABLES
          communication_idoc_control           = it_edidc
          master_idoc_data                     = it_edidd
    Thanks in advance,

    Hi Alexander,
             I am not getting any error when i try EDIDD for generating IDOC..but if i try EDID4........it does give me error message.
               so please tell me what is the solution for this.

  • Using High-Level API, need to use KeyRelease just for Lists

    I'm coding a MIDlet with High-Level API, but I found that is really annoying to press down 30 times in a long List to reach the item you want to select. So I thought "what about pressing right/left and make it working like pressing down/up like 10 times"?
    Something like this:
    Canvas canvas = new Canvas() {
             public void paint(Graphics g) { }
             protected void keyPressed(int keyCode) {
                switch(keyCode) {
                    case -3:mylist.setSelectedIndex(mylist.getSelectedIndex()-10,true);break;
                    case -4:mylist.setSelectedIndex(mylist.getSelectedIndex()+10,true);
          }; // end of anonymous class*/But I have no idea about how to implement this =(

    first of all, is there any particular reason you want to stick to the high-level API?
    Well, I have already nearly 700 lines of code. I don't want to start from 0 :P
    I think the best way to implement this would be to use customItems so you can control the view of the list.
    I think that requires MIDP2.0 I'm trying to make it work in MIDP 1.0
    The best you could do with high level UI is add navigation Commands to the List.
    I have already 2 Commands per List. Not all phones have a button in the center of "cursors", so I use right button for select and left for back/exit.
    Thanks for replies anyway

  • Placing a Low Level DB Function for Time Offset

    Would any one be able to point me to any documentation on the Oracle 10g R2 release that might help me understand if there is a way to modify datetime query parameters and datetime query results at a low level in the DB? R12 of Oracle Apps does not handle global implementations very well when it comes to running 24/7 with sites around the globe and handling data stored with a time element. Everything is stored using the single server time zone. So I thought perhaps there might be a way to modify the DB at a low level to perform the offset of the value for any datetime parameter to correspond to the proper server time zone to pull data and then to also offset the queried datetime values to the users, via a session value, time zone. So I am thinking long shot but perhaps there is a way to insert a function call to a function built in C and linked in to the DB somehow or the DB listener or the DB connection driver software. I don't know. I am familiar with OCI and SQLCA but don't believe these offer this type of interjection with the DB I am looking for. Of course, if there is a simple solution I am all for that.
    Thanks,
    Jason

    Adjusting the timezone at the session level doesn't do what I need it to do. At least based upon the tests I have done. And my research into changing the session DB time zone only applies to the new timestamp data types and not to the date data type.
    However, if you think that changing the DB session time zone setting would help do what I have stated please tell me.
    Thanks,
    Jason

  • Merge API stub for 'Generate Table API...'?

    Hi,
    Has there been a request for a stub in the menu option 'Generate Table API...' that creates a merge procedure? If it generated the MERGE command for a given table that would be great and even better than trying to call the UPD procedure, trap the does not exist error and then call the INS procedure.
    The key to making this work is by passing the parameters for the actual match to the MERGE statement via the DUAL table in the source definition of USING clause. By doing this via the primary key of the table drives the cost for this procedure to unique scan via the PK which is 1 (one) logical I/O for the lookup and the decision to do an insert or update. The overall cost should be around 4.
    Thanks,
    ScottK
    The general pattern could be:
    PROCEDURE mrg (
    p_pk_col_1 IN table_name.pk_col1%type
    ,p_pk_col_n IN table_name.pk_coln%type
    ,p_non_pk_col1 IN table_name.non_pk_col1%type
    ,p_non_pk_coln IN table_name.non_pk_coln%type
    ) IS
    BEGIN
    MERGE INTO table_name target
    USING (SELECT
    p_pk_col1 alias_pk_col1
    ,p_pk_coln alias_pk_coln
    FROM dual) source
    ON ( source.alias_pk_col1 = target.pk_col1
    and source.alias_pk_coln = target.pk_coln)
    WHEN MATCHED THEN UPDATE
    SET target.non_pk_col1 = p_non_pk_col1
    ,target.non_pk_coln = p_non_pk_coln
    WHEN NOT MATCHED THEN INSERT
    column list
    VALUES
    parameter list
    END;
    Edited by: ScottK on Aug 11, 2011 3:17 PM
    Edited by: ScottK on Aug 11, 2011 3:48 PM
    Edited by: ScottK on Aug 11, 2011 3:49 PM

    You can always request this at the SQL Developer Exchange, so other users can vote and add weight for possible future implementation.
    Regards,
    K.

  • Problem Using JSQL level 4 driver for SQL Server 2000

    I am having problem , connecting to my Sql Server 2000 ( deployed on Windows 2000 Professional) using Microsoft JSQL level 4 Deriver .
    I am doing it with following code,
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
         Connection conn = DriverManager.getConnection
    ("jdbc:microsoft:sqlserver://192.168.0.232:1433;databaseName=DBNew;user=nakhter;Password=java;");
    It gives me following Exception ,
    java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Login failed for user 'nakhter'. Reason: Not associated with a trusted SQL Server connection.
         at com.microsoft.jdbc.base.BaseExceptions.createException Unknown Source)
         at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
         at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
         at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
         at com.microsoft.jdbc.sqlserver.tds.TDSLoginRequest.processReplyToken(Unknown Source)
         at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
         at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
         at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
         at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
         at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
         at java.sql.DriverManager.getConnection(DriverManager.java:517)
         at java.sql.DriverManager.getConnection(DriverManager.java:177)
    I am usign my windows authentication usrname and password .
    I has tried it with user "sa" but still same exception .
    Could someone help me in this regard ?

    You need to switch SQL server to just use SQL Server authentication or both. The problem is that it is looking for a Windows NT account for nakhter with the password java. We get this all the time on new SQL Server installs if you just take the defaults.

  • In IE I used different levels of folders for my favourites. After importing I miss the bookmarks of folders within folders within folders etc.

    In Internet Explorer it is possible to organize favourites with folders as in firefox. In these folders you can make new folders and within those new folders. Can this tree structure be used in Firefox? After importing most of my favourites are gone, I can find no folders within folders within folders etc. So most of my favourites are not imported from IE.

    Thanks for the helpful thoughts LarryHN. I'm having a Mac guy look at my MacBook Pro in the next day or so to see what he can find out. I described the issue on the phone... and like you, he said that saving my documents to a thumb drive shouldn't affect my iPhoto library.
    One reason I bought the thumb drive was to back up my iPhoto library, but the time I got to that, it was already gone. I've thought of getting Time Machine (and have checked out other systems), but the reviews are so mixed, I'm dragging my feet on coughing up the cash right now.
    When I launch iPhoto, I only see the last few weeks' worth of photos. Oddly, photos I imported 3 weeks ago appear, but are in a folder dated November 2012--when I know I took those and imported them in January 2013. So that's weird...
    When I got to iPhoto Library, I have an Auto Import folder with nothing in it. "My Pictures" folder has nothing as well. I did hold down the option key while opening up iPhoto, but only my recent library (a few weeks' worth of photos) appears. I'm using iPhoto 2011 (6.2.3). I can only hope my Mac guy can help...

  • Set component property using top level api

    Hi I have a requirement to change the property of a component.
       I can use javax.jcr.node  and use setProperty method.But I want to have the same functionality using sling or wcm api.

    Hi Sham ,
         See I want to change the sling:resourceType of the components that are present in pages .So generally we will do
         Node snode= we will convert (/content/www/en/jcr:content/component) to node
      then  If (snode.hasProperty("sling:resourceType){
                    snode.setProperty("sling:resourceType","XXXXX");
    We will do as mentioned above.
       Now I dont want to do this using JCR api (here javax.jcr.node) . I want to have the same functionality using wcm or sling API.

  • Generic way of handling SoftKeys in Canvas (low level API)

    Folks, is there a way to handle SOFTKEY presses in J2ME. I am aware of how Nokia does it, but, given a Canvas, is it possible to write a cross-device-protable code which can detect which SOFTKEY has been pressed

    hello, i have had similar issues when trying to find a portable solution to using softkeys with the canvas. In the end i decided that the cross-phone support was not possible for the left and right softkeys(nokia left softkey = 6, moto left soft key =21?? or something like that?), however i did find that the fire and arrow keys are mapped the same for almost all phones and brands, instead of using the softkeys, i click once to display a pop-up menu, where the user can move up or down then select again with the fire button.. seems to work pretty well. so no softkeys?.../freddie

  • Using DDE with Oracle Forms for uploading Excel data

    Hi There,
    I have used DDE in Forms to upload data from Excel.
    The code which I have implemented is as follows:
    DECLARE
    iApplication pls_integer;
    iConv pls_integer;
    v2Buffer varchar2(100);
    v2text varchar2(100);
    nLength number;
    nTransactionId number;
    /* these varrays are defined in a package specification*/
    vExcelProduct p_upload_functions.prd_no:=p_upload_functions.prd_no('1');
    vExcelVpc p_upload_functions.vpc:=p_upload_functions.vpc('1');
    BEGIN
    /*Open an DDE Server application*/
    iApplication:= DDE.App_Begin('C:/excel.exe ‘||v2fileName,DDE.App_Mode_Minimized);
    iConv:=DDE.Initiate('EXCEL',v2filename);
    BEGIN
    /* first row of the sheet used for title . So loop is started from 2*/
    /* Reading a row*/
    FOR I IN 2..10000
    LOOP
    /* Reading columns of a particular row*/
         FOR J IN 1..n / * n be the number of columns in excel sheet */
         LOOP
    /* generate the cell no of excel sheet from where data will
    be fetched- R is used for row no and C is foe column no*/
         v2text:='R'||I||'C'||J||':'||'R'||I||'C'||J;
    /* Store the value in variable */
    dde.request(iConv,v2text,v2Buffer,dde.cf_text,1000);
    /*Stores values in the varrays for a row*/
    IF j=1 THEN
    /* for first column*/
    nLength:=length(v2Buffer);
    vExcelOrg(I-1):=To_Number(substr(v2Buffer,1,nLength-2));
         /* for second column */
    ELSIF j=2 THEN
    nLength:=length(v2Buffer);
    vExcelProduct(I-1):=substr(v2Buffer,1,nLength-2);
    END IF;
    END LOOP;
    /*Exit the loop when it encounters an empty row*/
    IF vExcelProduct(I-1) IS NULL AND vExcelOrg(I-1) IS NULL THEN
    EXIT;
    END IF;
    /* Otherwise extending the varray*/
    vExcelProduct.extend;
    vExcelOrg.extend;
    /* Reading the next row*/
    END LOOP;
    /* Now close the DDE application */
    DDE.app_end(iApplication);
    DDE.terminate(iConv);
    EXCEPTION
         WHEN Others THEN
         DDE.app_end(iApplication);
    DDE.terminate(iConv);
    RAISE Form_Trigger_Failure;
    END;
    I am facing a problem, I will appreciate if you can give some insights to help.
    We have been having problem logging in to application when there are a number of EXCEL processes running (17-18) on the server. Users that have already logged in have no problem, but new login will get "FRM-92101 There was a failure in the Forms Server during startup". The Forms Server itself is running fine. After we killed a few EXCEL processes, new users will be able to login.
    Thanks and regards,
    Mandeep

    this is a trial method and right now i am trying to read only the first cell of the excel sheet and return that value and show it in the UI when the user presses the button but this code is not returning any value.
    METHOD read_excel.
      INCLUDE ole2incl.
      DATA: filename(128) TYPE c,
                excel TYPE ole2_object,
                cell TYPE ole2_object,
                workbook TYPE ole2_object,
               pfile TYPE localfile VALUE
               'C:\Documents and Settings\I047323\Desktop\new.xls',
                name TYPE string.
      CREATE OBJECT excel 'EXCEL.APPLICATION'.
      SET PROPERTY OF excel 'VISIBLE' = 0.
      CALL METHOD OF excel 'WORKBOOKS' = workbook.
      CALL METHOD OF workbook 'OPEN'
        EXPORTING  #1       = pfile.
        CALL METHOD OF excel  'CELLS' = cell
          EXPORTING
            #1      = 1
            #2      = 1
        GET PROPERTY OF cell 'VALUE' = value.
      CALL METHOD OF workbook 'SAVE'.
      CALL METHOD OF workbook 'CLOSE'.
      CALL METHOD OF excel 'QUIT'.
      FREE OBJECT excel.
    ENDMETHOD.
    Edited by: neelima v on Jan 14, 2008 4:06 PM

  • Low-Level or High-Level for GUI ?

    I am developing a MIDLet that has to run CLDC-1.1 MIDP-2.0 Devices. The MIDLet has a simple user interface, and there is no gaming. I developed the MIDLet using the high-level GUI class, but I discovered that this class is nice, yet limited. Now I am investigating using the low level canvas class for the GUI. Is it possible to maintain cross-platform compatibility with the canvas, or should I stick with the high-level class?

    High Level Group
    Classes provided are
         Perfect for development of MIDlets that target the maximum number of devices
         Heavily abstracted to provide minimal control over their look and feel
         Classes do not provide exact control over their display
    Low Level Group
    Classes provided are
         Perfect for MIDlets where we want precise control over the location and display of the UI elements
         If more control there is comes less portability It may not be deployable on certain devices
    Cheers,
    Rohan Chandane

  • Low level network info

    I'm coding a cellular phone program. It needs low level network info, idealy it would be a CellID that it is connected to.
    The main problem is to know if two phones ar in the same area without using location ('cos it is a relatively new api and here in argentina time will past until location phones are here ).
    The simplest thing i imagine is to know the cellid where the phone is connected and match in a server what phones are in the same cellid. I was looking for a low level api or something to use AT commands in the phone but i can't find nothing.
    If you know any way to acces that info or the AT commands please respond.
    If you know other way to know if two phones are in the same area, please let my know.
    When i say "same area", i mean like 20-30 milles (50km) from each other, more or less, it dont need to be accurate.
    Thanks in advance
    Losky

    This seems to be a bug. When a transformation (to 3785, 3857) is involved it seems to query the whole table to build up the cache.  Will investigate further to see if caching=none makes a difference.

  • Updation of higher level item text to lower level item text

    Hi All,
    while creating sales order VA01   i need to pass the value of higher level item text to lower level item text
    for that i read the text of the higher level item text using the fm read_text
    and pass the text to the lower level items using save_text and commit_text
    this coding works only when the lower order item  text is empty
    my queries are
    1. if the lower level item having some text that text will be replaced by the higher level item text, that is happening but showing error that I/O error , how to solve this
    2. while gone to VA02 and add one more item then also same error is happening how to solve this please help me.
    regards
    krishna

    got the solution

Maybe you are looking for

  • X505-870 overheating

    My x505-870 has a cooling problem with no cooling system warnings. 12days after I got the laptop I noticed the system would start slowing down after playing games or watching movies, then discoloration from heat on the left side of the monitor since

  • How to use 'delivery text' in VOFA?

    I have selected the field 'delivery text' in VOFA. what should do next?

  • How could I Write data into a field in Oracle whose data type is VARCHAR2

    The target data I want to write into Oracle is in http://tw.yahoo.com/info/utos.html. Now, these data is stored in Mysql database and the field which stores these data uses "Text" as its data type. I want to derive these data from mysql database and

  • Gnome 3.12 cannot launch gnome-terminal with sudo

    I am suffering from a problem that seems similar to the thread https://bbs.archlinux.org/viewtopic.php?id=180103 and https://bbs.archlinux.org/viewtopic.php?pid=1402702 but since they are marked solved I am opening my own. My real problem is I use th

  • My ipod refuses to sync or download any music.

         This has been going on for about 4 months now and I am getting really frustrated. I have clicked and unclicked every box in the itunes to ipod sync tab (from the "manually manage" box to the "Sync music" tab). When I try to download songs to my