Example usage for org.apache.poi.poifs.filesystem POIFSFileSystem POIFSFileSystem

List of usage examples for org.apache.poi.poifs.filesystem POIFSFileSystem POIFSFileSystem

Introduction

In this page you can find the example usage for org.apache.poi.poifs.filesystem POIFSFileSystem POIFSFileSystem.

Prototype


public POIFSFileSystem(InputStream stream) throws IOException 

Source Link

Document

Create a POIFSFileSystem from an InputStream.

Usage

From source file:com.nkapps.billing.services.BankStatementPrintServiceImpl.java

@Override
public HSSFWorkbook printRegister(List<PrintRegisterPojo> listPojo) throws Exception {
    HSSFWorkbook workbook = null;/*  w w w  .  jav  a  2s . c om*/

    POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(
            servletContext.getRealPath("templates") + File.separator + "print_register.xls"));
    workbook = new HSSFWorkbook(fs);
    HSSFSheet sheet = workbook.getSheetAt(0);
    // title
    //HSSFRow row = sheet.getRow(1);
    //HSSFCell cell = row.getCell(1);
    //String title;
    //cell.setCellValue(title);
    //
    HSSFRow row;
    final int CELL_START = 1;
    final int ROW_START = sheet.getLastRowNum() - 1;
    final int CELL_END = sheet.getRow(ROW_START).getLastCellNum();

    int rowCurrent = ROW_START, rowTotal = sheet.getLastRowNum(), cellCurrent;
    //
    HSSFCellStyle[] style = new HSSFCellStyle[CELL_END];
    short styleHeight = sheet.getRow(rowCurrent).getHeight();
    for (int i = CELL_START; i < CELL_END; i++) {
        style[i] = sheet.getRow(rowCurrent).getCell(i).getCellStyle();
    }

    // total style
    HSSFCellStyle[] totalStyle = new HSSFCellStyle[CELL_END];
    short totalStyleHeight = sheet.getRow(rowTotal).getHeight();
    for (int i = CELL_START; i < CELL_END; i++) {
        totalStyle[i] = sheet.getRow(rowTotal).getCell(i).getCellStyle();
    }

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
    int numQuantity = 0;
    for (PrintRegisterPojo prp : listPojo) {
        numQuantity++;

        row = sheet.createRow(rowCurrent++);
        row.setHeight(styleHeight);

        cellCurrent = CELL_START;
        createCell(row, cellCurrent++, style, prp.getInvoiceNum());
        createCell(row, cellCurrent++, style, prp.getPaymentNum());
        createCell(row, cellCurrent++, style, dateFormat.format(prp.getPaymentDate()));
        createCell(row, cellCurrent++, style, prp.getTin());
        createCell(row, cellCurrent++, style, prp.getName());
        createCell(row, cellCurrent++, style, prp.getPaymentSum());

    }
    List<Integer> totalCellIndexes = new ArrayList<>();
    totalCellIndexes.add(CELL_START + 5); // for payment sum columns
    createTotalCells(totalCellIndexes, sheet, totalStyle, totalStyleHeight, ROW_START, CELL_START, rowCurrent);

    return workbook;
}

From source file:com.nkapps.billing.services.BankStatementPrintServiceImpl.java

