Here is the answer to my question. Please refer this Sourcepublic Workbook readWorkBookAndWriteErrors(String bufId,String inputFile, String ext) throws Exception { Workbook workBook =null; Sheet sheet = null; if(GlobalVariables.EXCEL_FORMAT_XLS.equalsIgnoreCase(ext)){ // Get the workbook instance for XLS file workBook = new HSSFWorkbook(new FileInputStream(inputFile)); }else{ // Get the workbook instance for XLSX file workBook = new XSSFWorkbook(new FileInputStream(inputFile)); } sheet = workBook.getSheetAt(0); Row row = null; if(sheet.isColumnHidden(0)){ sheet.setColumnHidden(0, false); if(sheet instanceof XSSFSheet){ CTWorksheet ctWorksheet = null; CTSheetViews ctSheetViews = null; CTSheetView ctSheetView = null; XSSFSheet tempSheet = (XSSFSheet) sheet; // First step is to get at the CTWorksheet bean underlying the worksheet. ctWorksheet = tempSheet.getCTWorksheet(); // From the CTWorksheet, get at the sheet views. ctSheetViews = ctWorksheet.getSheetViews(); // Grab a single sheet view from that array ctSheetView = ctSheetViews.getSheetViewArray(ctSheetViews.sizeOfSheetViewArray() - 1); // Se the address of the top left hand cell. ctSheetView.setTopLeftCell("A1"); }else{ sheet.setActiveCell(new CellAddress("A1")); sheet.showInPane(0, 0); } Iterator<Row> rowIterator = sheet.iterator(); int rowIndex = 1; while (rowIterator.hasNext()) { row = rowIterator.next(); if(rowIndex == 1){ rowIndex++; continue; } Cell cell = row.createCell(0); cell.setCellValue("error message"); rowIndex++; } } return workBook; } 这篇关于有什么方法可以使用 POI 将工作表的水平滚动条向左移动一列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-29 19:57