Showing posts with label current affairs. Show all posts
Showing posts with label current affairs. Show all posts

Friday, 2 May 2025

Excel Data read by Selenium java

 Code to read data from Excel 

package mit;


import java.io.File;

import java.io.FileInputStream;

import java.util.Arrays;

import java.util.Iterator;


import org.apache.poi.ss.usermodel.DataFormatter;

import org.apache.poi.ss.usermodel.Row;

import org.apache.poi.ss.usermodel.Sheet;

import org.apache.poi.ss.usermodel.Workbook;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;


public class TestExcelData {


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


        File file = new File("Untitled spreadsheet (1) (1).xlsx");


        FileInputStream fin = new FileInputStream(file);


        Workbook wb = new XSSFWorkbook(fin);

        

        Sheet s1 = wb.getSheet("Sheet1");

        

        int r1=s1.getPhysicalNumberOfRows();

        int c1=s1.getRow(0).getPhysicalNumberOfCells();

        

String[][] data =new String[r1-1][c1];

   //     String s = r.getCell(1).toString();

    //    System.out.println(s);


        

        for (int i = 0; i < r1-1; i++)

        

        {

for (int j = 0; j < c1; j++)

{

DataFormatter df=new DataFormatter();

data[i][j]= df.formatCellValue(s1.getRow(i).getCell(j));

}

}


    

        // Clean up

       

        fin.close();

        

       for (String[]dataAStr:data)

        {

System.out.println(Arrays.toString(dataAStr));

}

    }

}


Package and Imports

package mit;
  • Declares the package name mit. It organizes classes into namespaces.

import java.io.File;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.Iterator;
  • File: For representing file and directory pathnames.

  • FileInputStream: For reading raw bytes from a file.

  • Arrays: For utility functions like toString() to print array contents.

  • Iterator: Though imported, it is not used in this program.

import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  • These classes are part of Apache POI for working with Excel files (.xlsx).

    • Workbook: Represents the whole Excel file.

    • Sheet: Represents a single worksheet.

    • Row: Represents a row in a sheet.

    • DataFormatter: Converts cell values to readable Strings.

    • XSSFWorkbook: Used specifically for .xlsx files.


Class Definition