@Override
public HSSFWorkbook printClaimRegister(List<PrintClaimRegisterPojo> listPojo) throws Exception {
    HSSFWorkbook workbook = null;// w ww .  j  a va2 s.co m

    POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(
            servletContext.getRealPath("templates") + File.separator + "print_claim_register.xls"));
    workbook = new HSSFWorkbook(fs);
    HSSFSheet sheet = workbook.getSheetAt(0);
    // title
    //HSSFRow row = sheet.getRow(1);
    //HSSFCell cell = row.getCell(1);
    //String title;
    //cell.setCellValue(title);
    //
    HSSFRow row;
    final int CELL_START = 1;
    final int ROW_START = sheet.getLastRowNum() - 1;
    final int CELL_END = sheet.getRow(ROW_START).getLastCellNum();

    int rowCurrent = ROW_START, rowTotal = sheet.getLastRowNum(), cellCurrent;
    //
    HSSFCellStyle[] style = new HSSFCellStyle[CELL_END];
    short styleHeight = sheet.getRow(rowCurrent).getHeight();
    for (int i = CELL_START; i < CELL_END; i++) {
        style[i] = sheet.getRow(rowCurrent).getCell(i).getCellStyle();
    }

    // total style
    HSSFCellStyle[] totalStyle = new HSSFCellStyle[CELL_END];
    short totalStyleHeight = sheet.getRow(rowTotal).getHeight();
    for (int i = CELL_START; i < CELL_END; i++) {
        totalStyle[i] = sheet.getRow(rowTotal).getCell(i).getCellStyle();
    }

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
    int numQuantity = 0;
    for (PrintClaimRegisterPojo pcrp : listPojo) {
        numQuantity++;

        row = sheet.createRow(rowCurrent++);
        row.setHeight(styleHeight);

        cellCurrent = CELL_START;
        createCell(row, cellCurrent++, style, pcrp.getInvoiceNum());
        createCell(row, cellCurrent++, style, pcrp.getPaymentNum());
        createCell(row, cellCurrent++, style, dateFormat.format(pcrp.getPaymentDate()));
        createCell(row, cellCurrent++, style, pcrp.getTin());
        createCell(row, cellCurrent++, style, pcrp.getName());
        createCell(row, cellCurrent++, style, pcrp.getPaymentSum());

    }
    List<Integer> totalCellIndexes = new ArrayList<>();
    totalCellIndexes.add(CELL_START + 5); // for payment sum columns
    createTotalCells(totalCellIndexes, sheet, totalStyle, totalStyleHeight, ROW_START, CELL_START, rowCurrent);

    return workbook;
}

From source file:com.nkapps.billing.services.BankStatementPrintServiceImpl.java

@Override
public HSSFWorkbook printPaymentManual(BankStatement bs) throws Exception {
    HSSFWorkbook workbook = null;/*from  w  w  w  .  j  a  v  a  2  s.co m*/

    POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(
            servletContext.getRealPath("templates") + File.separator + "payment_manual.xls"));
    workbook = new HSSFWorkbook(fs);
    HSSFSheet sheet = workbook.getSheetAt(0);

    HSSFRow row = sheet.getRow(0);
    row.getCell(1).setCellValue(bs.getId());

    final int CELL_START = 1;
    final int ROW_START = sheet.getLastRowNum();
    final int CELL_END = sheet.getRow(ROW_START).getLastCellNum();

    int rowCurrent = ROW_START, cellCurrent;
    //
    HSSFCellStyle[] style = new HSSFCellStyle[CELL_END];
    short styleHeight = sheet.getRow(rowCurrent).getHeight();
    for (int i = CELL_START; i < CELL_END; i++) {
        style[i] = sheet.getRow(rowCurrent).getCell(i).getCellStyle();
    }

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
    row = sheet.createRow(3);

    createCell(row, 1, style, "");
    createCell(row, 2, style, bs.getMfo());
    createCell(row, 3, style, bs.getChet());
    createCell(row, 4, style, bs.getPaymentNum());
    createCell(row, 5, style, dateFormat.format(bs.getPaymentDate()));
    createCell(row, 6, style, "");
    createCell(row, 7, style, bs.getTin());

    return workbook;
}

From source file:com.nkapps.billing.services.PaymentServiceImpl.java

