Home Tutorials Poi Excel Prompt User on Focus
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Excel Prompt User on Focus

Advertisement
In this section, you will learn how to prompt user on focusing the cell using Apache POI.

Excel Prompt User on Focus

In this section, you will learn how to prompt user on focusing the cell using Apache POI.

EXAMPLE

In the below example, you will learn how to prompt user on focusing the cell. Here, the message title and message is user defined.

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

import org.apache.poi.hssf.usermodel.DVConstraint;
import org.apache.poi.hssf.usermodel.HSSFDataValidation;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.DataValidation;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddressList;

public class XLFocusPrompt {
public static void main(String args[]) throws FileNotFoundException {
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet("Message on Focus");
CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0);
DVConstraint dvConstraint = DVConstraint
.createExplicitListConstraint(new String[] { "10", "20", "30" });
DataValidation dataValidation = new HSSFDataValidation(addressList,
dvConstraint);

// DISPLAY MSG WHEN CELL A1 IS ON FOCUS
dataValidation.createPromptBox("Message on Focus",
"Cell A1 is on Focus");
dataValidation.setShowPromptBox(true);

sheet.addValidationData(dataValidation);
FileOutputStream fileOut = new FileOutputStream("xls/XLFocusPrompt.xls");
try {
workbook.write(fileOut);
fileOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

OUTPUT

Download Source Code

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 20, 2011

Ask Questions?    Discuss: Excel Prompt User on Focus  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com