import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.*;
import java.util.Collections;
import java.util.List;
public class ExcelOrderParser {
public static void main(String[] args) {
try {
FileInputStream file = new FileInputStream(new File("order_report.xlsx"));
Workbook workbook = WorkbookFactory.create(file);
Sheet sheet = workbook.getSheetAt(0);
// Iterate over rows and process order details
for (Row row : sheet) {
Cell nameCell = row.getCell(0);
Cell materialCell = row.getCell(1);
Cell destinationCell = row.getCell(2);
// Extract and process order details
String name = nameCell.getStringCellValue();
String material = materialCell.getStringCellValue();
String destination = destinationCell.getStringCellValue();
// Split name into parts if possible
String[] nameParts = name.split(" ");
// Create a new row in the output document
Row newRow = sheet.createRow(sheet.getLastRowNum() + 1);
newRow.createCell(0).setCellValue(nameParts[0]);
newRow.createCell(1).setCellValue(nameParts.length > 1 ? nameParts[1] : "");
newRow.createCell(2).setCellValue(material);
newRow.createCell(3).setCellValue(destination);
}
// Write the modified workbook to a new file
FileOutputStream out = new FileOutputStream(new File("processed_orders.xlsx"));
workbook.write(out);
out.close();
workbook.close();
file.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class OrderSorter {
public static void sortOrdersByMaterial(List<Order> orders) {
Collections.sort(orders, (o1, o2) -> o1.getMaterial().compareTo(o2.getMaterial()));
}
public static void sortOrdersByDestination(List<Order> orders) {
Collections.sort(orders, (o1, o2) -> o1.getDestination().compareTo(o2.getDestination()));
}
}
public class Order {
private String name;
private String material;
private String destination;
public Order(String name, String material, String destination) {
this.name = name;
this.material = material;
this.destination = destination;
}
// Getters and Setters
public String getName() {
return name;
}
public String getMaterial() {
return material;
}
public String getDestination() {
return destination;
}
}