@Override
public void parseAndSavePaymentManual(File file, Long issuerSerialNumber, String issuerIp) throws Exception {
    FileInputStream fis = new FileInputStream(file);
    POIFSFileSystem fs = new POIFSFileSystem(fis);
    HSSFWorkbook workbook = new HSSFWorkbook(fs);
    HSSFSheet sheet = workbook.getSheetAt(0);

    String bankStatementId = null;
    List<Payment> paymentList = new LinkedList<Payment>();
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");

    int rowCurrent = 0, cellCurrent = 0;
    Iterator<Row> rowIterator = sheet.iterator();
    while (rowIterator.hasNext()) {
        rowCurrent++;//from w  ww  .  j av a2s.c  o m
        cellCurrent = 0;

        Row row = rowIterator.next();

        if (rowCurrent == 1) { // bank statement id
            bankStatementId = row.getCell(1).getStringCellValue();

        } else if (rowCurrent > 3) {
            Payment payment = new Payment();
            payment.setTin(row.getCell(1).getStringCellValue());
            payment.setPaymentNum(row.getCell(4).getStringCellValue());
            payment.setPaymentDate(dateFormat.parse(row.getCell(5).getStringCellValue()));
            payment.setPaymentSum(new BigDecimal(row.getCell(6).getNumericCellValue()));
            payment.setTinDebtor(row.getCell(7).getStringCellValue());
            payment.setSourceCode((short) 1);
            payment.setState((short) 1);
            payment.setClaim((short) 0);

            paymentList.add(payment);
        }
    }
    fis.close();

    paymentDao.savePaymentManual(bankStatementId, paymentList, issuerSerialNumber, issuerIp);

}

From source file:com.nkapps.billing.services.ReportPrintServiceImpl.java

@Override
public HSSFWorkbook printClick(List<ReportClickListPojo> listPojos) throws Exception {
    HSSFWorkbook workbook = null;//from   ww w  .  ja  v  a2s .  co m

    POIFSFileSystem fs = new POIFSFileSystem(
            new FileInputStream(servletContext.getRealPath("templates") + File.separator + "report_click.xls"));
    workbook = new HSSFWorkbook(fs);
    HSSFSheet sheet = workbook.getSheetAt(0);
    // title
    //HSSFRow row = sheet.getRow(1);
    //HSSFCell cell = row.getCell(1);
    //String title;
    //cell.setCellValue(title);
    //
    HSSFRow row;
    final int CELL_START = 1;
    final int ROW_START = sheet.getLastRowNum() - 1;
    final int CELL_END = sheet.getRow(ROW_START).getLastCellNum();

    int rowCurrent = ROW_START, rowTotal = sheet.getLastRowNum(), cellCurrent;
    //
    HSSFCellStyle[] style = new HSSFCellStyle[CELL_END];
    short styleHeight = sheet.getRow(rowCurrent).getHeight();
    for (int i = CELL_START; i < CELL_END; i++) {
        style[i] = sheet.getRow(rowCurrent).getCell(i).getCellStyle();
    }

    // total style
    HSSFCellStyle[] totalStyle = new HSSFCellStyle[CELL_END];
    short totalStyleHeight = sheet.getRow(rowTotal).getHeight();
    for (int i = CELL_START; i < CELL_END; i++) {
        totalStyle[i] = sheet.getRow(rowTotal).getCell(i).getCellStyle();
    }

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
    int numQuantity = 0;
    for (ReportClickListPojo rclp : listPojos) {
        numQuantity++;

        row = sheet.createRow(rowCurrent++);
        row.setHeight(styleHeight);

        cellCurrent = CELL_START;
        createCell(row, cellCurrent++, style, numQuantity);
        createCell(row, cellCurrent++, style, dateFormat.format(rclp.getOperationDate()));
        createCell(row, cellCurrent++, style, dateFormat.format(rclp.getBsPaymentDate()));
        createCell(row, cellCurrent++, style, rclp.getBsPaymentNum());
        createCell(row, cellCurrent++, style, rclp.getBsPaymentSum());
        createCell(row, cellCurrent++, style, rclp.getClickPaymentSum());
        createCell(row, cellCurrent++, style, rclp.getDiffSum());
    }
    List<Integer> totalCellIndexes = new ArrayList<>();
    totalCellIndexes.add(CELL_START + 4); // for 
    totalCellIndexes.add(CELL_START + 5); // for 
    totalCellIndexes.add(CELL_START + 6); // for 
    createTotalCells(totalCellIndexes, sheet, totalStyle, totalStyleHeight, ROW_START, CELL_START, rowCurrent);

    return workbook;
}

