我想从特定的行号读取Excel表格,只想要一些特定的列值。我尝试了很多东西,但是我没有按预期获得正确的输出。 以下是我的代码段:
public class ReadExcel {
File src=new File("F:\\ucd\\UAT_Patch_31012018.xlsx");
XSSFWorkbook wb;
XSSFSheet Sheet1;
FileOutputStream fileOut;
public void ReadExcel1() throws Exception{
FileInputStream fis = new FileInputStream(src);
XSSFWorkbook wb=new XSSFWorkbook(fis);
XSSFSheet Sheet1=wb.getSheetAt(0);
int rowcount=Sheet1.getPhysicalNumberOfRows();
int colcount=Sheet1.getRow(0).getPhysicalNumberOfCells();
for(int i=6;i<=9;i++){
for(int j=0;j<=rowcount;j++){
String testdata1=Sheet1.getRow(i).getCell(j).getStringCellValue();
System.out.println(testdata1);
}
}
}
public static void main(String args[]) throws Exception{
ReadExcel read=new ReadExcel();
read.ReadExcel1();
}
}
Excel文件格式:
File Name Target Server Target Path
abc/Abc.txt 10.0.43.101 /home/urbancode/UrbanCode/Test/DeployableComponent/abc
pqr/Abc.txt /home/urbancode/UrbanCode/Test/DeployableComponent/pqr
xyz/Abc.txt /home/urbancode/UrbanCode/Test/DeployableComponent/xyz
我想将输出保存在temp.txt文件中,如下所示:
abc/Abc.txt;/home/urbancode/UrbanCode/Test/DeployableComponent/abc
pqr/Abc.txt;/home/urbancode/UrbanCode/Test/DeployableComponent/pqr