Working with Big Excel Sheet

Hello All,
I have a large excel sheet having 50K rows and I am constrained to not use more than 250 MB of Heap space.
Using Apache poi API the creating new WorkBook Object itself gives MemoryOutOfSpace Error
Workbook source = WorkbookFactory.create(new FileInputStream(Path));
Please suggest some solution/work around. I am open to use some other API as well but preference lies for Apache poi.
Thanks In Anticipation
Shivam

This is the sample code that I am running, I am only creating an Workbook object and then traversing the excel. I am getting the java.lang.OutOfMemoryError: Java heap space error
package excel;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
public class BigFile {
     private static String DATE_FORMAT = "yyyy_MM_dd_HH_mm_ss";
     public static String calcTimeStamp()
          Date date = new Date();
          SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
          return format.format(date.getTime());
     public static void main(String args[])
          String Path = "C:\\EXCEL\\Large.xls";
          long t = System.currentTimeMillis();
          try {
               Workbook source = WorkbookFactory.create(new FileInputStream(Path));
               Sheet sheet = source.getSheetAt(0);
               for (Row row : sheet)
                    for (Cell cell : row)
          }catch (FileNotFoundException e) {
               e.printStackTrace();
          } catch (IOException e) {
               e.printStackTrace();
          }catch (Exception e)
               e.printStackTrace();
          }finally {
               System.out.println("Total Time Taken "
                         + (System.currentTimeMillis() - t)/1000 + " seconds");
               System.out.println("End Time :" + calcTimeStamp()+" in "+System.getProperty("user.timezone")+" timezone");
Here is the Stack Trace
Total Time Taken 10 seconds
End Time :2011_03_31_09_40_26 in Asia/Calcutta timezone
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
     at java.util.Arrays.copyOf(Unknown Source)
     at java.util.Arrays.copyOf(Unknown Source)
     at java.util.ArrayList.ensureCapacity(Unknown Source)
     at java.util.ArrayList.add(Unknown Source)
     at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:443)
     at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:263)
     at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:188)
     at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:305)
     at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:286)
     at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:60)
     at excel.BigFile.main(BigFile.java:33)

