Apache POI is an open-source library by Apache which can be used to create, modify and display files MS office file in Java. It provides classes and methods to do so. This API provides various components such as POIFS (Poor Obfuscation Implementation File System), HSSF (Horrible Spreadsheet Format), XSSF (XML Spreadsheet Format), HPSF (Horrible Property Set Format), HWPF (Horrible Word Processor Format), XWPF (XML Word Processor Format), HSLF (Horrible Slide Layout Format). Data in a spreadsheet is always stored in a cell. Apache library allows you to perform various operations on these cells such as changing font style, add a hyperlink, changes text direction.
Apache library allows you to change the direction of the text in a cell by displaying the text in different angles of directions. So we specify an angle in the function. E.g. setRotation((short) 20);
For this example, XSSF components are used.
- First, download the library, It will download all the required jar files.
- Right Click on a project in package explorer -> click on Build path -> Configure Build Path -> Add libraries -> Add external Jar files -> select the JAR files from the unzipped folder.
Following are the classes that will be used in the code:
- XSSFWorkbook: Root class to handle XLSX. It reads an excel file from a file input stream.
- XSSFSheet: A workbook can have more than one sheet.
- XSSFRow: Used to represents a row of excel sheet.
- XSSFCell: Used to represents a cell to the corresponding row.
Output in Excel sheet:
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.