Announcement Announcement Module
Collapse
No announcement yet.
Wishlist / Coding Examples for the following... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Hi Dave,

    Thanks for the reply,

    I finally figured out what's wrong. It was because I included the log4j jar file but did not create a log4j property file so all my errors messages did not appear. Anyway, the actual cause was that I had a class not found exception. I had renamed my custom item writer class but had not updated it in my job configuration xml file. Also, I changed my approach. Here's how I coded it.

    Code:
    public class CustomExcelSheetReader extends FlatFileItemReader implements StepExecutionListener {
    
    public void beforeStep(StepExecution arg0) {
       //read excel file name from execution context
      //convert excel file to csv
      // super.setResource(new FileSystemResource(parentPath + "Sample.csv"));
    }
    with that code, I am now able to read my input file as a flat file and use it for my processing.

    Regards,
    Raymond

    Comment


    • #17
      hi raymond,

      can you provide the code for beforeStep method ?


      Originally posted by raymondwee View Post
      Hi Dave,

      Thanks for the reply,

      I finally figured out what's wrong. It was because I included the log4j jar file but did not create a log4j property file so all my errors messages did not appear. Anyway, the actual cause was that I had a class not found exception. I had renamed my custom item writer class but had not updated it in my job configuration xml file. Also, I changed my approach. Here's how I coded it.

      Code:
      public class CustomExcelSheetReader extends FlatFileItemReader implements StepExecutionListener {
      
      public void beforeStep(StepExecution arg0) {
         //read excel file name from execution context
        //convert excel file to csv
        // super.setResource(new FileSystemResource(parentPath + "Sample.csv"));
      }
      with that code, I am now able to read my input file as a flat file and use it for my processing.

      Regards,
      Raymond

      Comment


      • #18
        how ?

        how did you covert excel to csv ?

        Comment


        • #19
          Hi,

          I'm using Apache POI to convert from excel to CSV. Please see a sample code below:

          Code:
              InputStream inp;
              HSSFWorkbook wb = null;
              
              //instantiate a new workbook object
              try {
                   //inputFile is the name of the xls file, i.e. sample.xls
          	 inp = new FileInputStream(inputFile);
          	 wb = new HSSFWorkbook(inp);
              } catch (FileNotFoundException e1) {
          	// TODO Auto-generated catch block
          	e1.printStackTrace();
              } catch (IOException e) {
          	// TODO Auto-generated catch block
          	e.printStackTrace();
              }
          
              HSSFSheet sheet = wb.getSheet(sheetName);
              try {
                  Writer output = new BufferedWriter(
                               new FileWriter(sheetName + ".csv"));
          	StringBuilder contents = new StringBuilder();
          		
                  //i=1 because I wanted to skip the first line. 
          	for (int i=1; i <= sheet.getLastRowNum(); i++) {
          	    HSSFRow row = sheet.getRow(i);			
          
          	   for (int j=0; j < sheet.getRow(0).getPhysicalNumberOfCells(); j++) {
          		HSSFCell cell = row.getCell(j);
          				
          		if (cell != null) {
          			contents.append(cell.getRichStringCellValue());
          		} 
          		if (j< (sheet.getRow(0).getPhysicalNumberOfCells() -1)) {
          			contents.append(",");
          		}					
          	   }
          	   contents.append("\n");				
          	}
          	try {
          		output.write( contents.toString());
          	} finally {
          		output.close();
          	}		
              }
          Regards,
          Raymond

          Comment


          • #20
            Thanks for quick reply.

            Originally posted by raymondwee View Post
            Hi,

            I'm using Apache POI to convert from excel to CSV. Please see a sample code below:

            Code:
                InputStream inp;
                HSSFWorkbook wb = null;
                
                //instantiate a new workbook object
                try {
                     //inputFile is the name of the xls file, i.e. sample.xls
            	 inp = new FileInputStream(inputFile);
            	 wb = new HSSFWorkbook(inp);
                } catch (FileNotFoundException e1) {
            	// TODO Auto-generated catch block
            	e1.printStackTrace();
                } catch (IOException e) {
            	// TODO Auto-generated catch block
            	e.printStackTrace();
                }
            
                HSSFSheet sheet = wb.getSheet(sheetName);
                try {
                    Writer output = new BufferedWriter(
                                 new FileWriter(sheetName + ".csv"));
            	StringBuilder contents = new StringBuilder();
            		
                    //i=1 because I wanted to skip the first line. 
            	for (int i=1; i <= sheet.getLastRowNum(); i++) {
            	    HSSFRow row = sheet.getRow(i);			
            
            	   for (int j=0; j < sheet.getRow(0).getPhysicalNumberOfCells(); j++) {
            		HSSFCell cell = row.getCell(j);
            				
            		if (cell != null) {
            			contents.append(cell.getRichStringCellValue());
            		} 
            		if (j< (sheet.getRow(0).getPhysicalNumberOfCells() -1)) {
            			contents.append(",");
            		}					
            	   }
            	   contents.append("\n");				
            	}
            	try {
            		output.write( contents.toString());
            	} finally {
            		output.close();
            	}		
                }
            Regards,
            Raymond

            Comment


            • #21
              Spring Batch Document PDF missing images

              Hi,

              I download Spring Batch2.0 PDF Reference Document.
              PDF file does not contains images layered architecture and other images like HTML file

              Last version Spring Batch1.0 contains all images like HTML.
              Will new version of Spring Batchh 2.0 PDF will be released?

              I use to print out the PDF Version Spring Batch as reference guide for Spring batch. I want to have PDF Spring batch with all images like HTML because I use to keep it as ebooks to reference.

              Comment


              • #22
                Spring batch 2.0 is not released yet, so documentation may be in any state.
                Just wait for release.
                Originally posted by phyo936 View Post
                Hi,

                I download Spring Batch2.0 PDF Reference Document.
                PDF file does not contains images layered architecture and other images like HTML file

                Last version Spring Batch1.0 contains all images like HTML.
                Will new version of Spring Batchh 2.0 PDF will be released?

                I use to print out the PDF Version Spring Batch as reference guide for Spring batch. I want to have PDF Spring batch with all images like HTML because I use to keep it as ebooks to reference.

                Comment

                Working...
                X