Hey
I hope you can figure out how to read data from the table on the webpage.
Once you are done with the reading part below is the approach for writing an excel sheet
just read the data from the web page and write it on the excel sheet by setting the content type to ms-excel eg - response.setContentType("application/vnd.ms-excel")
Now to write it on the excel you have two options -
1. do it like u write a table dynamically in
jsp, but in this case the format of excel sheet will not be in your control. trust me this is easy but of no good.
2. Use Apache poi project for excel sheet . download the api give it classpath and then use the api in the
servlet. Why servlet because jsp will not allow you to write the data on the excel sheet even though it wont give an error. Writing a servlet wont be tough.
below is the eg. for writing excel using servlet -
import java.io.* ;
import javax.servlet.* ;
import javax.servlet.http.* ;
import org.apache.poi.hssf.usermodel.* ;
import org.apache.poi.hssf.dev.* ;
import org.apache.poi.hssf.util.* ;
public class ExcelFile extends HttpServlet{
public void doPost(HttpServletRequest request , HttpServletResponse response) throws ServletException, IOException{
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition","attachment;filename=Web_Transact_Report.xls");
System.out.println("Going to create Excel file");
int rownum= 0 ;
HSSFWorkbook wb= new HSSFWorkbook();
HSSFSheet sheet= wb.createSheet("Transaction Report");
HSSFSheet sheet1= wb.createSheet("Net Banking");
System.out.println("Going to create rows");
HSSFRow row = sheet.createRow((short)rownum);
rownum++;
HSSFCellStyle headerStyle= wb.createCellStyle();
HSSFFont headerfont= wb.createFont();
headerfont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
headerfont.setColor((short)9);
headerfont.setFontName("Arial");
headerStyle.setFont(headerfont);
headerStyle.setFillBackgroundColor((short)18);
headerStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
HSSFCellcel ;
cel = row.createCell((short)0);
cel.setCellValue("Service");
cel.setCellStyle(headerStyle);
cel = row.createCell((short)1 );
cel.setCellValue("TXN ID");
cel.setCellStyle(headerStyle);
System.out.println("writing data to response");
wb.write(response.getOutputStream());
}