Hi,

I think the problem is that you re-create the row in each
loop-iteration, thus overwriting the cells/rows from before...

You probably want to create the rows once outside the main loop and
only create the cells in the main loop itself.

Dominik.

On Thu, Feb 12, 2015 at 5:42 AM, Sriram <[email protected]> wrote:
> Dear Users,
>
> Please help in the following case with your ideas, I am noticing a strange
> behavior where the the I am expecting the scenario 1 from the below code ,
> But it not happening. Somewhere the entries are getting erased.
> <http://apache-poi.1045710.n5.nabble.com/file/n5717858/2015_02_12_10_10_25_Microsoft_Excel_testexcel.png>
>
> I wanted the write data to the XLS in new column once the treshold is
> reached. But what happens is the the data in the 0th column are getting
> erased during this process.
>
>
> regards,
> Sriram R
>
>
> import java.io.FileOutputStream;
> import java.io.IOException;
> import java.util.HashSet;
> import java.util.Iterator;
>
> import org.apache.poi.hssf.usermodel.HSSFSheet;
> import org.apache.poi.hssf.usermodel.HSSFWorkbook;
> import org.apache.poi.ss.usermodel.Cell;
> import org.apache.poi.ss.usermodel.Row;
>
> public class tt {
>
>         private static  int rowNum = 0;
>         private static  int cellNum = 0;
>
>         public static void main(String args[]) throws IOException {
>
>                 HashSet<String> set = new HashSet<>();
>                 for (int i = 0; i < 10; i++) {
>                         set.add("123456789"+String.valueOf(i));
>                 }
>                 System.out.println("set" + set);
>                 int threshhold = 5;
>                 Iterator<String> itr = set.iterator();
>                 String nxt = null;
>                 while (itr.hasNext()) {
>                         Row myRow = mySheet.createRow((short)rowNum++);
>                         if(rowNum == threshhold){
>                                  rowNum = 1;
>                                  cellNum++;
>                         }
>                         System.out.println("->>"+rowNum+"--"+cellNum);
>                         Cell cell =myRow.createCell(cellNum);
>                         nxt = itr.next();
>            cell.setCellValue((String) nxt);
>                 }
>
>                 try {
>                         FileOutputStream out = new FileOutputStream(dest);
>                         myWorkBook.write(out);
>                         out.close();
>                 } catch (Exception e) {
>                         e.printStackTrace();
>                 }
>
>         }
>
>         private static String dest = 
> "C:\\Users\\rsriram\\Desktop\\testexcel.xls";
>         private static HSSFWorkbook myWorkBook = new HSSFWorkbook();
>         private static HSSFSheet mySheet = myWorkBook.createSheet();
>
> }
>
>
>
> --
> View this message in context: 
> http://apache-poi.1045710.n5.nabble.com/Problem-in-writing-data-to-Excel-XLS-format-tp5717858.html
> Sent from the POI - Dev mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to