From source file:com.nkapps.billing.services.ReportPrintServiceImpl.java

@Override
public HSSFWorkbook printSmst(List<ReportSmstListPojo> listPojos) throws Exception {
    HSSFWorkbook workbook = null;//from ww w  .  j  a  v  a  2s .  c  o  m

    POIFSFileSystem fs = new POIFSFileSystem(
            new FileInputStream(servletContext.getRealPath("templates") + File.separator + "report_smst.xls"));
    workbook = new HSSFWorkbook(fs);
    HSSFSheet sheet = workbook.getSheetAt(0);
    // title
    //HSSFRow row = sheet.getRow(1);
    //HSSFCell cell = row.getCell(1);
    //String title;
    //cell.setCellValue(title);
    //
    HSSFRow row;
    final int CELL_START = 1;
    final int ROW_START = sheet.getLastRowNum() - 1;
    final int CELL_END = sheet.getRow(ROW_START).getLastCellNum();

    int rowCurrent = ROW_START, rowTotal = sheet.getLastRowNum(), cellCurrent;
    //
    HSSFCellStyle[] style = new HSSFCellStyle[CELL_END];
    short styleHeight = sheet.getRow(rowCurrent).getHeight();
    for (int i = CELL_START; i < CELL_END; i++) {
        style[i] = sheet.getRow(rowCurrent).getCell(i).getCellStyle();
    }

    // total style
    HSSFCellStyle[] totalStyle = new HSSFCellStyle[CELL_END];
    short totalStyleHeight = sheet.getRow(rowTotal).getHeight();
    for (int i = CELL_START; i < CELL_END; i++) {
        totalStyle[i] = sheet.getRow(rowTotal).getCell(i).getCellStyle();
    }

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
    int numQuantity = 0;
    for (ReportSmstListPojo rslp : listPojos) {
        numQuantity++;

        row = sheet.createRow(rowCurrent++);
        row.setHeight(styleHeight);

        cellCurrent = CELL_START;
        createCell(row, cellCurrent++, style, numQuantity);
        createCell(row, cellCurrent++, style, dateFormat.format(rslp.getOperationDate()));
        createCell(row, cellCurrent++, style, rslp.getBsPaymentSum());
        createCell(row, cellCurrent++, style, rslp.getSmstPaymentSum());
        createCell(row, cellCurrent++, style, rslp.getDiffSum());
    }
    List<Integer> totalCellIndexes = new ArrayList<>();
    totalCellIndexes.add(CELL_START + 2); // for 
    totalCellIndexes.add(CELL_START + 3); // for 
    totalCellIndexes.add(CELL_START + 4); // for 
    createTotalCells(totalCellIndexes, sheet, totalStyle, totalStyleHeight, ROW_START, CELL_START, rowCurrent);

    return workbook;
}

From source file:com.norconex.importer.parser.impl.quattro.QPWTextExtractor.java

License:Apache License

public void extract(InputStream input, Writer out, ImporterMetadata metadata) throws IOException {
    //TODO shall we validate and throw warning/error if the file does not 
    //start with a BOF and ends with a EOF?
    try (WPInputStream in = new WPInputStream(
            new POIFSFileSystem(input).createDocumentInputStream(OLE_DOCUMENT_NAME))) {
        Context ctx = new Context(in, out, metadata);
        while (hasNext(in)) {
            ctx.type = in.readWPShort();
            ctx.bodyLength = in.readWPShort();
            Extractor extractor = EXTRACTORS.get(ctx.type);
            if (extractor != null) {
                extractor.extract(ctx);/*from w  ww.  j a  v  a  2  s  . c  o  m*/
            } else {
                Extractor.IGNORE.extract(ctx);
            }
        }
    }
}

From source file:com.oneis.graphics.ThumbnailFinder.java

License:Mozilla Public License

