Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Writing in the column excel

  1. #1
    Member
    Join Date
    Jun 2017
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Writing in the column excel

    public void scriviNewId() throws IOException {
    		String FILE_NAME = "C:\\Users\\java\\Desktop\\x.xlsx";
    		InputStream inp = new FileInputStream(FILE_NAME);
    		Workbook wb = WorkbookFactory.create(inp);
    		Sheet sheet = wb.getSheetAt(0);
     
    		//Vai a leggere la nuova colonna
    		Cliente cliente = new Cliente();
    		cliente.fillVeicoloId();
     
    		for (int i = 0; i < cliente.getVeicoloId().size(); i++) {
    			Row row = sheet.createRow(i + 1); //Inizia alla riga 1
    			System.out.println("Scrivi:  " + cliente.getVeicoloId().get(i));
     
    			// Specific cell number 
    	        Cell cell = row.createCell(5); 
     
    	        // putting value at specific position 
    	        cell.setCellValue(cliente.getVeicoloId().get(i)); 
     
    			//row.createCell(5).setCellValue(cliente.getVeicoloId().get(i)); // Colonna 34
     
    		}
     
    		FileOutputStream fileOut = new FileOutputStream(FILE_NAME);
    		wb.write(fileOut);
    		fileOut.close();
     
    	}


    Why does it overwrite other columns?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Writing in the column excel

    Can you post some example of what the code is doing?
    Add some comments to show what you want it to do instead.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Jun 2017
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Writing in the column excel

    In practice, I like to write this code in column F.
    But when he writes in column F, he deletes the data from the other columns, how come?

    column

    A B C D E F
    0
    1
    5
    ..


    the other columns delete them and I do not want the data of the other columns to be deleted

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Writing in the column excel

    In most cases When updating the contents of a file, ALL the data that you want to be in the file needs to be written to the file.

    I don't know how the Workbook write method works. Does it automatically fill in all the columns?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Jun 2017
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Writing in the column excel

    yes the column is completely filled in, how can I solve the problem?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Writing in the column excel

    I don't know how the Workbook write method works.
    Try this:
    Fill in all the columns you want to be written before calling the write method.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Writing to Excel
    By Joe4296 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 30th, 2014, 04:31 AM
  2. store certain column in ArrayList from excel file
    By vector_ever in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 12th, 2013, 08:46 AM
  3. Sum elements column by column
    By NallelyXIII in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 9th, 2013, 01:22 AM
  4. Reading from a Text file & writing to Excel spreadsheets
    By javanooby in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: May 14th, 2012, 12:41 PM
  5. Excel Column Letter Referencing
    By aussiemcgr in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 21st, 2010, 03:47 PM