Example usage for org.apache.poi.ss.usermodel Workbook getSheetAt

List of usage examples for org.apache.poi.ss.usermodel Workbook getSheetAt

Introduction

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

Prototype

Sheet getSheetAt(int index);

Source Link

Document

Get the Sheet object at the given index.

Usage

From source file:com.crimelab.service.FirearmsServiceImpl.java

@Override
public Workbook create(Firearms firearms, HttpSession session) {
    Workbook wb = null;

    try {//w  ww  . ja  v  a2 s . c o  m
        InputStream inp = session.getServletContext().getResourceAsStream("/WEB-INF/templates/Default.xls");
        wb = WorkbookFactory.create(inp);
        Sheet sheet = wb.getSheetAt(0);

        Cell division = findCell(sheet, "$division");
        Cell reportNo = findCell(sheet, "$reportNo");
        Cell caseType = findCell(sheet, "$caseType");
        Cell suspect = findCell(sheet, "$suspect");
        Cell victim = findCell(sheet, "$victim");
        Cell timeDateReceived = findCell(sheet, "$timeDateReceived");
        Cell requestingParty = findCell(sheet, "$requestingParty");
        Cell specimenSubmitted = findCell(sheet, "$specimenSubmitted");
        Cell purposeOfLabExam = findCell(sheet, "$purposeOfLabExam");
        Cell findings = findCell(sheet, "$findings");
        Cell conclusion = findCell(sheet, "$conclusion");
        Cell remarks = findCell(sheet, "$remarks");
        Cell timeDateCompleted = findCell(sheet, "$timeDateCompleted");
        Cell examinerName = findCell(sheet, "$examinerName");
        Cell examinerRank = findCell(sheet, "$examinerRank");
        Cell examinerPosition = findCell(sheet, "$examinerPosition");
        Cell notedName = findCell(sheet, "$notedName");
        Cell notedRank = findCell(sheet, "$notedRank");
        Cell notedPosition = findCell(sheet, "$notedPosition");

        division.setCellValue(firearms.getDivision());
        reportNo.setCellValue(firearms.getReportNo());
        caseType.setCellValue(firearms.getCaseType());
        suspect.setCellValue(firearms.getSuspect());
        victim.setCellValue(firearms.getVictim());
        timeDateReceived.setCellValue(firearms.getTimeDateReceived());
        requestingParty.setCellValue(firearms.getRequestingParty());
        specimenSubmitted.setCellValue(firearms.getSpecimenSubmitted());
        purposeOfLabExam.setCellValue(firearms.getPurposeOfLabExam());
        findings.setCellValue(firearms.getFindings());
        conclusion.setCellValue(firearms.getConclusion());
        remarks.setCellValue(firearms.getRemarks());
        timeDateCompleted.setCellValue(firearms.getTimeDateCompleted());
        examinerName.setCellValue(firearms.getExaminerName());
        examinerRank.setCellValue(firearms.getExaminerRank());
        examinerPosition.setCellValue(firearms.getExaminerPosition());
        notedName.setCellValue(firearms.getNotedName());
        notedRank.setCellValue(firearms.getNotedRank());
        notedPosition.setCellValue(firearms.getNotedPosition());
        firearmsDAO.firearmsInfo(firearms);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return wb;
}

From source file:com.crimelab.service.FirearmsServiceImpl.java

@Override
public Workbook createFirearmsCases(HttpSession session, String month) {
    Workbook wb = null;

    try {/*from   w w w . ja v  a 2  s.c o m*/
        InputStream inp = session.getServletContext()
                .getResourceAsStream("/WEB-INF/templates/FirearmsCases.xls");
        wb = WorkbookFactory.create(inp);
        Sheet sheet = wb.getSheetAt(0);
        CellStyle cs1 = wb.createCellStyle();
        CellStyle cs2 = wb.createCellStyle();
        CellStyle bl = wb.createCellStyle();
        CellStyle br = wb.createCellStyle();
        CellStyle bt = wb.createCellStyle();
        CellStyle bb = wb.createCellStyle();
        cs1.setWrapText(true);
        cs2.setAlignment(ALIGN_CENTER);
        bt.setBorderTop(BORDER_THIN);
        bb.setBorderBottom(BORDER_THIN);
        bl.setBorderLeft(BORDER_THIN);
        br.setBorderRight(BORDER_THIN);

        Row intro1 = sheet.createRow(9);
        Cell in1 = intro1.createCell(0);
        in1.setCellValue("Period Covered:");
        in1.setCellStyle(cs1);
        in1.setCellStyle(cs2);

        Row intro2 = sheet.createRow(10);
        Cell in2 = intro2.createCell(0);
        in1.setCellValue(month.split("-")[0]);
        in1.setCellStyle(cs1);
        in1.setCellStyle(cs2);

        int ctr = 12; //initial
        Row row = sheet.createRow(ctr);
        month = month.split("-")[1];

        //JOptionPane.showMessageDialog(null, firearmsDAO.getAllFirearms(month));
        for (Firearms firearms : firearmsDAO.getAllFirearms(month)) {
            //JOptionPane.showMessageDialog(null, firearms.getReportNo());
            Cell cell0 = row.createCell(0);
            cell0.setCellValue(firearms.getReportNo());
            cell0.setCellStyle(bt);
            cell0.setCellStyle(bb);
            cell0.setCellStyle(bl);
            cell0.setCellStyle(br);

            Cell cell1 = row.createCell(1);//.setCellValue(firearms.getReportNo());
            cell1.setCellValue(firearms.getExaminerName());
            cell1.setCellStyle(bt);
            cell1.setCellStyle(bb);
            cell1.setCellStyle(bl);
            cell1.setCellStyle(br);

            Cell cell2 = row.createCell(2);//.setCellValue(firearms.getRequestingParty());
            cell2.setCellValue(firearms.getCaseType());
            cell2.setCellStyle(bt);
            cell2.setCellStyle(bb);
            cell2.setCellStyle(bl);
            cell2.setCellStyle(br);

            Cell cell3 = row.createCell(3);//.setCellValue(firearms.getDescriptionOfEvidence());
            cell3.setCellValue(firearms.getVictim());
            cell2.setCellStyle(bt);
            cell2.setCellStyle(bb);
            cell3.setCellStyle(bl);
            cell3.setCellStyle(br);

            Cell cell4 = row.createCell(4);//.setCellValue(firearms.getSpecimenWeight());
            cell4.setCellValue(firearms.getSuspect());
            cell4.setCellStyle(bt);
            cell4.setCellStyle(bb);
            cell4.setCellStyle(bl);
            cell4.setCellStyle(br);

            Cell cell5 = row.createCell(5);//.setCellValue(firearms.getCustody());
            cell5.setCellValue(firearms.getTimeDateIncident());
            cell5.setCellStyle(bt);
            cell5.setCellStyle(bb);
            cell5.setCellStyle(bl);
            cell5.setCellStyle(br);

            Cell cell6 = row.createCell(6);//.setCellValue(firearms.getSuspects());
            cell6.setCellValue(firearms.getPlaceOfIncident());
            cell6.setCellStyle(bt);
            cell6.setCellStyle(bb);
            cell6.setCellStyle(bl);
            cell6.setCellStyle(br);

            Cell cell7 = row.createCell(7);//.setCellValue(firearms.getTypeOfOperation());
            cell7.setCellValue(firearms.getRequestingParty());
            cell7.setCellStyle(bt);
            cell7.setCellStyle(bb);
            cell7.setCellStyle(bl);
            cell7.setCellStyle(br);

            Cell cell8 = row.createCell(8);//.setCellValue(firearms.getPlaceOfOperation());
            cell8.setCellValue(firearms.getInvestigator());
            cell8.setCellStyle(bt);
            cell8.setCellStyle(bb);
            cell8.setCellStyle(bl);
            cell8.setCellStyle(br);

            Cell cell9 = row.createCell(9);//.setCellValue(firearms.getPlaceOfOperation());
            cell9.setCellValue(firearms.getCaseStatus());
            cell9.setCellStyle(bt);
            cell9.setCellStyle(bb);
            cell9.setCellStyle(bl);
            cell9.setCellStyle(br);

            row = sheet.createRow(ctr += 1);

            return wb;
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return wb;
}

From source file:com.crimelab.service.MacroEtchingServiceImpl.java

@Override
public Workbook create(MacroEtching macroEtching, HttpSession session) {
    Workbook wb = null;
    try {//from  www . j a  v a  2s  .co  m
        InputStream inp = session.getServletContext().getResourceAsStream("/WEB-INF/templates/meCert.xls");
        wb = WorkbookFactory.create(inp);
        Sheet sheet = wb.getSheetAt(0);

        Cell dateCreated = findCell(sheet, "$dateCreated");
        Cell rclo = findCell(sheet, "$rclo");
        Cell make = findCell(sheet, "$make");
        Cell color = findCell(sheet, "$color");
        Cell plateNo = findCell(sheet, "$plateNo");
        Cell engineNo = findCell(sheet, "$engineNo");
        Cell chassisNo = findCell(sheet, "$chassisNo");
        Cell eNo = findCell(sheet, "$eNo");
        Cell cNo = findCell(sheet, "$cNo");
        Cell owner = findCell(sheet, "$owner");
        Cell address = findCell(sheet, "$address");
        Cell appName = findCell(sheet, "$appName");
        Cell appRank = findCell(sheet, "$appRank");
        Cell appPosition = findCell(sheet, "$appPosition");
        Cell examinerName = findCell(sheet, "$examinerName");
        Cell examinerRank = findCell(sheet, "$examinerRank");
        Cell examinerPosition = findCell(sheet, "$examinerPosition");

        dateCreated.setCellValue(macroEtching.getDateCreated());
        rclo.setCellValue(macroEtching.getRclo());
        make.setCellValue(macroEtching.getMake());
        color.setCellValue(macroEtching.getColor());
        plateNo.setCellValue(macroEtching.getPlateNo());
        engineNo.setCellValue(macroEtching.getEngineNo());
        chassisNo.setCellValue(macroEtching.getChassisNo());
        eNo.setCellValue(macroEtching.getEngineNo());
        cNo.setCellValue(macroEtching.getChassisNo());
        owner.setCellValue(macroEtching.getOwner());
        address.setCellValue(macroEtching.getAddress());
        appName.setCellValue(macroEtching.getAppName());
        appRank.setCellValue(macroEtching.getAppRank());
        appPosition.setCellValue(macroEtching.getAppPosition());
        examinerName.setCellValue(macroEtching.getExaminerName());
        examinerRank.setCellValue(macroEtching.getExaminerRank());
        examinerPosition.setCellValue(macroEtching.getExaminerPosition());

        macroEtchingDAO.macroEtchingInfo(macroEtching);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return wb;
}

From source file:com.crimelab.service.MedicoLegalServiceImpl.java

@Override
public Workbook create(MedicoLegal medicoLegal, HttpSession session) {
    Workbook wb = null;

    try {/*from  w  w w . j ava 2 s  .  co  m*/
        InputStream inp = session.getServletContext().getResourceAsStream("/WEB-INF/templates/Default.xls");
        wb = WorkbookFactory.create(inp);
        Sheet sheet = wb.getSheetAt(0);

        Cell division = findCell(sheet, "$division");
        Cell reportNo = findCell(sheet, "$reportNo");
        Cell caseType = findCell(sheet, "$caseType");
        Cell suspect = findCell(sheet, "$suspect");
        Cell victim = findCell(sheet, "$victim");
        Cell timeDateReceived = findCell(sheet, "$timeDateReceived");
        Cell requestingParty = findCell(sheet, "$requestingParty");
        Cell specimenSubmitted = findCell(sheet, "$specimenSubmitted");
        Cell purposeOfLabExam = findCell(sheet, "$purposeOfLabExam");
        Cell findings = findCell(sheet, "$findings");
        Cell conclusion = findCell(sheet, "$conclusion");
        Cell remarks = findCell(sheet, "$remarks");
        Cell timeDateCompleted = findCell(sheet, "$timeDateCompleted");
        Cell examinerName = findCell(sheet, "$examinerName");
        Cell examinerRank = findCell(sheet, "$examinerRank");
        Cell examinerPosition = findCell(sheet, "$examinerPosition");
        Cell notedName = findCell(sheet, "$notedName");
        Cell notedRank = findCell(sheet, "$notedRank");
        Cell notedPosition = findCell(sheet, "$notedPosition");

        division.setCellValue(medicoLegal.getDivision());
        reportNo.setCellValue(medicoLegal.getReportNo());
        caseType.setCellValue(medicoLegal.getCaseType());
        suspect.setCellValue(medicoLegal.getSuspect());
        victim.setCellValue(medicoLegal.getVictim());
        timeDateReceived.setCellValue(medicoLegal.getTimeDateReceived());
        requestingParty.setCellValue(medicoLegal.getRequestingParty());
        specimenSubmitted.setCellValue(medicoLegal.getSpecimenSubmitted());
        purposeOfLabExam.setCellValue(medicoLegal.getPurposeOfLabExam());
        findings.setCellValue(medicoLegal.getFindings());
        conclusion.setCellValue(medicoLegal.getConclusion());
        remarks.setCellValue(medicoLegal.getRemarks());
        timeDateCompleted.setCellValue(medicoLegal.getTimeDateCompleted());
        examinerName.setCellValue(medicoLegal.getExaminerName());
        examinerRank.setCellValue(medicoLegal.getExaminerRank());
        examinerPosition.setCellValue(medicoLegal.getExaminerPosition());
        notedName.setCellValue(medicoLegal.getNotedName());
        notedRank.setCellValue(medicoLegal.getNotedRank());
        notedPosition.setCellValue(medicoLegal.getNotedPosition());

        medicoLegalDAO.medicoLegalInfo(medicoLegal);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return wb;
}

From source file:com.crimelab.service.MedicoLegalServiceImpl.java

@Override
public Workbook createMedicoMonthly(HttpSession session, String month) {
    Workbook wb = null;

    try {//from  w  ww . ja  v  a 2  s  . co m
        InputStream inp = session.getServletContext()
                .getResourceAsStream("/WEB-INF/templates/MedicoMonthly.xls");
        wb = WorkbookFactory.create(inp);
        Sheet sheet = wb.getSheetAt(0);
        CellStyle cs1 = wb.createCellStyle();
        CellStyle cs2 = wb.createCellStyle();
        CellStyle bl = wb.createCellStyle();
        CellStyle br = wb.createCellStyle();
        CellStyle bt = wb.createCellStyle();
        CellStyle bb = wb.createCellStyle();
        cs1.setWrapText(true);
        cs2.setAlignment(ALIGN_CENTER);
        bt.setBorderTop(BORDER_THIN);
        bb.setBorderBottom(BORDER_THIN);
        bl.setBorderLeft(BORDER_THIN);
        br.setBorderRight(BORDER_THIN);

        Row intro1 = sheet.createRow(9);
        Cell in1 = intro1.createCell(0);
        in1.setCellValue("Period Covered:");
        in1.setCellStyle(cs1);
        in1.setCellStyle(cs2);

        Row intro2 = sheet.createRow(10);
        Cell in2 = intro2.createCell(0);
        in1.setCellValue(month.split("-")[0]);
        in1.setCellStyle(cs1);
        in1.setCellStyle(cs2);

        int ctr = 12; //initial
        Row row = sheet.createRow(ctr);
        month = month.split("-")[1];

        //JOptionPane.showMessageDialog(null, medicoLegalDAO.getAllMedicoLegal(month));
        for (MedicoLegal medicoLegal : medicoLegalDAO.getAllMedicoLegal(month)) {
            //JOptionPane.showMessageDialog(null, medicoLegal.getReportNo());
            Cell cell0 = row.createCell(0);
            cell0.setCellValue(medicoLegal.getCaseNo());
            cell0.setCellStyle(bt);
            cell0.setCellStyle(bb);
            cell0.setCellStyle(bl);
            cell0.setCellStyle(br);

            Cell cell1 = row.createCell(1);//.setCellValue(medicoLegal.getReportNo());
            cell1.setCellValue(medicoLegal.getExaminerName());
            cell1.setCellStyle(bt);
            cell1.setCellStyle(bb);
            cell1.setCellStyle(bl);
            cell1.setCellStyle(br);

            Cell cell2 = row.createCell(2);//.setCellValue(medicoLegal.getRequestingParty());
            cell2.setCellValue(medicoLegal.getCaseType());
            cell2.setCellStyle(bt);
            cell2.setCellStyle(bb);
            cell2.setCellStyle(bl);
            cell2.setCellStyle(br);

            Cell cell3 = row.createCell(3);//.setCellValue(medicoLegal.getDescriptionOfEvidence());
            cell3.setCellValue(medicoLegal.getVictim());
            cell2.setCellStyle(bt);
            cell2.setCellStyle(bb);
            cell3.setCellStyle(bl);
            cell3.setCellStyle(br);

            Cell cell4 = row.createCell(4);//.setCellValue(medicoLegal.getSpecimenWeight());
            cell4.setCellValue(medicoLegal.getSuspect());
            cell4.setCellStyle(bt);
            cell4.setCellStyle(bb);
            cell4.setCellStyle(bl);
            cell4.setCellStyle(br);

            Cell cell5 = row.createCell(5);//.setCellValue(medicoLegal.getCustody());
            cell5.setCellValue(medicoLegal.getTimeDateReceived());
            cell5.setCellStyle(bt);
            cell5.setCellStyle(bb);
            cell5.setCellStyle(bl);
            cell5.setCellStyle(br);

            Cell cell6 = row.createCell(6);//.setCellValue(medicoLegal.getSuspects());
            cell6.setCellValue(medicoLegal.getFindings());
            cell6.setCellStyle(bt);
            cell6.setCellStyle(bb);
            cell6.setCellStyle(bl);
            cell6.setCellStyle(br);

            row = sheet.createRow(ctr += 1);

            return wb;
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return wb;
}

From source file:com.crimelab.service.PiServiceImpl.java

@Override
public Workbook create(PiReport piReport, HttpSession session) {
    Workbook wb = null;
    try {//ww w.j av a 2  s . c o m
        InputStream inp = session.getServletContext().getResourceAsStream("/WEB-INF/templates/Default.xls");
        wb = WorkbookFactory.create(inp);
        Sheet sheet = wb.getSheetAt(0);

        Cell examType = findCell(sheet, "$examType");
        Cell reportNo = findCell(sheet, "$reportNo");
        Cell caseType = findCell(sheet, "$caseType");
        Cell suspects = findCell(sheet, "$suspects");
        Cell victims = findCell(sheet, "$victims");
        Cell timeDateReceived = findCell(sheet, "$timeDateReceived");
        Cell requestingParty = findCell(sheet, "$requestingParty");
        Cell specimenSubmitted = findCell(sheet, "$specimenSubmitted");
        Cell purposeOfLabExam = findCell(sheet, "$purposeOfLabExam");
        Cell findings = findCell(sheet, "$findings");
        Cell conclusions = findCell(sheet, "$conclusions");
        Cell remarks = findCell(sheet, "$remarks");
        Cell timeDateCompleted = findCell(sheet, "$timeDateCompleted");
        Cell examinerName = findCell(sheet, "$examinerName");
        Cell examinerRank = findCell(sheet, "$examinerRank");
        Cell examinerPosition = findCell(sheet, "$examinerPosition");
        Cell appName = findCell(sheet, "$appName");
        Cell appRank = findCell(sheet, "$appRank");
        Cell appPosition = findCell(sheet, "$appPosition");
        Cell notedName = findCell(sheet, "$notedName");
        Cell notedRank = findCell(sheet, "$notedRank");
        Cell notedPosition = findCell(sheet, "$notedPosition");

        examType.setCellValue(piReport.getExamType());
        reportNo.setCellValue(piReport.getReportNo());
        caseType.setCellValue(piReport.getCaseType());
        suspects.setCellValue(piReport.getSuspects());
        victims.setCellValue(piReport.getVictims());
        timeDateReceived.setCellValue(piReport.getTimeDateReceived());
        requestingParty.setCellValue(piReport.getRequestingParty());
        specimenSubmitted.setCellValue(piReport.getSpecimenSubmitted());
        purposeOfLabExam.setCellValue(piReport.getPurposeOfLabExam());
        findings.setCellValue(piReport.getFindings());
        conclusions.setCellValue(piReport.getConclusions());
        remarks.setCellValue(piReport.getRemarks());
        timeDateCompleted.setCellValue(piReport.getTimeDateCompleted());
        examinerName.setCellValue(piReport.getExaminerName());
        examinerRank.setCellValue(piReport.getExaminerRank());
        examinerPosition.setCellValue(piReport.getExaminerPosition());
        appName.setCellValue(piReport.getAppName());
        appRank.setCellValue(piReport.getAppRank());
        appPosition.setCellValue(piReport.getAppPosition());
        notedName.setCellValue(piReport.getNotedName());
        notedRank.setCellValue(piReport.getNotedRank());
        notedPosition.setCellValue(piReport.getNotedPosition());

        piDAO.piReportInfo(piReport);
    } catch (Exception e) {
        e.printStackTrace();

    }
    return wb;
}

From source file:com.crimelab.service.QdServiceImpl.java

@Override
public Workbook create(Qd qd, HttpSession session) {
    Workbook wb = null;

    try {//from w w w .  j  a v a 2s .c o m
        InputStream inp = session.getServletContext().getResourceAsStream("/WEB-INF/templates/Default.xls");
        wb = WorkbookFactory.create(inp);
        Sheet sheet = wb.getSheetAt(0);

        Cell division = findCell(sheet, "$division");
        Cell reportNo = findCell(sheet, "$reportNo");
        Cell caseType = findCell(sheet, "$caseType");
        Cell suspect = findCell(sheet, "$suspect");
        Cell victim = findCell(sheet, "$victim");
        Cell timeDateReceived = findCell(sheet, "$timeDateReceived");
        Cell requestingParty = findCell(sheet, "$requestingParty");
        Cell specimenSubmitted = findCell(sheet, "$specimenSubmitted");
        Cell purposeOfLabExam = findCell(sheet, "$purposeOfLabExam");
        Cell findings = findCell(sheet, "$findings");
        Cell conclusion = findCell(sheet, "$conclusion");
        Cell remarks = findCell(sheet, "$remarks");
        Cell timeDateCompleted = findCell(sheet, "$timeDateCompleted");
        Cell examinerName = findCell(sheet, "$examinerName");
        Cell examinerRank = findCell(sheet, "$examinerRank");
        Cell examinerPosition = findCell(sheet, "$examinerPosition");
        Cell notedName = findCell(sheet, "$notedName");
        Cell notedRank = findCell(sheet, "$notedRank");
        Cell notedPosition = findCell(sheet, "$notedPosition");

        division.setCellValue(qd.getDivision());
        reportNo.setCellValue(qd.getReportNo());
        caseType.setCellValue(qd.getCaseType());
        suspect.setCellValue(qd.getSuspect());
        victim.setCellValue(qd.getVictim());
        timeDateReceived.setCellValue(qd.getTimeDateReceived());
        requestingParty.setCellValue(qd.getRequestingParty());
        specimenSubmitted.setCellValue(qd.getSpecimenSubmitted());
        purposeOfLabExam.setCellValue(qd.getPurposeOfLabExam());
        findings.setCellValue(qd.getFindings());
        conclusion.setCellValue(qd.getConclusion());
        remarks.setCellValue(qd.getRemarks());
        timeDateCompleted.setCellValue(qd.getTimeDateCompleted());
        examinerName.setCellValue(qd.getExaminerName());
        examinerRank.setCellValue(qd.getExaminerRank());
        examinerPosition.setCellValue(qd.getExaminerPosition());
        notedName.setCellValue(qd.getNotedName());
        notedRank.setCellValue(qd.getNotedRank());
        notedPosition.setCellValue(qd.getNotedPosition());

        qdDAO.qdInfo(qd);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return wb;
}

From source file:com.cx.test.FromHowTo.java

License:Apache License

public static void main(String[] args) throws Exception {
    Class[] clazz = new Class[] { String.class, String.class, String.class, String.class, Integer.class,
            String.class, String.class };
    InputStream stream = new FileInputStream(new File("C:\\Users\\Administrator\\Desktop\\menu.xlsx"));
    Workbook wb = new XSSFWorkbook(stream);
    Sheet sheet = wb.getSheetAt(0);
    int rows = sheet.getLastRowNum();
    int cells = sheet.getRow(0).getPhysicalNumberOfCells();
    for (int i = 0; i < rows; i++) {
        Row row = sheet.getRow(i + 1);// w  w w.j  av  a 2 s  .co  m
        for (int j = 0; j < cells; j++) {
            Cell cell = row.getCell(j);
            Object obj = null;
            if (cell != null) {
                obj = getCellValue(cell, clazz[j]);
            }
            switch (j) {
            case 0:
                System.out.println("000000000-----" + obj);
                break;
            case 1:
                System.out.println("1111111111111" + obj);
                break;
            default:
                break;
            }
        }
    }
}

From source file:com.dataart.spreadsheetanalytics.engine.ConverterUtils.java

License:Apache License

/**
 * Gets an instance of a Workbook ({@link ConverterUtils#newWorkbook(InputStream)}, creates copy of original file, 
 * clears all the cell values, but preserves formatting.
 *//*from  w w w  . j ava  2s  .  c  o m*/
static Workbook clearContent(final Workbook book) {
    ByteArrayOutputStream originalOut = new ByteArrayOutputStream();

    try {
        book.write(originalOut);
    } catch (IOException e) {
        throw new CalculationEngineException(e);
    }

    InputStream originalIn = new ByteArrayInputStream(copyOf(originalOut.toByteArray(), originalOut.size()));

    Workbook w = ConverterUtils.newWorkbook(originalIn);
    Sheet s = w.getSheetAt(0); //TODO: only one sheet is supported

    for (int i = s.getFirstRowNum(); i <= s.getLastRowNum(); i++) {
        Row r = s.getRow(i);
        if (r == null) {
            continue;
        }

        for (int j = r.getFirstCellNum(); j <= r.getLastCellNum(); j++) {
            Cell c = r.getCell(j);
            if (c == null) {
                continue;
            }

            c.setCellType(CELL_TYPE_BLANK);
        }
    }

    return w;
}

From source file:com.dataart.spreadsheetanalytics.engine.DataModelConverters.java

License:Apache License

/**
 * For given {@link Workbook} does convert everything to new {@link DataModel} structure.
 * Does copy all supported fields (for supported fields see {@link DataModel} class.
 *//* w  w w.j  a  v  a  2 s. c  o m*/
static IDataModel toDataModel(final Workbook workbook) {
    if (workbook == null) {
        return null;
    }

    //add custom functions information
    workbook.addToolPack(getUdfFinder());

    Sheet s = workbook.getSheetAt(0); //TODO: only one sheet is supported
    if (s == null) {
        return null;
    }

    IDataModel dm = new DataModel(s.getSheetName());

    for (int i = s.getFirstRowNum(); i <= s.getLastRowNum(); i++) {
        Row r = s.getRow(i);
        if (r == null) {
            continue;
        }

        DmRow row = new DmRow(i);
        dm.setRow(i, row);

        for (int j = r.getFirstCellNum(); j < r.getLastCellNum(); j++) {
            Cell c = r.getCell(j);
            if (c == null) {
                continue;
            }

            DmCell cell = new DmCell();
            row.setCell(j, cell);

            cell.setAddress(new CellAddress(dm.getDataModelId(), A1Address.fromRowColumn(i, j)));
            cell.setContent(ConverterUtils.resolveCellValue(c));
        }
    }

    EvaluationWorkbook evaluationWbook = ConverterUtils.newEvaluationWorkbook(workbook);

    for (int nIdx = 0; nIdx < workbook.getNumberOfNames(); nIdx++) {
        Name name = workbook.getNameAt(nIdx);

        String reference = name.getRefersToFormula();
        if (reference == null) {
            continue;
        }

        if (A1Address.isAddress(removeSheetFromNameRef(reference))) {
            dm.setNamedAddress(name.getNameName(), A1Address.fromA1Address(removeSheetFromNameRef(reference)));
        } else if (isFormula(reference, evaluationWbook)) {
            dm.setNamedValue(name.getNameName(), new CellValue(FORMULA_PREFIX + reference));
        } else {
            dm.setNamedValue(name.getNameName(), CellValue.from(reference));
        }
    }

    return dm;
}