0
我想從Excel文件中讀取特定列數據並在具有附加數據的文本文件中搜索列的相關標題。我想用Java poi將這些細節打印回另一個excel文件。 我的數據是這樣的:從Excel中讀取數據並使用Java POI從文本文件中檢索相關數據並在另一個excel中顯示結果
Excel中:
Name Number
ABC 2345
XYZ 6789
文本文件:
Name|Class|School
ABC|1|bnm
XYZ|2|hjk
KOP|3|ert
我要在Excel輸出:
Name Class School
ABC 1 bnm
XYZ 2 hjk
public static void main(String[] args) throws Exception {
String filename = System.getProperty("D:/Files/Input.xslx");
List sheetData = new ArrayList();
String columnWanted = "Name";
Integer columnNo = null;
FileInputStream fis = null;
try {
fis = new FileInputStream(filename);
XSSFWorkbook workbook = new XSSFWorkbook(fis);
XSSFSheet sheet = workbook.getSheetAt(0);
Row firstRow = sheet.getRow(0);
for(Cell cell:firstRow){
if (cell.getStringCellValue().equals(columnWanted)){
columnNo = cell.getColumnIndex();
}
}
if (columnNo != null){
for (Row row : sheet) {
Cell c = row.getCell(columnNo);
if (c == null || c.getCellType() == Cell.CELL_TYPE_BLANK) {
// Nothing in the cell in this row, skip it
} else {
sheetData.add(c);
}
}System.out.println(sheetData);
}else{
System.out.println("could not find column ");
}
// Taking a new array list 'arr' for printing result data
List arr =new ArrayList();
File f=new File("D:/Files/Details.txt");
Scanner in=new Scanner(f);
System.out.println("Read Data From The Txt file ");
while(in.hasNext())
{
arr.add(in.nextLine());
}
System.out.println(arr);
}
catch (IOException e) {
e.printStackTrace();
} finally {
if (fis != null) {
fis.close();
}
}
}
}
I want help in searching Names in text file taking input from Input.xslx
我試圖檢索excel數據並將其保存到array.not能夠鏈接該數據並在文本文件中搜索 – user3382164
我的意思是:顯示我們的代碼.. –
我的答案中是否有足夠的信息?你需要進一步的指導嗎? –