您好我正在从Excel中的单元格中读取实时值。这些值来自Siemens S7 plc。如果它们进展得足够慢,我可以得到它们。例如,如果我选择一个保存分钟的单元格,则在读取时会正确更新。但是,当我查看包含秒的单元格时,它每30秒才会更新一次。我总是得到15或45.我有没有办法每秒钟获得细胞内容?
public static void main(String[] args) throws InterruptedException {
try {
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename));
HSSFWorkbook hssfworkbook = new HSSFWorkbook(fs);
HSSFSheet sheet = hssfworkbook.getSheetAt(0);
HSSFCell currentStateCell=null;
HSSFRow currentRow = sheet.getRow(34);
currentStateCell = currentRow.getCell(0);
while(true) {
Thread.sleep(800);
fs = new POIFSFileSystem(new FileInputStream(filename));
hssfworkbook = new HSSFWorkbook(fs);
sheet = hssfworkbook.getSheetAt(0);
//this row contains the seconds cell(cell A,33)
currentRow = sheet.getRow(33);
currentStateCell = currentRow.getCell(0);
//this print out willgive me either 15.0 or 45.0 I want 1:60
System.out.println(currentStateCell.getNumericCellValue());
}} catch (IOException ex) {
Logger.getLogger(ReadExcelExample.class.getName()).log(Level.SEVERE, null, ex);
}
}
}