TestingDocs.com
    Software Testing website
    • Automation
      • Selenium
      • JBehave Framework
    • Tutorials
      • MySQL Tutorials
      • Testlink
      • Maven
      • Git
    • IDEs
      • IntelliJ IDEA
      • Eclipse
    • Flowcharts
      • Flowgorithm
      • Raptor
    • About

    Automation

    HSSF / XSSF Interaction with Microsoft Excel ( .xls and .xlsx )

    Overview

    We will discuss HSSF / XSSF Interaction with Microsoft Excel ( .xls and .xlsx ). Mostly, interacting with excel documents in automation frameworks built with the open source we use either Apache POI or JExcel ( a.k.a JXL API ). In this article, we will concentrate on Apache POI.

    Test data in Excel files might be in .xls or .xlsx format. We need to keep some things in mind before interacting with these formats. Depending on the file format we need to change the API being used. Below are some of the key points.

    The wrong usage of the API would end with exceptions in your code.

    Sample exception below:

    org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)
        at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:131)
        at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:104)
        at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:128)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:342)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:323)

     

    
    

    The Difference:

    HSSF is the POI’s pure Java implementation of the Excel ’97(-2007) file format. XSSF is the POI’s pure Java implementation of the Excel 2007+ OOXML file format.( i.e .xlsx format )

    Both provide ways to read, create, modify, read and write excel spreadsheets. The below picture depicts the API usage for the file format:

     

    HSSFvsXSSF_POI

     

    1. An event model API for efficient read-only access

    2.Usermodel API for creating, reading and modifying  xls files

     

    If you’re merely reading spreadsheets, then use the eventmodel API in either the org.apache.poi.hssf.eventusermodel package, or the org.apache.poi.xssf.eventusermodel package, depending on your file format. Also, if you’re modifying spreadsheets then use the usermodel API. Furthermore, you can also generate spreadsheets by this way.

    Related Posts

    Automation /

    Dart return Statement

    Emma Tool

    Automation /

    Code Coverage Tools

    Selenium 4 Automation Project

    Automation /

    Selenium 4 Project Setup on Ubuntu Linux

    Testing webpage mobile-friendliness using a tool

    Automation /

    Testing webpage mobile-friendliness using a tool

    Errors Code Testing Development

    Automation /

    Error Severity Metrics

    ‹ Types of Brute Force Attacks› Declare variables in Raptor Flowchart

    Recent Posts

    • Running Tests in Parallel with Selenium Grid
    • Advanced Selenium Features
    • Locating Web Elements
    • Running the Test Script
    • Writing Your First Selenium Test Script
    • Getting Started with Selenium Automation Testing
    • Setting Up the Environment
    • How can you monitor the Quality Assurance Audit?
    • Leveraging LambdaTest with Appium 2.0
    • Appium 2.0 Plugins ListAppium 2.0 Plugins
    • Touch Actions and Multi-Touch Actions
    • Changes in Drivers and Classes
    • Appium Inspector
    • Capabilities in Appium 2.0
    • Appium 2.0 Driver ListAppium 2.0 Driver Installation & Management
    CyberLink Multimedia Software

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com