/**
 * Try and get a thumbnail from an old Microsoft Office document
 *///from  www .  j a v  a2  s.c  om
private void findFromOldMSOffice() {
    try {
        File poiFilesystem = new File(inFilename);

        // Open the POI filesystem.
        InputStream is = new FileInputStream(poiFilesystem);
        POIFSFileSystem poifs = new POIFSFileSystem(is);
        is.close();

        // Read the summary information.
        DirectoryEntry dir = poifs.getRoot();
        DocumentEntry siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
        DocumentInputStream dis = new DocumentInputStream(siEntry);
        PropertySet ps = new PropertySet(dis);
        dis.close();
        SummaryInformation si = new SummaryInformation(ps);
        if (si != null) {
            byte[] thumbnailData = si.getThumbnail();
            if (thumbnailData != null) {
                Thumbnail thumbnail = new Thumbnail(thumbnailData);
                byte[] wmf = thumbnail.getThumbnailAsWMF();
                // Got something!
                thumbnailDimensions = tryWMFFormat(new ByteArrayInputStream(wmf), outFilename, outFormat,
                        maxDimension);
            }
        }
    } catch (Exception e) {
        logIgnoredException("ThumbnailFinder Apache POI file reading failed", e);
    }
}

From source file:com.openkm.extractor.MsExcelTextExtractor.java

License:Open Source License

/**
 * {@inheritDoc}//w  w  w.  j  a  va  2s  . co  m
 */
public String extractText(InputStream stream, String type, String encoding) throws IOException {
    try {
        POIFSFileSystem fs = new POIFSFileSystem(stream);
        return new ExcelExtractor(fs).getText();
    } catch (RuntimeException e) {
        logger.warn("Failed to extract Excel text content", e);
        throw new IOException(e.getMessage(), e);
    } finally {
        stream.close();
    }
}

From source file:com.openkm.util.metadata.MetadataExtractor.java

License:Open Source License

/**
 * Extract metadata from Office Word//from   w ww .  ja  v a 2  s .c o m
 */
public static OfficeMetadata officeExtractor(InputStream is, String mimeType) throws IOException {
    POIFSFileSystem fs = new POIFSFileSystem(is);
    OfficeMetadata md = new OfficeMetadata();
    SummaryInformation si = null;

    if (MimeTypeConfig.MIME_MS_WORD.equals(mimeType)) {
        si = new WordExtractor(fs).getSummaryInformation();
    } else if (MimeTypeConfig.MIME_MS_EXCEL.equals(mimeType)) {
        si = new ExcelExtractor(fs).getSummaryInformation();
    } else if (MimeTypeConfig.MIME_MS_POWERPOINT.equals(mimeType)) {
        si = new PowerPointExtractor(fs).getSummaryInformation();
    }

    if (si != null) {
        md.setTitle(si.getTitle());
        md.setSubject(si.getSubject());
        md.setAuthor(si.getAuthor());
        md.setLastAuthor(si.getLastAuthor());
        md.setKeywords(si.getKeywords());
        md.setComments(si.getComments());
        md.setTemplate(si.getTemplate());
        md.setRevNumber(si.getRevNumber());
        md.setApplicationName(si.getApplicationName());
        md.setEditTime(si.getEditTime());
        md.setPageCount(si.getPageCount());
        md.setWordCount(si.getWordCount());
        md.setCharCount(si.getCharCount());
        md.setSecurity(si.getSecurity());

        Calendar createDateTime = Calendar.getInstance();
        createDateTime.setTime(si.getCreateDateTime());
        md.setCreateDateTime(createDateTime);

        Calendar lastSaveDateTime = Calendar.getInstance();
        lastSaveDateTime.setTime(si.getLastSaveDateTime());
        md.setLastSaveDateTime(lastSaveDateTime);

        Calendar lastPrinted = Calendar.getInstance();
        lastPrinted.setTime(si.getLastPrinted());
        md.setLastPrinted(lastPrinted);
    }

    log.info("officeExtractor: {}", md);
    return md;
}