@Overridepublic void adjustExcleColumnPosition(String filePath,int col) throwsException{
File file=newFile(filePath);
InputStream inputStream=newFileInputStream(file);
HSSFWorkbook workBook=newHSSFWorkbook(inputStream);
HSSFSheet firstSheet=workBook.getSheetAt(0);for(int i=0;i<=firstSheet.getLastRowNum();i++){
HSSFRow row=firstSheet.getRow(i);//记录每行第一列 数据
String firstCellValue=row.getCell(0).getStringCellValue();for(int j=0;j
HSSFCell currentCell=row.getCell(j);if(null ==currentCell){
currentCell=row.createCell(j);
}if(j==col-1){//如果是最后一列了 把合同附件名称和编号 放到最后 循环下一行
currentCell.setCellValue(firstCellValue);continue;
}
HSSFCell nextCell=row.getCell(j+1);if(null ==nextCell){
nextCell=row.createCell(j+1);
}
String nextCellValue=nextCell.getStringCellValue();
currentCell.setCellValue(nextCellValue);
}
}for(int i=0;i<=firstSheet.getLastRowNum();i++){
HSSFRow row=firstSheet.getRow(i);
HSSFCell firstCell=row.getCell(0);
HSSFCell lastCell=row.getCell(col-1);
String firstCellValue=firstCell.getStringCellValue();
String lastCellValue=lastCell.getStringCellValue();if(null!=firstCellValue&&null!=lastCellValue){
System.out.println(firstCellValue+"----"+lastCellValue);
}
}
ByteArrayOutputStream outByte=newByteArrayOutputStream();
workBook.write(outByte);byte[] contents=outByte.toByteArray();
InputStream ins=newByteArrayInputStream(contents);
OutputStream out= newFileOutputStream(file);int bytesRead = 0;byte[] buffer = new byte[8192];while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
out.write(buffer,0, bytesRead);
}
out.close();
ins.close();
}