Package org.apache.poi.hssf.usermodel

Examples of org.apache.poi.hssf.usermodel.HSSFSheet


    {

      protected void buildExcelDocument(Map model, HSSFWorkbook workbook, HttpServletRequest request,
          HttpServletResponse response) throws Exception
      {
        HSSFSheet sheet = workbook.createSheet("Spring Excel View");
        sheet.setDefaultColumnWidth((short) 12);

        // Write a text at A1.
        HSSFCell cell = getCell(sheet, 0, 0);
        setText(cell, "Spring Excel View Via Strecks");
View Full Code Here


         if(hssf != null && hssf2 != null) {
           // Check if the sheet count is same for both books
           if(hssf.getNumberOfSheets() == hssf2.getNumberOfSheets()) {
             // Iterate through the sheets
             for(int i=0;i<hssf.getNumberOfSheets();i++) {
               HSSFSheet sheet1 = hssf.getSheetAt(i);
               HSSFSheet sheet2 = hssf2.getSheetAt(i);
               // check if the sheet is not null
               if(sheet1 != null && sheet2 != null) {
                 int rowCount1 = sheet1.getLastRowNum();
                 int rowCount2 = sheet2.getLastRowNum();
                 // check if rows are the same for both books
                 if(rowCount1 == rowCount2) {
                   // iterate through the rows
                   for(int j=sheet1.getFirstRowNum();j<=rowCount1;j++) {
                     HSSFRow row1 = sheet1.getRow(j);
                     HSSFRow row2 = sheet2.getRow(j);
                     // check if the rows are not null
                     if(row1 != null && row2 != null) {
                         Iterator it1 = row1.cellIterator();
                         Iterator it2 = row2.cellIterator();
                         while(it1.hasNext() && it2.hasNext()) {
View Full Code Here

      }

      // Iterate through the sheets
      for (int i = 0; i < hssf.getNumberOfSheets(); i++)
      {
        HSSFSheet sheet1 = hssf.getSheetAt(i);
        HSSFSheet sheet2 = hssf2.getSheetAt(i);
        // check if the sheet is not null
        if (sheet1 == null || sheet2 == null)
        {
          equal = false;
          String dataToWrite = "One of the sheet is null" + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
          outputStream.write(dataToWrite.getBytes());
          continue;
        }

        int rowCount1 = sheet1.getLastRowNum();
        int rowCount2 = sheet2.getLastRowNum();
        // check if rows are the same for both books
        if (rowCount1 != rowCount2)
        {
          equal = false;
          continue;
View Full Code Here

    }

  if (oFile.getName().endsWith(".xls")) {
    FileInputStream oFistrm = new FileInputStream(oFile);
    HSSFWorkbook oWrkb = new HSSFWorkbook(oFistrm);
    HSSFSheet oSheet = oWrkb.getSheetAt(0);
    oFistrm.close();
    parseSheet(oSheet, sFileDescriptor);
  } else {

      cBuffer = new char[iBuffer];
View Full Code Here

    POIFSFileSystem poiFS = new POIFSFileSystem(new FileInputStream(new File(ifile)));
    HSSFWorkbook cworkBook = new HSSFWorkbook(poiFS);

    //*-- loop through the individual sheets and parse each one
    for (int i = 0; i < cworkBook.getNumberOfSheets(); i++)
    { HSSFSheet cSheet = cworkBook.getSheetAt(i);
    if (cSheet != null) { sheetText.append(" "); sheetText.append(extractText(cSheet)); }
    }
   } //*-- end of try block
   catch (OutOfMemoryError exc)
   { logger.error("Ran out of memory for " + ifile + " or could be corrupt file " + exc.getMessage()); }
View Full Code Here

   */
  public String[] readDescription() {
    if (workbook.getNumberOfSheets() < 1) {
      return new String[0];
    } else {
      HSSFSheet sheet = workbook.getSheetAt(0);
      return readLine(sheet, 0);
    }
  }
View Full Code Here

  public String[] readTitle() {
    if (workbook.getNumberOfSheets() < 1) {
      return new String[0];
    } else {
      HSSFSheet sheet = workbook.getSheetAt(0);
      String[] attrs = readLine(sheet, headIndex);
      attrCount = attrs.length;
      return attrs;
    }
  }
View Full Code Here

    logger.debug("has attrs {}", attrs);
    return attrs;
  }

  public Object read() {
    HSSFSheet sheet = workbook.getSheetAt(sheetNum);
    if (indexInSheet > sheet.getLastRowNum()) { return null; }
    HSSFRow row = sheet.getRow(indexInSheet);
    indexInSheet++;
    // 如果是个空行,返回空记录
    if (row == null) {
      return new Object[attrCount];
    } else {
View Full Code Here

import org.apache.poi.ss.usermodel.DataFormat;

public class PoiTest {
  public static void main(String[] args) throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("new sheet");

    // Create a row and put some cells in it. Rows are 0 based.
    HSSFRow row = sheet.createRow(0);

    // Create a cell and put a date value in it. The first cell is not
    // styled as a date.
    HSSFCell cell = row.createCell(0);
    cell.setCellValue(new Date());
View Full Code Here

   * @return
   * @throws Exception
   */
  public HSSFWorkbook toExcel(HSSFWorkbook wb, String sheetName, Collection<Object[]> datas,
      String propertyShowKeys) throws Exception {
    HSSFSheet sheet = wb.createSheet(sheetName);
    HSSFRow row = null;
    HSSFCell cell = null;

    /** **************** 取得传入的list列名称和显示名称 ********** */
    String[] pShowKeys = Tokenizer2StringArray(propertyShowKeys, ",");
    // 创建�?行(标题)
    row = sheet.createRow(0); // 建立新行
    // 显示标题列名
    for (int i = 0; i < pShowKeys.length; i++) {
      cell = row.createCell(i); // 建立新cell
      // cell.setEncoding(HSSFCell.ENCODING_UTF_16);
      cell.setCellValue(new HSSFRichTextString(pShowKeys[i]));
    }
    // 逐行取数
    int rowId = 1;// 数据行号(从2行开始填充数�?)
    for (Iterator<Object[]> iter = datas.iterator(); iter.hasNext(); rowId++) {
      row = sheet.createRow(rowId); // 建立新行
      Object[] objs = iter.next();
      // 生成每一�?
      for (int j = 0; j < objs.length; j++) {
        cell = row.createCell(j); // 建立新cell
        // cell.setEncoding(HSSFCell.ENCODING_UTF_16);
View Full Code Here

TOP

Related Classes of org.apache.poi.hssf.usermodel.HSSFSheet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.