I have to find the example string in excel sheet as I have to change it using java. I did it easily. But the problem comes when I have to do it same for specific times and each time I have to copy the data into new sheet. So if I have to do it for 5 times then there should be 5 worksheet in my excel workbok.
Here is my code.
int a=1;
String match="Keval Dalsaniya";
String[] name={"Ankit","Keval","Varun","Dhaval","Nirav"};
int i;
try {
FileInputStream file = new FileInputStream(new File("D:\\Ankit\\Data\\data.xlsx"));
XSSFWorkbook workbook = new XSSFWorkbook(file);
XSSFSheet sheet = workbook.getSheetAt(0);
for(i=0;a<=name.length;i++,a++)
{
Cell cell = null;
cell = sheet.getRow(0).getCell(4);
workbook.createSheet(name[i]);
if(cell.getStringCellValue().equals(match))
cell.setCellValue(name[i]);
else
JOptionPane.showMessageDialog(null, "No match found.");
System.out.println(name[i]);
}
file.close();
FileOutputStream outFile =new FileOutputStream(new File("D:\\Ankit\\Data\\update.xlsx"));
workbook.write(outFile);
outFile.close();
}
catch (Exception e)
{
e.printStackTrace();
}
wb.cloneSheet(sheetNumber)