-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDeleteItem.java
110 lines (82 loc) · 3.42 KB
/
DeleteItem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package invertorymanagement;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
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.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
/**
*
* @author partha
*/
public class DeleteItem {
static FileInputStream fis;
static File file;
static File f;
static HSSFWorkbook hssfw;
static Workbook wb;
static HSSFSheet hssfs;
static FormulaEvaluator formulaEvaluator;
static String Code,name;
static String cellid;
static double Price,TotalPrice;
static boolean check;
static Sheet s;
public DeleteItem( String Item_Code) throws FileNotFoundException, IOException, InvalidFormatException{
Code = Item_Code;
// Quantity =item_Quantity;
//System.out.println("Id:"+this.Id+"\n Pass: "+this.Password);
f =new File("Items.xlsx");
fis = new FileInputStream(f);
file =new File("Items.xlsx");
if(file.exists() && f.exists()){
hssfw = new HSSFWorkbook(fis);
hssfs = hssfw.getSheetAt(0);
// s=hssfw.getSheetAt(0);
}
for (int rowIndex = 0; rowIndex <= hssfs.getLastRowNum(); rowIndex++) {
Row row = hssfs.getRow(rowIndex);
if (row != null) {
Cell cell0 =row.getCell(0);
Cell cell = row.getCell(1);
Cell cell1 = row.getCell(3);
if (cell != null) {
// Found column and there is value in the cell.
cellid = cell.getStringCellValue();
if(cellid.equals(Code)){
Row rowh = hssfs.getRow(rowIndex);
name = cell0.getStringCellValue();
DeleteItem.Price =cell1.getNumericCellValue();
hssfs.removeRow(rowh);
row = hssfs.createRow(rowIndex);
row.createCell(0).setCellValue(this.name);
row.createCell(1).setCellValue(cellid);
row.createCell(2).setCellValue(0);
row.createCell(3).setCellValue(this.Price);
row.createCell(4).setCellValue(0);
check = true;
System.out.println(name);
}
}
}
}
FileOutputStream fos = new FileOutputStream(file);
hssfw.write(fos);
hssfw.close();
fos.close();
// return false;
}
}