I have to Fetch the data from Excel file which is Continuosly Changing. I have made a code in java it read the data from execl but not changing it. When i click the save button in excel and then run my code it will get the changing data.
private static void fuctionCall() throws BiffException, IOException {
// TODO Auto-generated method stub
Workbook workbook = Workbook.getWorkbook(new java.io.File("C:/ODIN/DIET/Arbitrage.xls"));
Sheet sheet = workbook.getSheet(0);
/*Cell a1 = sheet.getCell(0,0); String s1=a1.getContents(); System.out.println("My name is "+s1); */
for(int i=0;i<sheet.getColumns();i++) {
for(int j=1;j<sheet.getRows();j++) {
Cell cell=sheet.getCell(i, j);
System.out.println(" "+cell.getContents());
}
The problem is because the excel data is not saved. I was also dealing with the same problem and got up with a different solution which worked for me. I just created a macro in excel to save the excel workbook whenever it's cell values got changed. Now I got the excel file with up-to-date saved data which can be read through java code and can be used for other purposes.
I'll post my macro code and java code which I used to retrieve the data from excel,
Macro Code
Java Code
The next step you need to know is how to create a macro and save it so that at next restart of excel application your macro will be working fine without any user intervention.
Your excel file will be already present inside the above mentioned location. Now I'll explain each step to proceed further in MS Excel 2007.
But this will lead to performance issue because the saving process will be performed at each cell change.