Skip to main content

Posts

Showing posts from May, 2020

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

Create stop watch in java - by Dustbiin

Create Stopwatch class with start, stop and deference methods - It is use for find out the execution time of any process explicitly public class StopWatch {     long   start = System.currentTimeMillis();     long   stop  = 0;     String title = null;     public StopWatch( String title )     {         this.title = title;     }     public long start()     {         start = System.currentTimeMillis();         stop = 0;         return start;     }     public long stop()     {         stop = System.currentTimeMillis();         return stop;     }     public long diff()     {         if ( stop == 0 )         {             return ( System.currentTimeMillis() - start );         }         return ( stop - start );     }     public static void main( String[] args )     {         StopWatch stopWatch = new StopWatch( "My Stop watch" );         System.out.println( "Start : " + stopWatch.start() );         System.out.println( "stop : " + stopWatch.stop() );         System

Styling the excel sheet data like font size, color, font family, and text alignment - by Dustbiin

Apache poi provide very powerful fetcher for data formation and changing the color, size and font family- Create workspace and sheet- XSSFWorkbook workBook = new XSSFWorkbook (); Sheet sheet = workBook.createSheet("My sheet"); Create Font object and set font styling- Font font = workbook.createFont(); font.setBold( true ); font.setFontHeight( (short) ( 25 * 10 ) ); // set font family font.setFontName( "Courier New" ); // set font color font.setColor( IndexedColors.WHITE.getIndex() ); Create CellStyle object and set alignment of data in cell and set font to the data- CellStyle cellStyle = new CellStyle(); cellStyle.setFont(font); // use when you want to wrap text in multipal line cellStyle.setWrapText(true); Create Row and Cell and set cellStyle for the cell data- XSSFRow row = sheet.createRow( 1 ); Cell cell = row.createCell(1); cell.setCellValue("Hello World"); cell.setCellStyle( cellStyle );

How To Install Sticky Note In Ubuntu 19.10 - by Dustbiin

Install Sticky note in any Ubuntu system, it is very useful for store sort information: Indicator sticky note: Indicator sticky note is an open source software and it is spicily made for Ubuntu. It is also tested on GNOME shell. It work same as sticky note work in windows system. // Update your system sudo apt-get update //Install Indicator sticky note sudo apt-get install indicator-stickynotes Sticky notes look Remove Indicator Sticky note: sudo add-apt-repository ppa:umang/indicator-stickynotes –remove sudo apt-get remove indicator-stickynotes sudo apt-get autoremove

Merging cells in Excel using Apache POI - Dustbiin

Merge cells in a row or merge cells in column - Create a workbook and sheet in the workbook- XSSFWorkbook workBook = new XSSFWorkbook (); Sheet sheet = workBook.createSheet("My sheet"); sheet . addMergedRegion ( new CellRangeAddress ( startRowIndx ,   endRowIndx ,   startColIndx ,   endColIndx )); try (FileOutputStream outputStream = new FileOutputStream( "demo.xlsx" )) {     workbook.write( outputStream ); } finally {     workbook.close(); } Make sure the CellRangeAddress does not coincide with other merged regions as that will throw an exception. If you want to merge cells one above another, keep column indexes same If you want to merge cells which are in a single row, keep the row indexes same Indexes are zero-based, it means row and column start from zero. Start index of row and column must be l

Add multiple sheets in an excel file in JAVA by using Apache POI. - Dustbiin

Adding multiple sheets in excel file- Create new workbook first- XSSFWorkbook workBook = new XSSFWorkbook (); Add sheets in the workbook Sheet sheet1 = workbook.createSheet("Sheet name 1"); Sheet sheet2 = workbook.createSheet("Sheet name 2"); Sheet sheet3 = workbook.createSheet("Sheet name 3"); Sheet sheet4 = workbook.createSheet("Sheet name 4"); Sheet sheet5 = workbook.createSheet("Sheet name 5");     try (FileOutputStream outputStream = new FileOutputStream( "demo.xlsx" )) {     workbook.write( outputStream ); } finally {     workbook.close(); } Output -  Output with five sheet int excel file  

5 String utilities methods - Dustbiin

1) Check mobile number is valid or not  public boolean isValidMobile( final String inMobile )     {         Pattern pattern = Pattern.compile( "[6-9][0-9]{9}" );         Matcher matcher = pattern.matcher( inMobile );         if ( matcher.matches() )         {             return true;         }         else         {             return false;         }     } 2) Check PIN code is valid or not   public boolean isValidPinCode( final String inStr )     {         final String str = inStr.trim();         final String rule = "[0-9]{6}$";         final Pattern pattern = Pattern.compile( rule );         final Matcher matcher = pattern.matcher( str );         if ( matcher.matches() )             return true;         else             return false;     } 3) Array to string with separator by comma public String arrayToStringWithComma( String str[] )     {         String processedString = "";         processedString = Arrays.toS

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; impo