In: Computer Science
PROGRAM DEVELOPMENT: Analyze and write the code for the
following requirement:
The sales department wants to store the sales data of their
employees. Assume that there are 20 employeesand they all work in
three areas. Declare appropriately and accept the sales data from
the user.
import java.io.FileOutputStream;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
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;
public class Spreadsheet {
public Spreadsheet() {
Workbook SalesInfo = new HSSFWorkbook();
Sheet Information = SalesInfo.createSheet();
Row titles = Information.createRow(0);
Cell empid = titles.createCell(0);
id.setCellValue("empid");
Cell empname = titles.createCell(1);
empname.setCellValue("Name");
Cell email = titles.createCell(2);
email.setCellValue("Email");
Cell Area = titles.createCell(3);
Area.setCellValue("Area");
Cell salesfig = titles.createCell(4);
salesfig.setCellValue("Sales Figure");
try {
FileOutputStream Accounts = new FileOutputStream("Sales
Information.xls");
AccountInfo.write(Accounts);
}catch(Exception e){
e.printStackTrace();
}
}
}
--------------------
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.Border;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
public class CreateAccount extends JFrame implements ActionListener {
Workbook SalesInfo = new HSSFWorkbook();
Sheet Information = SalesInfo.createSheet();
JLabel empid = new JLabel("Enter Employee ID");
JTextField empid = new JTextField(null, 15);
JLabel empname = new JLabel("Enter Employee Name");
JTextField empname = new JTextField(null, 15);
JLabel email = new JLabel("Enter Employee Email");
JTextField email = new JTextField(null, 15);
JLabel Area = new JLabel("Enter Sales Area");
JTextField Area = new JTextField(null, 15);
JLabel salesfig = new JLabel("Enter Employee Salesfig");
JTextField salesfig= new JTextField(null, 15);
JButton okButton = new JButton("OK");
String id;
String name;
String emailaddress;
String salesarea;
String salesnumber;
public CreateAccount() {
add(id);
add(name);
add(emailaddresss);
add(salesarea);
add(salesnumber);
add(okButton);
okButton.addActionListener(this);
setTitle("New sales record Creation");
setVisible(true);
setLocationRelativeTo(null);
setSize(270, 250);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new FlowLayout());
}
private void addAccount(String username, String password) throws
IOException {
FileInputStream file = new FileInputStream(new File("SalesInfo
Information.xls"));
HSSFWorkbook workbook = new HSSFWorkbook(file);
HSSFSheet sheet = workbook.getSheetAt(0);
int newRowIndex = sheet.getPhysicalNumberOfRows(); //index of
new row to create
HSSFRow newRow = sheet.getRow(newRowIndex);
HSSFCell id1 = newRow.createCell(0);
id1.setCellValue(id);
HSSFCell name1 = newRow.createCell(0);
name1.setCellValue(name);
HSSFCell emailaddresss1 =
newRow.createCell(0);
emailaddresss1.setCellValue(emailaddresss);
HSSFCell salesarea1 = newRow.createCell(0);
salesarea1.setCellValue(salesarea);
HSSFCell salesnumber1 = newRow.createCell(0);
salesnumber1.setCellValue(salesnumber);
}
}