how to connect client to server using Sockets
/* author K.santhosh kumar-> [email protected]*/
import java.io.FileOutputStream;
import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class ExrelWriter{ public static void main(String[]args){ try{ String filename="c:/hello.xls" ; String rw[][]={{"1","san","kumar","ksankumar","[email protected]","india"}, {"2","palani","kumar","palanikumar","[email protected]","india"}, {"3","raja","pandiyan","rajapandiyan","[email protected]","US"}}; HSSFWorkbook hwb=new HSSFWorkbook(); HSSFSheet sheet = hwb.createSheet("new sheet");
HSSFRow rowhead= sheet.createRow((short)0); rowhead.createCell((short) 0).setCellValue("SNo");
rowhead.createCell((short) 1).setCellValue("First Name");
rowhead.createCell((short) 2).setCellValue("Last Name");
rowhead.createCell((short) 3).setCellValue("Username");
rowhead.createCell((short) 4).setCellValue("E-mail");
rowhead.createCell((short) 5).setCellValue("Country");
for(int i=1;i<3;i++)
for(int j=0;j<6;j++){
HSSFRow row= sheet.createRow((short)i);
row.createCell((short) j).setCellValue(rw[i-1][j]);
}
FileOutputStream fileOut = new FileOutputStream(filename); hwb.write(fileOut); fileOut.close(); System.out.println("Your excel file has been generated!");
} catch ( Exception ex ) { System.out.println(ex);
} } }
Ads