Page 2 of 2 FirstFirst 12
Results 21 to 32 of 32
  1. #21
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    9

    Default ahhh brain ache

    OK! I think i've cracked it.. This is now totally generic and if you come back to me and tell me this doesn't work, I give up!!!

    Java Code:
    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.InputStreamReader;
    
    public class csv {
    
    	public static void main(String[] args) throws Exception {
    		
    		// File path & name
    		String filepath = "csv.txt";
    		
    		// Read in file to determine how many lines it has
    		FileInputStream in = new FileInputStream(filepath);
    		BufferedReader br = new BufferedReader(new InputStreamReader(in));
    		String strLine;
    		int counter = 0;
    		
    		while ((strLine = br.readLine()) != null)
    		{
    			counter++;
    		}
    			
    		in.close();
    		
    		// Read in file
    		FileInputStream in2 = new FileInputStream(filepath);
    		BufferedReader br2 = new BufferedReader(new InputStreamReader(in2));
    		String strLine2;
    		
    		// Declare array
    		String[] myarray;
    		myarray = new String[counter];
    			
    			// Add each line to the array
    			for (int i = 0; i < myarray.length; i++){
    				myarray[i] = br2.readLine();
    			}
    		
    		in2.close();
    		
    		// Loop through array looking for the correct text, format & print
    		for (int c = 0; c < myarray.length; c++){
    			
    			if(myarray[c].contains("INVOICE NO") | myarray[c].contains("invoice No") ){
    								
    				String[] split = myarray[c+1].split(" ");
    				
    				String invoicePt1 = "";
    				String invoicePt2 = "";
    				String dated = "";
    				
    				for (int i = 0; i < split.length; i++){
    					if (split[i].length() == 4 &! split[i].contains("-")){
    						invoicePt1 = split[i].replace("\"", "");
    						}
    					if (split[i].length() > 1 &! split[i].contains("-")){
    						invoicePt2 = split[i].replace("\"", "");
    						}
    					else
    					{
    						dated = split[i].replace("\"", "").trim();
    					}
    				}
    											
    				System.out.println("INVOICE NO: " + invoicePt1 + " " + invoicePt2);
    				System.out.println("Dated: " + dated);
    			}
    			
    			if(myarray[c].contains("Buyer's Order")){
    				
    				String[] split = myarray[c+1].split(" ");
    				String buyersDate = "";				
    				String buyersOrder = "";
    				
    				for (int i = 0; i < split.length; i++){
    					if (split[i].length() > 1 &! split[i].contains("-")){
    						buyersOrder = split[i].replace("\"", "");
    					}
    					if (split[i].length() > 1 & split[i].contains("-")){
    						buyersDate = split[i].replace("\"", "");
    					}
    				}
    								
    				System.out.println("Buyer's Order No: " + buyersOrder );
    				System.out.println("Dated: " + buyersDate.trim());
    			}
    		}
    	}
    }
    Or:

    Java Code:
    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.InputStreamReader;
    
    public class csv {
    
    	public static void main(String[] args) throws Exception {
    		
    		// File path & name
    		String filepath = "csv.txt";
    		
    		// Read in file to determine how many lines it has
    		FileInputStream in = new FileInputStream(filepath);
    		BufferedReader br = new BufferedReader(new InputStreamReader(in));
    		String strLine;
    		int counter = 0;
    		
    		while ((strLine = br.readLine()) != null)
    		{
    			counter++;
    		}
    			
    		in.close();
    		
    		// Read in file
    		FileInputStream in2 = new FileInputStream(filepath);
    		BufferedReader br2 = new BufferedReader(new InputStreamReader(in2));
    		String strLine2;
    		
    		// Declare array
    		String[] myarray;
    		myarray = new String[counter];
    			
    			// Add each line to the array
    			for (int i = 0; i < myarray.length; i++){
    				myarray[i] = br2.readLine();
    			}
    		
    		in2.close();
    		
    		// Loop through array looking for the correct text, format & print
    		for (int c = 0; c < myarray.length; c++){
    			
    			if(myarray[c].contains("INVOICE NO") | myarray[c].contains("invoice No") ){
    								
    				String[] split = myarray[c+1].split(" ");
    				
    				String invoicePt1 = "";
    				String invoicePt2 = "";
    				String dated = "";
    				
    				for (int i = 0; i < split.length; i++){
    					if (split[i].contains("Jan") &! split[i].contains("-")){
    						invoicePt1 = split[i].replace("\"", "");
    					}
    					if (split[i].contains("Feb") &! split[i].contains("-")){
    						invoicePt1 = split[i].replace("\"", "");
    					}
    					if (split[i].contains("Mar") &! split[i].contains("-")){
    						invoicePt1 = split[i].replace("\"", "");
    					}
    					if (split[i].contains("Apr") &! split[i].contains("-")){
    						invoicePt1 = split[i].replace("\"", "");
    					}
    					if (split[i].contains("May") &! split[i].contains("-")){
    						invoicePt1 = split[i].replace("\"", "");
    					}
    					if (split[i].contains("Jun") &! split[i].contains("-")){
    						invoicePt1 = split[i].replace("\"", "");
    					}
    					if (split[i].contains("Jul") &! split[i].contains("-")){
    						invoicePt1 = split[i].replace("\"", "");
    					}
    					if (split[i].contains("Aug") &! split[i].contains("-")){
    						invoicePt1 = split[i].replace("\"", "");
    					}
    					if (split[i].contains("Sep") &! split[i].contains("-")){
    						invoicePt1 = split[i].replace("\"", "");
    					}
    					if (split[i].contains("Oct") &! split[i].contains("-")){
    						invoicePt1 = split[i].replace("\"", "");
    					}
    					if (split[i].contains("Nov") &! split[i].contains("-")){
    						invoicePt1 = split[i].replace("\"", "");
    					}
    					if (split[i].contains("Dec") &! split[i].contains("-")){
    						invoicePt1 = split[i].replace("\"", "");
    					}
    					if (split[i].length() > 1 &! split[i].contains("-")){
    						invoicePt2 = split[i].replace("\"", "");
    						}
    					else
    					{
    						dated = split[i].replace("\"", "").trim();
    					}
    				}
    											
    				System.out.println("INVOICE NO: " + invoicePt1 + " " + invoicePt2);
    				System.out.println("Dated: " + dated);
    			}
    			
    			if(myarray[c].contains("Buyer's Order")){
    				
    				String[] split = myarray[c+1].split(" ");
    				String buyersDate = "";				
    				String buyersOrder = "";
    				
    				for (int i = 0; i < split.length; i++){
    					if (split[i].length() > 1 &! split[i].contains("-")){
    						buyersOrder = split[i].replace("\"", "");
    					}
    					if (split[i].length() > 1 & split[i].contains("-")){
    						buyersDate = split[i].replace("\"", "");
    					}
    				}
    								
    				System.out.println("Buyer's Order No: " + buyersOrder );
    				System.out.println("Dated: " + buyersDate.trim());
    			}
    		}
    	}
    }
    Based on the csv file you attached above. This is the output:

    Java Code:
    INVOICE NO: Feb 08/Pur/21
    Dated: 20-Feb-2008
    Buyer's Order No: EKA78JN080662
    Dated: 20-Mar-2008
    :D
    Last edited by DonCash; 04-17-2008 at 12:54 PM.
    Did this post help you? Please me! :cool:

  2. #22
    jazz2k8's Avatar
    jazz2k8 is offline Senior Member
    Join Date
    Apr 2008
    Posts
    149
    Rep Power
    0

    Default

    We cannot predict that because the document is given by the OCR Engine.If the scanned image resolution varies then the data may jumbles...We have givencondition to client to scan with 300dpi when scanning.After Scanning the image will be given to OCR Engine for OCRing.The Output format may be .txt or .csv or any type which we can feel better to retrieve data from that.

    I am trying hard with regular Expressions...Hope i ll get...

    Thanks for your time and Help...If you want u can try..

    thanks
    jazz

  3. #23
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    9

    Default

    Try the above code!!!!! Tell me what happens....
    Did this post help you? Please me! :cool:

  4. #24
    jazz2k8's Avatar
    jazz2k8 is offline Senior Member
    Join Date
    Apr 2008
    Posts
    149
    Rep Power
    0

    Lightbulb

    Hurrrrrrrrrrrrrrreeeeeeeeeeeeeeeeeyyyyyyyyyyyyyyyy yyyyyyyy

    U R SIMPLY SUPERB:cool:

    Its Working Maaaan...Really Surprised....

    I will try with some other examples and let u Know if i get any...:-)

    Thanks for ur valuable time...may i know Your Details...

  5. #25
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    9

    Default

    U R SIMPLY SUPERB
    Thanks! Ill never get tired of hearing that! LOL

    I tested it with several versions of the csv file and it seems to be working 100%.

    That was quite tricky to work out actually!

    Please +Rep me ;) :D

    may i know Your Details...
    What do you mean?
    Did this post help you? Please me! :cool:

  6. #26
    jazz2k8's Avatar
    jazz2k8 is offline Senior Member
    Join Date
    Apr 2008
    Posts
    149
    Rep Power
    0

    Default

    Ahhh...UR Awesome...

    Here i want to put some more pressure on u...shall i send you other csv formats which i am trying with .

    Your Details Means..What is your actual Name and Your From?soon..:D

  7. #27
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    9

    Default

    Yeah you can do if you want although I can't spend much more time working on this and doing your job for you :p lol..

    How much Java do you know because you should easily be able to edit this to suit your needs.

    My names Don and im from England :)
    Did this post help you? Please me! :cool:

  8. #28
    jazz2k8's Avatar
    jazz2k8 is offline Senior Member
    Join Date
    Apr 2008
    Posts
    149
    Rep Power
    0

    Default

    Hope this is my last request ....

    I tried with .txt format too..its working fine for me...


    Here i am attaching my files..can u Have a look ...please..Never Mind..This is the Last Phase Where i stucked Up..

    In these files also i ned the same fileds to extract..


    I will be awaiting for your response...sorry to disturb You:-)
    Attached Files Attached Files

  9. #29
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    9

    Default

    Which format are you going to be using? The .txt or .csv? The csv file will be easier for me to modify this code for!!

    The 'kalatoaster' file is confusing me:

    "Invoice No. !Dated"
    "Kala Genset Pvt.Ltd."
    "392/1, Mahalunge Ingale, Feb 08/Pur118 12-Feb-2008"

    Which part of the information do you want to return for Invoice no?

    You can make this program work for 'berger.csv' by doing a slight edit.

    Locate this piece of code near the bottom:

    Java Code:
    	for (int i = 0; i < split.length; i++){
    		if (split[i].length() > 1 &! split[i].contains("-")){
    			buyersOrder = split[i].replace("\"", "");
    		}
    		if (split[i].length() > 1 & split[i].contains("-")){
    			buyersDate = split[i].replace("\"", "");
    		}
    	}
    And replace with this:

    Java Code:
    	for (int i = 0; i < split.length; i++){
    		if (split[i].length() > 1 &! split[i].contains("-")){
    			buyersOrder = split[i].replace("\"", "");
    		}
    		if (split[i].length() > 1 & split[i].contains("-")){
    			buyersDate = split[i].replace("\"", "");
    		}
    		else {
    			buyersDate = myarray[c+2].replace("\"", "");
    		}
    	}
    Last edited by DonCash; 04-17-2008 at 04:33 PM.
    Did this post help you? Please me! :cool:

  10. #30
    jazz2k8's Avatar
    jazz2k8 is offline Senior Member
    Join Date
    Apr 2008
    Posts
    149
    Rep Power
    0

    Red face

    Thanks DON...UR THE REAL DON..can i have your personal mail id???sothat i will be in touch with you..You are very inspiring to me..thanks once again

  11. #31
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    9

    Default

    Hey Jazz2k8.

    If you ever want to contact me then your welcome to PM me here.

    If you ever want Java help though its always best to posts a thread in the forums because you'll have the benafit of all our members help. I'm not normally around to dedicate as much time to a problem as I have here!

    If you feel your questions have been answered. Please mark this thread as solved :)
    Did this post help you? Please me! :cool:

  12. #32
    jazz2k8's Avatar
    jazz2k8 is offline Senior Member
    Join Date
    Apr 2008
    Posts
    149
    Rep Power
    0

    Default Thanks

    OK DON..its nice to hear from you..i ll always in touch with you...

    Can i have your help in "How to Run an .exe using java" thread???:-)

Page 2 of 2 FirstFirst 12

Similar Threads

  1. count character in text file as input file
    By aNNuur in forum New To Java
    Replies: 7
    Last Post: 03-25-2010, 04:01 PM
  2. How to read a text file from a Java Archive File
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 09:13 AM
  3. Displaying data into text area
    By abhiN in forum New To Java
    Replies: 1
    Last Post: 01-22-2008, 10:30 AM
  4. Extract Text from PDF File using java
    By TSW1016 in forum Advanced Java
    Replies: 5
    Last Post: 01-06-2008, 11:03 PM
  5. Converting text file(.txt) to JPG file(.jpg) in java
    By javadeveloper in forum Advanced Java
    Replies: 0
    Last Post: 11-09-2007, 04:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •