diff --git a/excelfilerw.php b/excelfilerw.php new file mode 100644 index 0000000..aadfc15 --- /dev/null +++ b/excelfilerw.php @@ -0,0 +1,171 @@ +getActiveSheet(); + $data = json_decode($_POST['data'], true); + + if (json_last_error() !== JSON_ERROR_NONE) { + echo 'JSON Error: ' . json_last_error_msg(); + exit; + } + + foreach ($data as $rowIndex => $rowData) { + foreach ($rowData as $colIndex => $cellValue) { + // Convert column index (0,1,2...) to Excel letter (A,B,C...) + $colLetter = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($colIndex + 1); + $cellRef = $colLetter . ($rowIndex + 1); // Example: A1, B2 + $sheet->setCellValue($cellRef, $cellValue); + } + } + + + $writer = new Xlsx($spreadsheet); + $writer->save($file); + echo 'success'; + exit; + } catch (Exception $e) { + echo 'Error: ' . $e->getMessage(); + exit; + } + } else { + echo 'Error: Excel file not found'; + exit; + } +} + +// Load employee file +$file = __DIR__ . "/employee.xlsx"; +$data = []; +if (file_exists($file)) { + try { + $spreadsheet = IOFactory::load($file); + $sheet = $spreadsheet->getActiveSheet(); + $data = $sheet->toArray(); + } catch (Exception $e) { + $error = 'Error reading Excel file: ' . $e->getMessage(); + } +} +?> + + + + + Employee Excel Manager + + + +

Employee Excel Manager

+ + +

+ + + + + $row): ?> + + + + + + + +
+ + + + +

Employee Excel file not found. Place employee.xlsx in this folder.

+ + + + +