Set Path for Apache Poi

Apache Poi Problems setting up in command line

You can specify your apache-poi jar as follow.

C:/demo/myprogram>javac -cp C:/project/jars/apache-poi.jar Main.java
C:/demo/myprogram>java -cp C:/project/jars/apache-poi.jar. Main

Here we specify the jar to classpath during the compilation and execution,in this way you will be able to access the apache-poi classes.

If you want to add multiple jars you can use * for that,

java -cp C:/project/jars/*. Main

How to make my path relative in selenium apache poi while I input my Excel file? and How to write the test result in excel after performing testing

Can you try like :

 FileInputStream input=new FileInputStream(new File("TestCase.xls"));

In your code? I think it should work.

POI API - Reference to font by the path

You should use HSSFFont for that. Take a look at the API.

For example:

 public class ChangeCellFontName {  
public static void main(String[] args) throws Exception{

/* Create Workbook and Worksheet */
HSSFWorkbook my_workbook = new HSSFWorkbook();
HSSFSheet my_sheet = my_workbook.createSheet("Cell Font");

/* Get access to HSSFCellStyle */
HSSFCellStyle my_style = my_workbook.createCellStyle();

/* Create HSSFFont object from the workbook */
HSSFFont my_font=my_workbook.createFont();

/* Set the font name to Verdana */
my_font.setFontName("Verdana");

/* Also make the font color to RED */
my_font.setColor(HSSFFont.COLOR_RED);

/* attach the font to the style created earlier */
my_style.setFont(my_font);

/* Attach the new font to a cell */
/* Create a row in the sheet */
Row row = my_sheet.createRow(0);

/* Create a cell */
Cell cell = row.createCell(0);
cell.setCellValue("The font for this text would be Verdana");

/* Attach the style to the cell */
cell.setCellStyle(my_style);


}
}

This last example was taken from here. Also, another example.



Related Topics



Leave a reply



Submit