Package org.apache.poi.hssf.usermodel

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


        final boolean dynamicColors = "true".equals
            (config.getConfigProperty(
                "org.pentaho.reporting.engine.classic.core.modules.output.table.xls.DynamicColors"));
        if (dynamicColors)
        {
          final HSSFWorkbook hssfWorkbook = (HSSFWorkbook) workbook;
          colorProducer = new DynamicExcelColorProducer(hssfWorkbook);
        }
        else
        {
          colorProducer = new StaticExcelColorSupport();
View Full Code Here


    {
      return new XSSFWorkbook();
    }
    else
    {
      return new HSSFWorkbook();
    }
  }
View Full Code Here

       FileOutputStream outputStream = null;
       try {
         inputStream = new FileInputStream(new File(file1));         
         inputStream2 = new FileInputStream(new File(file2));
         outputStream = new FileOutputStream(new File(file3));
         HSSFWorkbook hssf = new HSSFWorkbook(inputStream);
         HSSFWorkbook hssf2 = new HSSFWorkbook(inputStream2);
         // Check for the work book to be not empty
         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
View Full Code Here

    try
    {
      inputStream = new FileInputStream(new File(file1));
      inputStream2 = new FileInputStream(new File(file2));
      outputStream = new FileOutputStream(new File(file3));
      HSSFWorkbook hssf = new HSSFWorkbook(inputStream);
      HSSFWorkbook hssf2 = new HSSFWorkbook(inputStream2);
      // Check for the work book to be not empty
      // Check if the sheet count is same for both books
      if (hssf.getNumberOfSheets() != hssf2.getNumberOfSheets())
      {

        String dataToWrite = "Number of sheets are not equal" + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
        outputStream.write(dataToWrite.getBytes());
        return false;
      }

      // 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$
View Full Code Here

      return;
    }

  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

   StringBuffer sheetText = new StringBuffer();
   try
   {
    logger.info("Extracting text from spreadsheet " + ifile);
    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

    this(is, DEFAULT_HEADINDEX);
  }

  public ExcelItemReader(InputStream is, int headIndex) {
    try {
      init(new HSSFWorkbook(is), headIndex, headIndex + 1);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
View Full Code Here

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
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());

    // we style the second cell as a date (and time). It is important to
    // create a new cell style from the workbook
    // otherwise you can end up modifying the built in style and effecting
    // not only this cell but other cells.
    HSSFCellStyle cellStyle = wb.createCellStyle();
    DataFormat df = wb.createDataFormat();
    // cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
    cellStyle.setDataFormat(df.getFormat("YYYY-MM-DD HH:MM:SS"));
    cell = row.createCell(1);
    cell.setCellValue(new Date());
    cell.setCellStyle(cellStyle);
    // Write the output to a file
    FileOutputStream fileOut = new FileOutputStream("src/test/resources/workbook.xls");
    wb.write(fileOut);
    fileOut.close();
  }
View Full Code Here

  @Test(dependsOnMethods = { "testWrite" })
  public void testRead() throws Exception {
    File file = new File("src/test/resources/tmp.xls");
    FileInputStream in = new FileInputStream(file);
    HSSFWorkbook wb = new HSSFWorkbook(in);
    HSSFCell cell = wb.getSheetAt(0).getRow(0).getCell(0);
    // HSSFFont f = cell.getCellStyle().getFont(wb);
    // Assert.assertEquals(f.getBoldweight(), HSSFFont.BOLDWEIGHT_BOLD);
    Assert.assertEquals(cell.getCellStyle().getAlignment(), HSSFCellStyle.ALIGN_CENTER);
    in.close();
    file.delete();
View Full Code Here

@Test
public class ExcelReaderTest {

  public void testReadCell() throws Exception {
    FileInputStream in = new FileInputStream("src/test/resources/date.xls");
    HSSFWorkbook wb = new HSSFWorkbook(in);
    HSSFCell dateCell = wb.getSheetAt(0).getRow(0).getCell(0);
    HSSFCell dateTimeCell = wb.getSheetAt(0).getRow(0).getCell(1);
    Object value = ExcelItemReader.getCellValue(dateCell);
    Assert.assertTrue(value instanceof Date);
    Object value2 = ExcelItemReader.getCellValue(dateTimeCell);
    Assert.assertTrue(value2 instanceof Date);
    in.close();
View Full Code Here

TOP

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

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.