poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdhanara <rdhan...@ford.com>
Subject Re: Loading Large XLSM file using POI without Memory issue .
Date Mon, 15 Apr 2019 15:33:00 GMT

As suggested trying to do below steps,

1. Unzip the large xlsm file 
2.Delete the Sheet as per requirement
3.repack the source once again to xlsm file

I have done step 1 & 3 as follow. Please have a look and correct me if i am
going in wrong direction ..
*1.Tried unzipping the large xlsm file as follows*

String zipFilePath = "C:\\PROJECTS\\Source.xlsm";
String destDir = "C:\\PROJECTS\\unzip";

 private static void unzip(String zipFilePath, String destDir) {
	        File dir = new File(destDir);
	        // create output directory if it doesn't exist
	        FileInputStream fis;
	        //buffer for read and write data to file
	        byte[] buffer = new byte[1024];
	        try {
	            fis = new FileInputStream(zipFilePath);
	            ZipInputStream zis = new ZipInputStream(fis);
	            ZipEntry ze = zis.getNextEntry();
	            while(ze != null){
	                String fileName = ze.getName();
	                File newFile = new File(destDir + File.separator +
	                System.out.println("Unzipping to
	                //create directories for sub directories in zip
	                new File(newFile.getParent()).mkdirs();
	                FileOutputStream fos = new FileOutputStream(newFile);
	                int len;
	                while ((len = zis.read(buffer)) > 0) {
	                fos.write(buffer, 0, len);
	                //close this ZipEntry
	                ze = zis.getNextEntry();
	            //close last ZipEntry
	        } catch (IOException e) {

Once after executing above program it extract xlsm content as follows


*2. Repacking *

ZipOutputStream out = new ZipOutputStream(new

              Files.walkFileTree(Paths.get("C:\\PROJECTS\\unzip"), new
SimpleFileVisitor<Path>() {
                  public FileVisitResult visitFile(Path file,
BasicFileAttributes attrs) throws IOException {
                      Files.copy(file, out);
                      return FileVisitResult.CONTINUE;

If I open TEST.xlsm  I am able to see the original xlsm file content here..

But as per the suggestion before repacking i need to delete the expected
sheet and then repack it.
 I am trying to parse this file and delete the sheet tag..


Will update you shortly.

*Note: If you have any better approach than the one i mentioned here do let
me know ..*

Sent from: http://apache-poi.1045710.n5.nabble.com/POI-User-f2280730.html

To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org

View raw message