}
public static String generateSheet1_Summary(String strdate, int totaldays) throws Exception {
Connection conn = null;
Report report = null;
conn = DriverManager.getConnection("jdbc:mysql://192.95.29.8:2303/cms", "root", "password");
//create sheet1- Row, Cell
Workbook wb = new XSSFWorkbook();
Sheet sheet1 = wb.createSheet("Summary");
sheet1.setColumnWidth(0, 3000);
sheet1.setColumnWidth(1, 3000);
Font font = wb.createFont();
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
//-------------------------------sheet1-----------------------------------------------------
Row firstrow = sheet1.createRow((short) 0);
CellStyle firstrow_style = wb.createCellStyle();
firstrow_style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
firstrow_style.setFillPattern(CellStyle.SOLID_FOREGROUND);
firstrow_style.setFont(font);
//Border for first row
firstrow_style.setBorderBottom( CellStyle.BORDER_THIN );
firstrow_style.setBorderLeft( CellStyle.BORDER_THIN );
firstrow_style.setBorderRight( CellStyle.BORDER_THIN );
firstrow_style.setBorderTop( CellStyle.BORDER_THIN );
firstrow_style.setBorderLeft( CellStyle.BORDER_THIN );
Cell firstRowCell0 = firstrow.createCell((short) 0);
firstRowCell0.setCellValue("Date");
firstRowCell0.setCellStyle(firstrow_style);
Cell firstRowCell1 = firstrow.createCell((short) 1);
firstRowCell1.setCellValue("Count");
firstRowCell1.setCellStyle(firstrow_style);
//Border for row
CellStyle row_style = wb.createCellStyle();
row_style.setBorderBottom( CellStyle.BORDER_THIN );
row_style.setBorderLeft( CellStyle.BORDER_THIN );
row_style.setBorderRight( CellStyle.BORDER_THIN );
row_style.setBorderTop( CellStyle.BORDER_THIN );
row_style.setBorderLeft( CellStyle.BORDER_THIN );
row_style.setAlignment(CellStyle.ALIGN_RIGHT);
//-------------------------------end sheet1-------------------------------------------------
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date setdate = sdf.parse(strdate);
String []startdate = new String[totaldays];
String []enddate = new String[totaldays];
int totalcount =0;
try {
logger.info("<<start get Date and Count>>");
//--------------------Query sheet 1--------------------------------
for(int i =0; i < totaldays;i++){
startdate[i]= queryDateFormat(DateUtils.addDays(setdate, i)).toString();
enddate[i]= queryDateFormat(DateUtils.addDays(setdate, i+1)).toString();
String sql = "SELECT COUNT(*) as count FROM cms.users WHERE '"+startdate[i]+"' <= dateAdded AND dateAdded <'"+enddate[i]+"'";
PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
startdate[i]= defineContentDateFormat(DateUtils.addDays(setdate, i)).toString();
enddate[i]= defineContentDateFormat(DateUtils.addDays(setdate, i+1)).toString();
while (rs.next()) {
report = new Report();
report.setCount(rs.getInt("count"));
}
Row row = sheet1.createRow((short) i+1);
Cell RowCell0 = row.createCell((short) 0);
row.createCell(0).setCellValue(startdate[i]);
RowCell0.setCellStyle(row_style);
Cell RowCell1 = row.createCell((short) 1);
row.createCell(1).setCellValue(report.getCount( ));
RowCell1.setCellStyle(row_style);
logger.info("Date :" + startdate[i] +" ,Count:" + report.getCount( ));
totalcount += report.getCount( );
}
logger.info("<<end get Date and Count>> \n");
//Space row
sheet1.createRow((short) startdate.length+1).createCell((short) 0).setCellStyle(row_style);