2013年9月20日星期五

EXCEL write problems

private void write_excel (ArrayList [] array)
{
try {
OutputStream file1 = new FileOutputStream ("E: \ \ Delivery List test1.xls");
HSSFWorkbook wb1 = new HSSFWorkbook ();
HSSFSheet newsheet = wb1.createSheet ();
for (int k = 0; k {
for (int i = 0; i {
HSSFRow row = newsheet.createRow ((short) i);
HSSFCell cell = row.createCell ((short) k);
cell.setCellType (HSSFCell.CELL_TYPE_STRING);
/ / String a = (String) ite.next ();
cell.setCellValue (array [k]. get (i). toString ());
/ / System.out.println (a);
System.out.println (array [k]. get (i). toString ());

}
}
wb1.write (file1);
file1.close ();
} catch (FileNotFoundException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
} catch (IOException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}
}


ask, Why do I get a new excel only the most one array [] information in the next how can I ask all array [k] writes all the contents in excel ?
------ Solution ---------------------------------------- ----
http://bbs.csdn.net/topics/390360927
you this and I've edited this is basically exactly the same
but I input is an array String [] []
you typed
List [] listarray only
------ Solution ----------------------------- ---------------
landlord, you say the problem has been resolved, can not hold the spirit of sharing , sharing some of the stuff . We really want to solve addition to your , and your solution.
------ For reference only -------------------------------------- -
problem has been solved
------ For reference only ------------------------------ ---------
  The reply deleted by an administrator at 2013-09-19 09:14:12

------ For reference only ---------------------------------- -----
roof . . .
------ For reference only -------------------------------------- -

sorry, forgot to share
public void w_excel (ArrayList [] array_detail)
{
try
{
HSSFWorkbook wb = new HSSFWorkbook ();
HSSFSheet newsheet = wb.createSheet ();
for (short i = 0; i {
/ / System.out.println (array_detail.length);
HSSFRow row = newsheet.createRow (i);
for (short j = 0; j {
HSSFCell cell = row.createCell (j);
cell.setCellType (HSSFCell.CELL_TYPE_STRING);
cell.setCellValue (array_detail [j]. get (i). toString ());
System.out.println (array_detail [j]. get (i). toString ());
}
}
FileOutputStream file1 = new FileOutputStream ("E: \ \ test.xls");
wb.write (file1);
file1.close ();
} catch (IOException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}

}

没有评论:

发表评论