Top 26 Apache Poi Ppt Interview Questions You Must Prepare 23.Jul.2024

Q1. What Is The Purpose Of Xssfworkbook Class In Apache Poi?

It is a class that is used to represent both high and low level Excel file formats. It belongs to the org.apache.xssf.usemodel package and implements the Workbook interface.

Q2. How Will You Add A Hyperlink To A Cell Using Apache Poi?

XSSFHyperlink can be used to the add an hyperlink to a cell.

CreationHelper createHelper = workbook.getCreationHelper();

XSSFHyperlink link = (XSSFHyperlink)createHelper.createHyperlink(Hyperlink.LINK_URL);

link.setAddress("http://www.tutorialspoint.com/" );

cell.setHyperlink((XSSFHyperlink) link);

Q3. How Will You Style A Cell Using Apache Poi?

XSSFCellStyle class is used to style a cell. Following code snippet can be used to set the cell alignment to "Top Left".

XSSFCellStyle style1 = workbook.createCellStyle();

spreadsheet.setColumnWidth(0, 8000);

style1.setAlignment(XSSFCellStyle.ALIGN_LEFT);

style1.setVerticalAlignment(XSSFCellStyle.VERTICAL_TOP);

cell.setCellValue("Top Left");

cell.setCellStyle(style1);

Q4. What Is The Purpose Of Hssfcolor Class In Apache Poi?

This is a class under the org.apache.poi.hssf.util package. It provides different colors as nested classes. Usually these nested classes are represented by using their own indexes. It implements the Color interface.

Q5. How Will You Rotate A Cell Content Using Apache Poi?

XSSFCellStyle class can be used to rotate a cell. Following code snippet can be used to set the cell text alignment to a specified angle.

//90 degrees

XSSFCellStyle myStyle = workbook.createCellStyle();

myStyle.setRotation((short) 90);

cell = row.createCell(5);

cell.setCellValue("90D angle");

cell.setCellStyle(myStyle);

Q6. What Is The Purpose Of Xssfhyperlink Class In Apache Poi?

This is a class under the org.apache.poi.xssf.usermodel package. It implements the Hyperlink interface. It is used to set a hyperlink to the cell contents of a spreadsheet.

Q7. How Will You Add A Power Formular To A Cell Using Apache Poi?

XSSFCell.CELL_TYPE_FORMULA can be used to the cell as formula cell.

// Create SUM formula

cell.setCellType(XSSFCell.CELL_TYPE_FORMULA);

cell.setCellFormula("POWER(C2:C3)" );

cell = row.createCell(3);

cell.setCellValue("POWER(C2:C3)");

Q8. What Is The Purpose Of Xssffont Class In Apache Poi?

This is a class under the org.apache.poi.xssf.usermodel package. It implements the Font interface and therefore it can handle different fonts in a workbook.

Q9. How Will You Add A Sqrt Formular To A Cell Using Apache Poi?

XSSFCell.CELL_TYPE_FORMULA can be used to the cell as formula cell.

// Create SUM formula

cell.setCellType(XSSFCell.CELL_TYPE_FORMULA);

cell.setCellFormula("SQRT(C2)" );

cell = row.createCell(3);

cell.setCellValue("SQRT(C2)");

Q10. What Is The Purpose Of Xssfcell Class In Apache Poi?

This is a class under the org.apache.poi.xssf.usermodel package. It implements the Cell interface. It is a high-level representation of cells in the rows of a spreadsheet.

Q11. Write Down Steps To Create A Cell In A Spreadsheet In Apache Poi?

The following code snippet is used for creating a cell:

//create new workbook

XSSFWorkbook workbook = new XSSFWorkbook();

//create spreadsheet with a name

XSSFSheet spreadsheet = workbook.createSheet("new sheet");

//create first row on a created spreadsheet

XSSFRow row = spreadsheet.createRow(0);

//create first cell on created row

XSSFCell cell = row.createCell(0);

Q12. What Is The Purpose Of Xssfsheet Class In Apache Poi?

This is a class which represents high level representation of excel spreadsheet. It is under org.apache.poi.hssf.usermodel package.

Q13. How Will You Add A Max Formular To A Cell Using Apache Poi?

XSSFCell.CELL_TYPE_FORMULA can be used to the cell as formula cell.

// Create SUM formula

cell.setCellType(XSSFCell.CELL_TYPE_FORMULA);

cell.setCellFormula("MAX(C2:C3)" );

cell = row.createCell(3);

cell.setCellValue("MAX(C2:C3)");

Q14. What Is The Purpose Of Xssfrow Class In Apache Poi?

This is a class under the org.apache.poi.xssf.usermodel package. It implements the Row interface, therefore it can create rows in a spreadsheet.

Q15. What Is The Purpose Of Xssfprintsetup Class In Apache Poi?

This is a class under the org.apache.poi.xsssf.usermodel package. It implements the PrintSetup interface. It is used to set print page size, area, options, and settings.

