Home How to loop the output and write to excel
Reply: 0

How to loop the output and write to excel

user5059
1#
user5059 Published in April 25, 2018, 12:35 am

number3 : 10;
linenumber : 200;
quantity : 200 / 10

Example Output :-

CLASS: SQUARE
DESIGN : RECTANGLE
START SERIAL : "Data Line 1"
END SERIAL : "Data Line 10"
NO OF LINE : 10
PER TOTAL: 1 / 20

CLASS: SQUARE
DESIGN : RECTANGLE
START SERIAL : "Data Line 11"
END SERIAL : "Data Line 20"
NO OF LINE : 10
PER TOTAL: 2 / 20

CLASS: SQUARE
DESIGN : RECTANGLE
START SERIAL : "Data Line 21"
END SERIAL : "Data Line 30"
NO OF LINE : 10
PER TOTAL: 3 / 20

					String text1 = TextReport1.getText();
					String text2 = TextReport2.getText();
					
					String text3 = TextReport3.getText();
					int number3 = Integer.parseInt(text3);
					
					String absolutePath = files.getAbsolutePath();
		        	String filePath = absolutePath.substring(0,absolutePath.lastIndexOf(File.separator));
		        	new File(filePath+"/Label Report").mkdir();
					String date = format.format(new Date());
					try {
		 	    	   
			        	String FPath = files.getAbsolutePath();
			        	fr = new FileInputStream(FPath);
			        	reader = new BufferedReader(new InputStreamReader(fr));
			        	String line;
			        	
			        	int linenumber = 0;
			        	int start = 1 - number3 + number3;
			            int end   = 0 + number3;
			        	while((line = reader.readLine()) != null) {
			    			linenumber++;
			    			
			    			System.out.println("total 1 : " + linenumber);
			    			if(linenumber == start)
			    			track1 = line.substring(0, 19);
			    			if(linenumber == end) 
			    	        track2 = line.substring(0, 19);
			    		}
			        	
						FileOutputStream fos = new FileOutputStream(new File(filePath + "/Label Report/"+ "Label Report "+ date + ".xls"));
			        	HSSFWorkbook workbook = new HSSFWorkbook();
			        	HSSFSheet sheet = workbook.createSheet("label Generator");
			        	
			        	int i11 = 0;
			    		int i12 = 1;
            
	    for(int i = 1; i<=linenumber; i = i + number3) 
			//System.out.println("total 2 : " + linenumber);
			System.out.println("Quantity : " + linenumber / number3);
	    
		int Quantity = (linenumber / number3);
			//System.out.println("start 1 : " + start);
	    	//System.out.println("end   1 : " + end);
		
		start = (start + number3);
	    end = (end + number3);
	    	//System.out.println("start 2 : " + start);
	    	//System.out.println("end   2 : " + end);
		
							System.out.println("=========================");
				            System.out.println(text1);
				            System.out.println(text2);
				            System.out.println(track1);
				            System.out.println(track2);
				            System.out.println(number3 + " Card");
				            System.out.println(i12 +  "/" +  Quantity);
				            System.out.println("======================" + "\n");
				            
				            HSSFRow row = sheet.createRow((short) i11);
				            row = sheet.createRow((short) i11+0);
				            row.createCell(0).setCellValue("CUSTOMER ");
				            row.createCell(1).setCellValue(" : ");
					        row.createCell(2).setCellValue(text1);
					        
					        row = sheet.createRow((short) i11+1);
					        row.createCell(0).setCellValue("DESIGN ");
					        row.createCell(1).setCellValue(" : ");
					        row.createCell(2).setCellValue(text2);
					        
					        row = sheet.createRow((short) i11+2);
					        row.createCell(0).setCellValue("SERIAL START ");
				            row.createCell(1).setCellValue(" : ");
					        row.createCell(2).setCellValue(track1);
					        
					        row = sheet.createRow((short) i11+3);
					        row.createCell(0).setCellValue("SERIAL END ");
				            row.createCell(1).setCellValue(" : ");
					        row.createCell(2).setCellValue(track2);
					        
					        row = sheet.createRow((short) i11+4);
					        row.createCell(0).setCellValue("QUANTITY ");
				            row.createCell(1).setCellValue(" : ");
					        row.createCell(2).setCellValue(number3 + " Card");
					        
					        row = sheet.createRow((short) i11+5);
					        row.createCell(0).setCellValue("BOX NO ");
				            row.createCell(1).setCellValue(" : ");
					        row.createCell(2).setCellValue(i12 + "/" + Quantity);
					        
					        sheet.autoSizeColumn(0);
					        sheet.autoSizeColumn(1);
					        sheet.autoSizeColumn(2);
					        i11++;
					        i12++;
		
					reader.close();
					workbook.write(fos);
	    		    fos.flush();
	                fos.close();
					return;
					}catch (IOException e1) {
			            e1.printStackTrace();
					}

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.384978 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO