Example usage for org.apache.poi.ss.usermodel Sheet getLeftCol

List of usage examples for org.apache.poi.ss.usermodel Sheet getLeftCol

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Sheet getLeftCol.

Prototype

short getLeftCol();

Source Link

Document

The left col in the visible view when the sheet is first viewed after opening it in a viewer

Usage

From source file:CreateExcel.java

public static void add_column() throws FileNotFoundException, IOException {
    String excelFilePath = "C:\\Users\\aryan_000\\Desktop\\output.xlsx";
    FileOutputStream outputStream = new FileOutputStream(new File(excelFilePath));
    FileInputStream inputStream = new FileInputStream(new File(excelFilePath));
    Workbook wbout = new XSSFWorkbook();
    Workbook wbin = new XSSFWorkbook(inputStream);
    Sheet firstsheet = wbin.getSheetAt(0);

    XSSFSheet sheet = (XSSFSheet) wbout.createSheet("version 1");

    int max_row = firstsheet.getLastRowNum();
    for (int i = 0; i < max_row; i++) {
        Row row = sheet.createRow(i);//w w w  .j  av  a 2  s . c  o m

        for (int j = 0; j < firstsheet.getLeftCol(); j++) {
            //                String str = firstsheet.get
            //                Cell col = row.createCell(j).setCellValue(firstsheet.getRow(i).getCell(j).getStringCellValue());
        }
    }
}

From source file:org.tiefaces.components.websheet.configuration.ConfigurationHandler.java

License:MIT License

/**
 * Gets the sheet configuration./*from www . ja  va  2 s  . c o  m*/
 *
 * @param sheet
 *            the sheet
 * @param formName
 *            the form name
 * @param sheetRightCol
 *            the sheet right col
 * @return the sheet configuration
 */
private SheetConfiguration getSheetConfiguration(final Sheet sheet, final String formName,
        final int sheetRightCol) {

    SheetConfiguration sheetConfig = new SheetConfiguration();
    sheetConfig.setFormName(formName);
    sheetConfig.setSheetName(sheet.getSheetName());
    int leftCol = sheet.getLeftCol();
    int lastRow = sheet.getLastRowNum();
    int firstRow = sheet.getFirstRowNum();
    int rightCol = 0;
    int maxRow = 0;
    for (Row row : sheet) {
        if (row.getRowNum() > TieConstants.TIE_WEB_SHEET_MAX_ROWS) {
            break;
        }
        maxRow = row.getRowNum();
        int firstCellNum = row.getFirstCellNum();
        if (firstCellNum >= 0 && firstCellNum < leftCol) {
            leftCol = firstCellNum;
        }
        if ((row.getLastCellNum() - 1) > rightCol) {
            int verifiedcol = verifyLastCell(row, rightCol, sheetRightCol);
            if (verifiedcol > rightCol) {
                rightCol = verifiedcol;
            }
        }
    }
    if (maxRow < lastRow) {
        lastRow = maxRow;
    }
    // header range row set to 0 while column set to first column to
    // max
    // column (FF) e.g. $A$0 : $FF$0
    String tempStr = TieConstants.CELL_ADDR_PRE_FIX + WebSheetUtility.getExcelColumnName(leftCol)
            + TieConstants.CELL_ADDR_PRE_FIX + "0 : " + TieConstants.CELL_ADDR_PRE_FIX
            + WebSheetUtility.getExcelColumnName(rightCol) + TieConstants.CELL_ADDR_PRE_FIX + "0";
    sheetConfig.setFormHeaderRange(tempStr);
    sheetConfig.setHeaderCellRange(new CellRange(tempStr));
    // body range row set to first row to last row while column set
    // to
    // first column to max column (FF) e.g. $A$1 : $FF$1000
    tempStr = TieConstants.CELL_ADDR_PRE_FIX + WebSheetUtility.getExcelColumnName(leftCol)
            + TieConstants.CELL_ADDR_PRE_FIX + (firstRow + 1) + " : " + TieConstants.CELL_ADDR_PRE_FIX
            + WebSheetUtility.getExcelColumnName(rightCol) + TieConstants.CELL_ADDR_PRE_FIX + (lastRow + 1);
    sheetConfig.setFormBodyRange(tempStr);
    sheetConfig.setBodyCellRange(new CellRange(tempStr));
    sheetConfig.setFormBodyType(org.tiefaces.common.TieConstants.FORM_TYPE_FREE);
    sheetConfig.setCellFormAttributes(new HashMap<String, List<CellFormAttributes>>());

    // check it's a hidden sheet
    int sheetIndex = parent.getWb().getSheetIndex(sheet);
    if (parent.getWb().isSheetHidden(sheetIndex) || parent.getWb().isSheetVeryHidden(sheetIndex)) {
        sheetConfig.setHidden(true);
    }

    return sheetConfig;

}