Q16. How Will You Add A Sum Formular To A Cell Using Apache Poi?

XSSFCell.CELL_TYPE_FORMULA can be used to the cell as formula cell.

// Create SUM formula

cell.setCellType(XSSFCell.CELL_TYPE_FORMULA);

cell.setCellFormula("SUM(C2:C3)" );

cell = row.createCell(3);

cell.setCellValue("SUM(C2:C3)");

Q17. How Will You Set The Printable Area Of An Excel Using Apache Poi?

Following code snippet demonstrate setting up the printable area of an excel using Apache POI.

XSSFWorkbook workbook = new XSSFWorkbook(); 

XSSFSheet spreadsheet = workbook

.createSheet("Print Area");

//set print area with indexes

workbook.setPrintArea(

   0, //sheet index

   0, //start column

   5, //end column

   0, //start row

   5 //end row

);

//set paper size

spreadsheet.getPrintSetup().setPaperSize(

XSSFPrintSetup.A4_PAPERSIZE);

//set display grid lines or not

spreadsheet.setDisplayGridlines(true);

//set print grid lines or not

spreadsheet.setPrintGridlines(true);

Q18. Name Some Of The Components Of Apache Poi?

Components of Apache POI:

Apache POI contains classes and methods to work on all OLE2 Compound documents of MS Office. The list of components of this API is given below.

POIFS (Poor Obfuscation Implementation File System) − This component is the basic factor of all other POI elements. It is used to read different files explicitly.

  • HSSF (Horrible Spreadsheet Format): It is used to read and write xls format of MS-Excel files.
  • XSSF (XML Spreadsheet Format): It is used for xlsx file format of MS-Excel.
  • HPSF (Horrible Property Set Format): It is used to extract property sets of the MS-Office files.
  • HWPF (Horrible Word Processor Format): It is used to read and write doc extension files of MS-Word.
  • XWPF (XML Word Processor Format): It is used to read and write docx extension files of MS-Word.
  • HSLF (Horrible Slide Layout Format): It is used for read, create, and edit PowerPoint presentations.
  • HDGF (Horrible DiaGram Format): It contains classes and methods for MS-Visio binary files.
  • HPBF (Horrible PuBlisher Format): It is used to read and write MS-Publisher files.

Q19. What Is The Purpose Of Xssfcreationhelper Class In Apache Poi?

This is a class under the org.apache.poi.xssf.usermodel package. It implements the CreationHelper interface. It is used as a support class for formula evaluation and setting up hyperlinks.

Q20. What Is The Purpose Of Hssfsheet Class In Apache Poi?

This is a class under the org.apache.poi.hssf.usermodel package. It can create excel spreadsheets and it allows to format the sheet style and sheet data.

Q21. How Will You Add A Fact Formular To A Cell Using Apache Poi?

XSSFCell.CELL_TYPE_FORMULA can be used to the cell as formula cell.

// Create SUM formula

cell.setCellType(XSSFCell.CELL_TYPE_FORMULA);

cell.setCellFormula("FACT(C2)" );

cell = row.createCell(3);

cell.setCellValue("FACT(C2)");

Q22. How Will You Add A Font To A Cell Using Apache Poi?

XSSFFont class is used to add a font to a cell. Following code snippet can be used to set the background color of a cell to "Green".

//Create a new font and alter it.

XSSFFont font = workbook.createFont();

font.setFontHeightInPoints((short) 30);

font.setFontName("IMPACT");

font.setItalic(true);

font.setColor(HSSFColor.BRIGHT_GREEN.index);

//Set font into style

XSSFCellStyle style = workbook.createCellStyle();

style.setFont(font);

Q23. What Is The Purpose Of Xssfcellstyle Class In Apache Poi?

This is a class under the org.apache.poi.xssf.usermodel package. It will provide possible information regarding the format of the content in a cell of a spreadsheet. It also provides options for modifying that format. It implements the CellStyle interface.

Q24. Write Down Steps To Create A Spreadsheet In Apache Poi?

The following code snippet is used to create a spreadsheet:

//Create Blank workbook

XSSFWorkbook workbook = new XSSFWorkbook(); 

//Create a blank spreadsheet

XSSFSheet spreadsheet = workbook.createSheet("Sheet Name");

Write down steps to create a row in a spreadsheet in Apache POI.

The following code snippet is used to create a row.

XSSFRow row = spreadsheet.createRow((short)1);

Q25. What Is The Purpose Of Hssfworkbook Class In Apache Poi?

It is a high-level class under the org.apache.poi.hssf.usermodel package. It implements the Workbook interface and is used for Excel files in .xls format.

Q26. What Is Apache Poi?

Apache POI is a popular API that allows programmers to create, modify, and display MS Office files using Java programs. It is an open source library developed and distributed by Apache Software Foundation to design or modify Microsoft Office files using Java program. It contains classes and methods to decode the user input data or a file into MS Office documents.