Skip to main content

Basic object detection in python using OpenCv and Numpy - by Dustbiin

Create Excel (.xlsx) file in JAVA by Apache Poi - dustbiin

Create an excel file in java by apache poi easy and it is a very powerful API for excel creation.

Step-1: Create a maven project (ExcelGenerator) and Import apache poi dependency in pom.xml

<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>4.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>4.1.2</version>
</dependency>
 
 
Go to maven package site

Step-2: Create a class to generate an excel file


package com.demo.client;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ExcelGenerator
{
    public static void main( String[] args )
        throws FileNotFoundException,
        IOException
    {
        //create new workbook (you can say the excel file)
        XSSFWorkbook wb = new XSSFWorkbook();
        //create new sheet in excel file with name 'First sheet'
        Sheet sheet = wb.createSheet( "First Sheet" );
        //create new row in sheet with row number (row start from 0)
        XSSFRow row = sheet.createRow( 1 );
        // create dummy string array to set in excel sheet row
        String[] str = "Component,Category,S. No., Activity Name,Unit of           Measure,Current Status".split( "," );
        for ( int i = 0; i < str.length; i++ )
        {
            //create cell in the existng row of the sheet you can asume as column of the row (column start from 0 )
            Cell cell = row.createCell( i );
            //set the data in the perticular cell
            cell.setCellValue( str[i] );
        }
        //its your local dir path of your syste with file name which you want to create (demo.xlsx)
        String filePath = "/home/manjuman/Documents/demo.xlsx";
        try (OutputStream fileOut = new FileOutputStream( file ))
        {
            //generate your excel file
            wb.write( fileOut );
            System.out.println( "Excel generated" );
        }
        catch ( Exception e )
        {
            System.out.println( e.getMessage() );
        }
        finaly
       {
           //close your workbook
           wb.close();
       }
    }
}

Output file:

demo.xlsx
demo.xlsx with one sheet (First sheet )

 

Comments

Popular posts from this blog

Custom cell color in Excel Apache POI - By Dustbiin

Create custom color for cell background by using java color class Create custom color- XSSFWorkbook workBook = new XSSFWorkbook (); IndexedColorMap colorMap = workbook.getStylesSource().getIndexedColors(); Font tableHeadOneFontStyle = workbook.createFont();  tableHeadOneFontStyle.setBold( true ); tableHeadOneFontStyle.setColor( IndexedColors.BLACK.getIndex() ); XSSFCellStyle tableHeaderOneColOneStyle = workbook.createCellStyle(); tableHeaderOneColOneStyle.setFont( tableHeadOneFontStyle ); tableHeaderOneColOneStyle.setFillForegroundColor( new XSSFColor( new java.awt.Color( 255, 231, 153 ), colorMap ) ); tableHeaderOneColOneStyle.setFillPattern( FillPatternType.SOLID_FOREGROUND ); tableHeaderOneColOneStyle = setLeftRightBorderColor( tableHeaderOneColOneStyle ); tableHeaderOneColOneStyle = alignCenter( tableHeaderOneColOneStyle );

Create design by connecting dot's using opencv and numpy - by Dustbiin

Create basic design by using connecting dot's using your mouse- I have been create this by using mouse event check out the code below- use Python, OpenCv , NumPy import numpy as np import cv2 def click_event(event , x , y , flags , param): if event == cv2.EVENT_LBUTTONDOWN: print(x , " , " , y) font = cv2.FONT_HERSHEY_SIMPLEX strXY = str(x) + ' , ' + str(y) # cv2.putText(img,strXY, (x, y), font, .1, (255, 255, 0), 2) cv2.circle(img , (x , y) , 3 , ( 0 , 0 , 255 ) , - 1 ) points.append((x , y)) if len(points) >= 2 : cv2.circle(img , points[- 1 ] , 3 , ( 0 , 0 , 255 ) , - 1 ) # cv2.putText(img,strXY, points[-1], font, .1, (255, 255, 0), 2) cv2.line(img , points[- 2 ] , points[- 1 ] , ( 0 , 0 , 255 ) , 1 ) cv2.imshow( "Image" , img) points = [] img = np.zeros(( 512 , 512 , 3 )) cv2.imshow( "Image" , img) cv2.setMouseCallback( 'Image' ...

Read data from .pfx file for Digita Signature - by Dustbiin

Their is many way to read data for data for digital signature but hear we discus reading data from .pfx file -  code for read .pfx file - import java.io.FileInputStream; import java.security.KeyStore; import java.security.cert.X509Certificate; import java.util.Date; import java.util.Enumeration; import javax.net.ssl.KeyManagerFactory; public class PdfDemo { public static void checkExpire() { try { KeyManagerFactory kmf = javax.net.ssl.KeyManagerFactory.getInstance( "SunX509" ); KeyStore keystore = KeyStore.getInstance( "PKCS12" ); char[] password = "123456".toCharArray(); keystore.load( new FileInputStream( "demo.pfx" ), password ); //keystore.load(new FileInputStream(certificate), password); kmf.init( keystore, password ); Enumeration<String> aliases = keystore.aliases(); while ( aliases.hasMoreElements() ) { ...