Excel-to-SECS Structure Conversion Methods
These utility methods convert Excel sheets into hierarchical SecsFormat00 structures using `SecsFormat00` as the container for nested data and typed leaf values. They leverage ```java List<Map<String,Object» ExcelImporter.importExcel(File importFile, String sheetName) ``` to handle all low‑level parsing (including sparse cells). Each method iterates the fixed headers NAME, VALUE0, and VALUE1, ensuring every row yields exactly three entries. Empty cells become empty strings for string fields or zeros for numeric fields.
This method might require a module at runtime for the excel importer.
🔤 Parse All‑String Excel: sf00FromExcel(File importFile, String sheetName)
📋 Description
- Imports the sheet via `ExcelImporter`, producing a `List<Map<String,Object»`, where each map represents a row mapping header → cell value.
- Iterates a fixed header array so that every row yields exactly three entries.
- For each header:
- If the map contains a value, calls `toString()` and wraps it in SecsFormat20.
- If missing or null, wraps `““` in SecsFormat20.
💡 Example Code
public static SecsFormat00 sf00FromExcel(File importFile, String sheetName) { SecsFormat00 outerList = new SecsFormat00(); List<Map<String, Object>> rows = ExcelImporter.importExcel(importFile, sheetName); String[] headers = { "NAME", "VALUE0", "VALUE1" }; for (Map<String, Object> row : rows) { SecsFormat00 rowList = new SecsFormat00(); for (String hdr : headers) { Object raw = row.get(hdr); String s = (raw == null ? "" : raw.toString()); rowList.add(new SecsFormat20(s)); } outerList.add(rowList); } return outerList; }
🧪 Example Input (Excel)
NAME | VALUE0 | VALUE1 |
Temp | 100 | 1.5 |
Pressure | 200 | 2.5 |
✅ Output Structure
[ [<A 'Temp'>, <A '100'>, <A '1.5'>], [<A 'Pressure'>, <A '200'>, <A '2.5'>] ]
🧠 Parse Excel with Auto‑Typed Values: sf00FromExcelAutomaticTypes(File importFile, String sheetName)
📋 Description
- Imports rows the same way, iterating the fixed headers.
- For each header:
1. Retrieve the raw value or `”“` if missing.
2. Trim; if empty: - For **NAME**, wrap `""` in **SecsFormat20**. - For **VALUE0** and **VALUE1**, wrap `0` in **SecsFormat34** (integer). 3. If non‑empty, attempt, in order: - Parse as integer → **SecsFormat34** - Parse as double → **SecsFormat44** - Fallback to **SecsFormat20**
💡 Example Code
public static SecsFormat00 sf00FromExcelAutomaticTypes(File importFile, String sheetName) { SecsFormat00 outerList = new SecsFormat00(); List<Map<String, Object>> rows = ExcelImporter.importExcel(importFile, sheetName); String[] headers = { "NAME", "VALUE0", "VALUE1" }; for (Map<String, Object> row : rows) { SecsFormat00 rowList = new SecsFormat00(); for (String hdr : headers) { String raw = row.getOrDefault(hdr, "").toString().trim(); if (raw.isEmpty()) { if ("NAME".equals(hdr)) { rowList.add(new SecsFormat20("")); } else { rowList.add(new SecsFormat34(0)); } continue; } try { int i = Integer.parseInt(raw); rowList.add(new SecsFormat34(i)); } catch (NumberFormatException e1) { try { double d = Double.parseDouble(raw); rowList.add(new SecsFormat44(d)); } catch (NumberFormatException e2) { rowList.add(new SecsFormat20(raw)); } } } outerList.add(rowList); } return outerList; }
🧪 Example Input (Excel)
NAME | VALUE0 | VALUE1 |
Speed | 55.5 | 1 |
60 |
✅ Output Structure
[ [<A 'Speed'>, <F4 55.50000>, <I4 1>], [<A ''>, <I4 60>, <I4 0>] ]
🧩 Parse Strict Typed Tuples from Excel: sf00FromExcelTypedExample(File importFile, String sheetName)
📋 Description
- Uses fixed headers to produce exactly three fields per row.
- For NAME, takes the string (or `”“` if missing).
- For VALUE0, parses as double (`0.0` if missing).
- For VALUE1, parses as integer (`0` if missing).
- If a non‑empty value fails to parse, a `NumberFormatException` will propagate.
💡 Example Code
public static SecsFormat00 sf00FromExcelTypedExample(File importFile, String sheetName) { SecsFormat00 outerList = new SecsFormat00(); List<Map<String, Object>> rows = ExcelImporter.importExcel(importFile, sheetName); for (Map<String, Object> row : rows) { SecsFormat00 rowList = new SecsFormat00(); // NAME → string String nm = row.getOrDefault("NAME", "").toString().trim(); rowList.add(new SecsFormat20(nm)); // VALUE0 → double String v0 = row.getOrDefault("VALUE0", "").toString().trim(); double d0 = v0.isEmpty() ? 0.0 : Double.parseDouble(v0); rowList.add(new SecsFormat44(d0)); // VALUE1 → integer String v1 = row.getOrDefault("VALUE1", "").toString().trim(); int i1 = v1.isEmpty() ? 0 : Integer.parseInt(v1); rowList.add(new SecsFormat34(i1)); outerList.add(rowList); } return outerList; }
🧪 Example Input (Excel)
NAME | VALUE0 | VALUE1 |
alpha | 1.23 | 100 |
beta | 4.56 | 200 |
✅ Output Structure
[ [<A 'alpha'>, <F4 1.23000>, <I4 100>], [<A 'beta'>, <F4 4.56000>, <I4 200>] ]