In this article, we will see how to set up a Task reminder with Popup message in the Windows system. We need to have some basic understanding of Java and Windows shell scripting.
Step 1: Setup up Java project
Use any IDE e.g. Eclipse to create a Java project. We need below external jar files. Download the jar files below and set up in the classpath:
2. poi-3.17
Step 2: Write Java class
Use below code snippet to read an excel file and show popup message using Jpanel class.
import java.awt.Graphics;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.apache.poi.ss.usermodel.Cell;
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 ReadFile extends JPanel {
public void paint(Graphics g){
ReadFile rc = new ReadFile(); // object of the class
// reading the value of 2nd row and 2nd column
ArrayList<String> vOutput = rc.ReadCellData(2, 5);
int k = 10;
if (vOutput != null) {
if (vOutput.size() <=0) {
g.drawString("No reminder today! Enjoy!!!", 10, k);
} else {
for (int i = 0; i < vOutput.size() ; i++) {
g.drawString(vOutput.get(i), 10, k);
k = k + 20;
}
}
}
}
public static void main(String[] args) {
JFrame frame= new JFrame("Customer Reminder!");
frame.getContentPane().add(new ReadFile());
frame.setSize(300, 300);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
}
// method defined for reading a cell
public ArrayList<String> ReadCellData(int vRow, int vColumn) {
ArrayList<String> al = new ArrayList<>();
Workbook wb = null; // initialize Workbook null
try {
// reading data from a file in the form of bytes
FileInputStream fis = new FileInputStream("D:\\sample.xlsx");
// constructs an XSSFWorkbook object, by buffering the whole stream into the
// memory
wb = new XSSFWorkbook(fis);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
Sheet sheet = wb.getSheetAt(0); // getting the XSSFSheet object at given index
int j = 0;
for (int i = 1; i < 1000; i++) {
Row row = sheet.getRow(i); // returns the logical row
if (row != null) {
Cell cell = row.getCell(7); // getting the cell representing the given column
if (cell != null) {
Date dueDate = cell.getDateCellValue();
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
Date currentDate=java.util.Calendar.getInstance().getTime();
if (dueDate != null && (dateFormat.format(dueDate)).equals(dateFormat.format(currentDate))) {
Cell customerName = row.getCell(6);
String custName = null;
if (customerName != null) {
custName = customerName.getStringCellValue();
}
Cell phoneNum = row.getCell(8);
String phone = null;
if (phoneNum != null) {
phone = phoneNum.getStringCellValue();
}
if (custName != null) {
al.add("Call: [ " + custName + " : " + phone + "] ");
}
}
}
}
}
return al; // returns the cell value
}
}
Step 3: Create a runnable jar file
Use Eclipse -> Export option to create Runnable jar file and name it as reminder_project.jar (You can provide any name)
Step 4: Create a batch file
Create CMD file with the content below
java -jar D:\reminder_project.jar
Step 4: Setup Task using Task Scheduler in Windows system
Use Task Scheduler in the Windows system. Provide the name of the task, Trigger details (daily, weekly), and Actions.
Provide CMD file name in the schedular
No comments:
Post a Comment
Please do not enter any spam link in the comment box.