public class TestExcelData {
  • Defines a public class named TestExcelData.


Main Method

public static void main(String[] args) throws Exception {
  • Entry point of the program.

  • throws Exception: Declares that the method may throw exceptions (e.g., IOException or FileNotFoundException).


Step-by-step Operations

File file = new File("Untitled spreadsheet (1) (1).xlsx");
  • Creates a File object pointing to the Excel file. Make sure the path is correct.

FileInputStream fin = new FileInputStream(file);
  • Opens the file for reading its contents.

Workbook wb = new XSSFWorkbook(fin);
  • Loads the Excel workbook using Apache POI. This supports .xlsx files.

Sheet s1 = wb.getSheet("Sheet1");
  • Accesses the sheet named "Sheet1" from the workbook.

int r1 = s1.getPhysicalNumberOfRows();
  • Gets the number of rows that contain data (non-empty rows).

int c1 = s1.getRow(0).getPhysicalNumberOfCells();
  • Gets the number of cells (columns) in the first row (assumed to be the header).

String[][] data = new String[r1 - 1][c1];
  • Initializes a 2D array to store the Excel data (excluding the header row).


Reading the Excel Data

for (int i = 0; i < r1 - 1; i++) {
    for (int j = 0; j < c1; j++) {
        DataFormatter df = new DataFormatter();
        data[i][j] = df.formatCellValue(s1.getRow(i).getCell(j));
    }
}
  • Outer loop (i): Iterates over rows from 0 to r1-2 (excluding header row at r1-1).

  • Inner loop (j): Iterates over each cell in a row.

  • DataFormatter: Converts cell to a formatted string regardless of cell type (numeric, string, date).

  • Stores the formatted value in the data array.

Note: Since r1-1 is used in the array, it's implied that the header is included but not stored.


Closing Resources

fin.close();
  • Closes the file input stream.


Printing the Data

for (String[] dataAStr : data) {
    System.out.println(Arrays.toString(dataAStr));
}
  • Iterates through the data array.

  • Prints each row as a string using Arrays.toString().


🔚 Summary:

  • This program reads an Excel .xlsx file using Apache POI.

  • It stores data (excluding the header) in a 2D String array.

  • Uses DataFormatter to ensure proper formatting of cell values.

  • Then it prints the extracted data to the console.


Wednesday, 22 January 2025

महाकुंभ 2025: प्रयागराज में आध्यात्मिकता और आस्था का महासंगम

 महाकुंभ 2025: प्रयागराज में आध्यात्मिकता और आस्था का महासंगम

महाकुंभ के आयोजन की तारीखें और महत्व



प्रयागराज में महाकुंभ 2025 का आयोजन 13 जनवरी से 26 फरवरी तक होगा। इस 45 दिवसीय आयोजन में करोड़ों श्रद्धालुओं के आस्था का संगम देखने को मिलेगा।

समाचार में क्यों?
प्रधानमंत्री नरेंद्र मोदी के नेतृत्व में उत्तर प्रदेश सरकार ने इस ऐतिहासिक महोत्सव को भव्य, सुरक्षित और आध्यात्मिक रूप से समृद्ध बनाने के लिए व्यापक तैयारियां शुरू कर दी हैं। अनुमान है कि इस आयोजन में देश-विदेश से 40 करोड़ से अधिक श्रद्धालु भाग लेंगे।

महाकुंभ क्या है?
महाकुंभ मेला दुनिया का सबसे बड़ा शांतिपूर्ण आयोजन है, जिसमें लाखों श्रद्धालु पवित्र नदियों में स्नान कर आध्यात्मिक शुद्धि की अनुभूति करते हैं। यह मेला हर 12 वर्षों में एक बार चार पवित्र स्थलों में आयोजित होता है:

  1. हरिद्वार (गंगा नदी के किनारे)
  2. उज्जैन (शिप्रा नदी के किनारे)
  3. नासिक (गोदावरी नदी के किनारे)
  4. प्रयागराज (गंगा, यमुना और अदृश्य सरस्वती के संगम पर)

महाकुंभ का विशेष महत्व
महाकुंभ मेले को हर 12 वर्षों में मनाया जाने वाला इस पर्व का सबसे पवित्र स्वरूप माना जाता है। मान्यता है कि इस दौरान पवित्र डुबकी लगाने से आत्मिक शुद्धि और आध्यात्मिक उन्नति होती है।

पौराणिक और ऐतिहासिक आधार

  1. पौराणिक कथा: महाकुंभ का संबंध "समुद्र मंथन" की कथा से है, जिसमें अमृत कलश के कुछ बूंदें चार पवित्र स्थलों पर गिरी थीं।
  2. ऐतिहासिक उल्लेख: इसका पहला उल्लेख ऋग्वेद जैसे प्राचीन ग्रंथों में मिलता है। यह मौर्य और गुप्त साम्राज्य के समय में और भी प्रसिद्ध हुआ।
  3. ज्योतिषीय महत्व: कुंभ मेला सूर्य, चंद्रमा और गुरु के विशेष ज्योतिषीय योगों के आधार पर मनाया जाता है।

यूनेस्को द्वारा मान्यता
साल 2017 में यूनेस्को ने कुंभ मेले को अमूर्त सांस्कृतिक धरोहर (Intangible Cultural Heritage) के रूप में सूचीबद्ध किया, जिससे इसकी वैश्विक पहचान और बढ़ी।

महाकुंभ 2025 न केवल एक धार्मिक आयोजन है, बल्कि यह भारत की सांस्कृतिक विरासत और आध्यात्मिक समृद्धि का जीता-जागता उदाहरण भी है। इस पर्व में भाग लेने वाले हर श्रद्धालु के लिए यह जीवनभर की अमूल्य स्मृति बन जाती है।

Excel Data read by Selenium java

 Code to read data from Excel  package mit; import java.io.File; import java.io.FileInputStream; import java.util.Arrays; import java.util.I...