Read the excel file with Wild card characters in file name

Hi Team,
I use the below code to fetch the data from Excel file

nameForYourData = ExcelFactory.getExcelDataWithDefaultSheet(“C:\Users\Documents\Downloads\sample.xls”, “classic”, true)

String userName = nameForYourData .getValue(3, 1)
String userPassword= nameForYourData .getValue(4, 1)

System.out.println('Output is ’ + userName)

It works like charm.
But my problem is file name is not static.
It varies at every time
File name format is constant number followed by varying text
Pls guide to get the file name


use regex to fetch filename like

import java.util.regex.Matcher;
import java.util.regex.Pattern;

        String name = "01223_adsdwd.xls";
        Pattern p = Pattern.compile("([\\d]+)\\S(\\w+)(\\Sxls)");
        Matcher m = p.matcher(name);
        String firstGroup = "";
        String secondGroup = "";
        String thirdGroup = "";
        while(m.find()) {
            firstGroup =;
            secondGroup =;
            thirdGroup =;

        System.out.println("first "+firstGroup);
        System.out.println("second "+secondGroup);
        System.out.println("third "+thirdGroup);

        String finalFileName = secondGroup+"_"+thirdGroup+".xls";
        System.out.println("finalName "+finalFileName);

first 01223_adsdwd.xls
second 01223
third adsdwd
finalName 01223_adsdwd.xls

Thank You so much.
It worked well.
I moved to specified cell and printed the value of that cell.
My new requirement is
I need to scroll to bottom of the excel and take the screenshot.
Pls help me to take screenshot of excel


use Robot class to take screenshot from excel file
this will capture whole page
open the excel file first

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;

    try {
        Robot robot = new Robot();
        String format = "jpg";
        String fileName = "FullScreenshot." + format;

        Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
        BufferedImage screenFullImage = robot.createScreenCapture(screenRect);
        ImageIO.write(screenFullImage, format, new File(fileName));

        System.out.println("A full screenshot saved!");
    } catch (AWTException | IOException ex) {

not tried but i guess will work

1 Like

Super.Thank you.It is working well
But I need to open the Excel and move to bottom of excel and then need to take screenshot.
But the present code is taking the screenshot of current screen not the excelfile. :grinning:


as I said open excel file first

Desktop.getDesktop().open(new File(“path/to/your/file.xls”));

Super.Thank you. worked well