上的Excel数据表执行操作有在excel表四列用java
- 我需要在三列执行操作和显示在第四个结果。
- Image with data in excel
- 如果我执行B9-D9,那么结果等于C9。
- 发生这种情况时,输出应为“匹配”。
我需要知道如何访问每个行和列并对其执行必要的操作。 看看你是否可以帮助我,让我知道是否需要任何额外的细节。
package com.infy; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Iterator; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class ReconMatch { public static void main(String[] args) throws IOException, FileNotFoundException{ // TODO Auto-generated method stub String excelFilePath ="C:/Users/akshay.kuchankar/Documents/demo.xlsx"; FileInputStream inputStream = new FileInputStream(new File(excelFilePath)); Workbook workbook = new XSSFWorkbook(inputStream); Sheet firstSheet = workbook.getSheetAt(0); Iterator<Row> iterator = firstSheet.iterator(); while (iterator.hasNext()) { Row nextRow = iterator.next(); Iterator<Cell> cellIterator = nextRow.cellIterator(); while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); //what should be the basic approach or the syntax to perform the operaiton?? } System.out.println(); } workbook.close(); inputStream.close(); } }
for(int i= 0; i<firstSheet.getRow(0).getCell(0).getNumericCellValue(); i++) { FGAmount = firstSheet.getRow(1).getCell(1).getNumericCellValue(); // System.out.println(FGAmount); difference = firstSheet.getRow(1).getCell(3).getNumericCellValue(); value = FGAmount + difference; } alconAmount = firstSheet.getRow(1).getCell(2).getNumericCellValue(); // result = firstSheet.getRow(1).getCell(4).getStringCellValue(); } } try { if(value== alconAmount){ firstSheet.getRow(1).getCell(4).setCellValue("Manual Matched"); System.out.println("matched"); } } catch (Exception e) { e.printStackTrace(); System.out.println(e); } // System.out.println(result); workbook.close(); inputStream.close();
请避免使用大写字母(这就像在图书馆里大喊大叫) – amonk
好吧...下次我不会再发生@agerom –