Similar Messages

  • Problem of crashing in Ill. CS5 when working with big files.....

    Hello, I'm working as a cartographer at Port of Rotterdam and frequently work with big maps in Illustrator CS5. As soon as the filesize exceeds 150 MB, and especially when small rasterfiles (mostly jpg's) are placed inside the document, either embedded or not-embedded, me and my collegue get notifications indicating "Can't show preview"or worse: The operation can't be concluded due to lack of RAM (dutch translation). This being a last warningsign just before CS5 collapses and it thus becomes impossible to make any Save on the document.... The hardware we work with: Quad Core 3GHz;NVidia Quadro 1GB;Windows XP with SP3, DirectX9; 8GB int. memory. We hope to find out the reasons of the frequent collapses and if you know of any possible solutions. On behalf of many of my collegues, thank you in advance for replying, greetings, Fred van Eck

    There can be other causes for instance if your scratch disk is fragmented and if your scratch disk has gotten overloaded with actual files storage.
    Or if the permissions for the scrtch has been changed for some reason.
    The scratch need a lot of free contigious free space to work well with large files.
    Even with CS 6 you can have a problem if your scratch is not healthy.
    Do you have a dedicated drive or partition of one as a primary scratch, does the scratch have a fast enough buffer (cache)? Current drives run 32 MB and 64 MB cache.
    Is the file stored on a fast disk?
    If you work on large files consider storing them on a RAID 0 for while working on them and storing the final some where else.
    CS 6 should be helpful but you need lots for RAM I would not run a system and work on large files with 8GB of memeory 16GB should be your minimum.
    If you are working in a professional envoronment then you really need a professional set up and make your life easier and save money in the time you save.
    It is expensive to set up but wotth it in the end.

  • Working with big files

    I would appreciate any suggestion as to how best one can work with big files.  I have eight one hour tapes containing information about various places I visited.  Some contain only one place while others can contain two or more places. As a preference I like to create up to one hour DVDs that contain an identifiable segment; eg either one place only or more but I do try not to break up a place and record it on two DVDs.  However, the problem I faced in the past, is that by the time I get to the end of an hour, the program Premiere Elements 7 (PE7) is getting slow and keeps telling me that it is running out of memory. That is despite the fact that I have 3 GM of RAM and over 200 GB of dedicated separate hard drive.  I tried saving segments under ‘Share’, ‘DV AVI’ and selecting ‘DV PAL Standard’ (the system I use), but the result, as far as quality was concerned, was very disappointing. There is no option to change or set quality as was the case in previous versions of PE.  Nor can I combine two .prel files into one while I am editing. 
    Is there any other way I can work in segments, say 15 minutes, and combine them at the end without losing on the quality? 
    Any suggestion would be most appreciated.
    Tom 

    Hi Steve
    It is a Sony DCR-HC40E PAL, and they were captured as AVI clips.
    The project settings are:
    General – not highlighted but it shows DV Pal and 25.00 frame/second
    Video – 720 horizontal 576vertical (4/3)
    Display format - 25 fps Timecode
    Capture – DV Capture
    Tom

  • Advice needed: The way to solve out of memory problem (or the way to work with big csv files)

    Hello:)
    I'm in trouble: I have a big csv file (over 5gb of web-analytics data) and my 64 bit excel (and 6gb ram)
    I cant load file to data model because of it's size. There is an error "out of memory" in power query. 
    This is the first time when I encountered such a problem.
    What options do I have to work with such a file? To increase memory in my computer? Would it solve the problem? How much do I need to work with 6gb csv? 
    Or may be I can upload my data somewhere to azure and work with it there? 
    So the problem - is there any way to deal with big files using power query? Or I need to become a developer and learn sql or other languages? 
    Thanks in advance.
    Max

    Hi Miguel!
    Thanks for your answer. 
    I've tried to load this file on virtual pc from azure cloud with this config:
    I have increased memory limit in power query settings:
    And still, the proble is the same:
    What I do wrong? 

  • To send an email with attachment excel sheet

    Hi Friends,
    I am struk up at to send an eamil with Excel sheet.
    I used FM SO_DOCUMENT_SEND_API1.
    but is is sending an email but with out data
    how to work this senario kindly help me please.
    Thanks and Regards,
    Bhavani.

    Hi,
    https://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=61243822
    Thanks,
    Krishna...

  • Problem in Sending mail with attachment (Excel sheet)

    Hi
    Iam using this FM   SO_NEW_DOCUMENT_ATT_SEND_API1  for sending mail with an attachment (excel sheet).
    the application is running fine , mail is going to other system .   but the excel sheet attachment contain only few rows  not all.
    and the body of the mail is not displaying . 
    Can any one help me. Thanks in advance.

    Hi,
    you can use cl_bcs classes for the same. I am using below code for same thng
      CONSTANTS:c_tab  TYPE c VALUE cl_bcs_convert=>gc_tab.
      CONSTANTS:c_crlf TYPE c VALUE cl_bcs_convert=>gc_crlf.
      DATA o_send_request   TYPE REF TO cl_bcs.
      DATA o_document       TYPE REF TO cl_document_bcs.
      DATA o_recipient      TYPE REF TO if_recipient_bcs.
      DATA o_bcs_exception  TYPE REF TO cx_bcs.
      TRY.
        o_document = cl_document_bcs=>create_document(
          i_type    = 'RAW'
          i_text    = is_mail_text
          i_subject = text-005 ).
      ENDTRY.
    *create file header
    CONCATENATE
                    text-h00 c_tab text-h01 c_tab text-h02 c_tab text-h03 c_tab text-h04 c_tab
                    text-h52 c_tab text-h05 c_tab text-h06 c_tab text-h07 c_tab text-h08 c_tab text-h09 c_tab
                   c_crlf INTO w_data_string.
    Loop at itab which contains data to be send as attachment
    concatenate field1 field2 field3 c_crlf into your_string separated by  c_tab
    conatenate final string your_string into final_string.
    endloop.
    *Convert data into suitable excel format
      TRY.
          CALL METHOD cl_bcs_convert=>string_to_solix
            EXPORTING
              iv_string   = w_data_string
              iv_codepage = '4103'
              iv_add_bom  = 'X'
            IMPORTING
              et_solix    = w_binary_content.
        CATCH cx_bcs INTO o_bcs_exception.
          IF o_bcs_exception IS NOT INITIAL.
            w_exec_txt = o_bcs_exception->get_text( ).
            MESSAGE w_exec_txt TYPE 'S'.
          ENDIF.
      ENDTRY.
        add the spread sheet as attachment to document object
      CONCATENATE text-006 sy-datum INTO w_attach_name SEPARATED BY space.
      o_document->add_attachment(
        i_attachment_type    = 'xls'
        i_attachment_subject = w_attach_name
        i_att_content_hex    = w_binary_content ).
    *create persistent send request
      o_send_request = cl_bcs=>create_persistent( ).
        add document object to send request
      o_send_request->set_document( o_document ).
        create recipient object for external mail id
      w_mlrec = iw_recipent.
      TRY.
          o_recipient = cl_distributionlist_bcs=>getu_persistent(
              i_dliname = w_mlrec
              i_private = space ).
        CATCH cx_bcs INTO o_bcs_exception.
          IF o_bcs_exception IS NOT INITIAL.
            w_exec_txt = o_bcs_exception->get_text( ).
            MESSAGE w_exec_txt TYPE 'S'.
          ENDIF.
      ENDTRY.
        add recipient object to send request
      o_send_request->add_recipient( o_recipient ).
        ---------- send document ---------------------------------------
      w_sent_to_all = o_send_request->send( i_with_error_screen = 'X' ).
      IF w_sent_to_all EQ abap_true.
        COMMIT WORK.
      ENDIF.

  • Why did Firefox intervened to move data while working with an Excel file; cannot locate the data.

    Downloaded Firefox 2wks ago. Just now working with a large Excel spreadsheet when something happened losing all 6 sheets of data. My file location now shows sheet data as Firefox Document. Now I can't retrieve this file of data; it was financial data! What happened for Firefox to intervene?

    No, Sir. I was strictly working within a newly created Excel file. Actually, Internet Explorer is current browser.
    Thank you for interest and any suggestion.
    Re-thinking thru this, it is probable I downloaded the base data thru FIREFOX. I was working with the project on an Excel spread sheet when I lost the data. The sheets still exist but the data is missing. Very strange.

  • My Labview Report generator is not working with 2013 excel version

    Hi All,
    My report generator tool kit which was developpend using labview 2011 was workign with excel 2010...after that i installed 2013 excel and the code is not working..
    Do i need to enable some setting to work with excel 2013.
    Basically this generator tool will copy the charts from excel and paste in power point...Please let me know.
    Thanks,
    Hareesh

    Ah, I understand now - I had assumed you were using the NI Toolkit.
    If you're not using the report generation toolkit, did you write your own VIs for communicating with Office or are you using a different toolkit? If you're using ActiveX to communicate with Office it may be that the ActiveX API has changed for Office 2013 - you will probably need to modify your program for the new calls.
    Since it wasn't as obvious as I thought with the report generation toolkit, it would help if you posted some code to try and understand what might be happening. Are you getting any errors in your application when you try to use Office 2013?
    Certified LabVIEW Architect, Certified TestStand Developer
    NI Days (and A&DF): 2010, 2011, 2013, 2014
    NI Week: 2012, 2014
    Knowledgeable in all things Giant Tetris and WebSockets

  • Acrobat X - Word with linked Excel-Sheets is blank

    Hello Acrobats,
    the following problem occurs using MS Office 2007 on Win XP with Acrobat X PDF-Maker:
    A MS Word document has a linked Excel-Sheet inserted.
    The PDF maker is used to create a PDF with no tags or PDF/A specification.
    With Acrobat 9 no problems occured.
    Now, with Acrobat X the following happens: The part, where the Excel sheet is positioned, only a black frame is shown with a "play"-button (as shown below).
    Does anybody know how to avoid this problem?
    Thanks in advance
    mannikaltz

    Hi ,
    This is a known issue and this will be fixed soon in the next sub-release of Acrobat X . Till then ,as a workaround , you can copy paste the contents of the 'linked' file to your word file ,instead of linking the file , this will produce an equivalent PDF .
    Thanks for your feedback .
    Thanks,
    Apoorv

  • Problem with Protected Excel sheets through OLE

    Hi Friends
    We are facing the problem with the protected sheets in excel, when we are accessing worksheets via SAP.
    We can insert the values in the protected sheet and we can do other manupalations, but when we are trying to do the autofit for the protected sheet via SAP, then its throwing an error while making it as Visible in SAP ECC 6.0.
    Though it is valid, because even when we do in the excel itself, it wont allow the user to shrink the columns, but this one is possible in ECC 5.0  and we can make excel is visible on the screen.
    I would like to know is this SAP Version problem or anything else apart from this? and I would like to know is there anyway to unprotect and protect the sheet through ABAP program with out a password. Now my clients wants the autofit though its protected.
    Please give me any suggestions.
    Thanks
    Praveen

    its bug with ECC 5.0. If we want to make it auto fit we need to unprotect, then auto fit.
    Later we can protect again

  • Working with big vectors

    My program works with a large vector of objects.
    The problem is that the vector is to big to be stored in memory.
    Is there any utility that will store the whole vector in a file
    and seamlessly cache parts of it to memory ?
    Thanks.

    It seems I will have to build my own file mapping.
    Since all my objects have the same size (e.g. all
    Integers or String),
    what is the best and fast way to read a specific
    object (e.g. vector[200]) ? Also, what is the fast way
    to read a bulk of objects (e.g. vector[200-300]) ?If your are dealing with integers or Strings I don't think you should go for a Vector filled with objects solution. You can minimize the memory requirements quite a bit if you use arrays.
    Integers. Why not use an int array? Each int takes up 4 bytes in memory but an Integer Object adds an overhead of maybe 16 byte. If you use int's your memory need shrinks to a fifth.
    Strings. A char takes 2 bytes. Maybe you can store a String as a byte array instead, thus saving 1 byte per char. The memory need shrinks to a half. It would be even more efficient if you just dumped all strings in one large byte array (with a null byte terminating each string). In addition you would need a second array with the start positions to the strings.
    These are the densest in memory data structures you can get. If you still have too much data you will have to go for files. The in memory solutions I've suggested can be directly used with files (just substitute array with file).

  • How can I work with big iMovie 6 file?

    I am trying to make a one 70 minute movie with iMovie 6 but am having great difficulties because the file has reached 78 gig and is now unworkable because it is just too slow to even play. Even cutting it in half does not solve the problem. Each half will play but I can't work with them in the timeline. I need to add more audio files and music. Any suggestions?

    I suspect most slowdowns occur because of complex audio, not the size of the project. It sometimes helps to export the audio to an AIFF file, then re-import that file back into the project and place it in its own audio track. When you disable the audio of the other tracks, playback is improved.
    That makes it harder to edit a half-finished project, however. It's a technique best reserved for almost-finished projects.
    You could export the timeline to the camera, then re-import it to a new project. That will both make the project smaller and "flatten" its audio and video. Most clips will return as the clips they are now.
    70 minutes of video is ordinarily about 15GB, so something has increased the size substantially. (That's not normally a problem you have to worry about; the size of the project itself is probably not the problem.)
    Karl

  • Winshuttle problem with new excel sheet

    Hi ,
    I am getting Winshuttle problem after the excel upgraded to latest version.
    when i open the winshuttle from icon, i dont get any prompt/no information.
    Any ideas fromo experts ?
    Siva

    We solved the problem by going into the performance settings and disabling the "fade" functionality in Windows. To get to the screen to make the changes in Windows, open the Control Panel and navigate to "System". Open "System" and click on the "Advanced Settings" tab. Next, click on the button marked "Settings" in the "Performance" area. In the "Visual Affects" tab, clear the checkbox for three "Fade... " options.
    I tested this successfully, even for users who have no administrative rights on their computer.
    Please try this solution and see what results you receive. The strange thing in our situation is that the OS image used for laptops does not suffer the problem with Bex and WinShuttle as does the OS image used for desktop computers.
    BG, are you from the UK? I ask as I watch a few UK television programs, and I notice they use "sorted" in the same manner us Americans use "taken care of" or as us Southerners say "figured out".
    Cheers,
    Kurt

  • In mail drag and drop to desktop does not work with big pictures in 10.9

    My drag and drop function in apple mail program does not working anymore after upgrade to macos 10.9
    Big picture in my mail does not want to drag to the desktop anymore!
    Imac 2.93 Ghz core i7

    Hello,
    Please give your SPS (Java) and Patch level of BIBASES & BIWEBAPP.
    Regards, Karol
    SAP NetWeaver BI, Development

  • With an excel sheet open I try to open skype, excel goes away

    When I have an excel spreadsheet open and try to open Skype the spreadsheet disappears. What is happening
    and how do I correct the problem.

    What do you mean by "disappears"? The program quits? Please be more specific with detail.

Maybe you are looking for