Skip to content

Instantly share code, notes, and snippets.

@androidovshchik
Created May 17, 2019 17:41
Show Gist options
  • Save androidovshchik/3c73e9940180b4815d54ec1f8feaafc7 to your computer and use it in GitHub Desktop.
Save androidovshchik/3c73e9940180b4815d54ec1f8feaafc7 to your computer and use it in GitHub Desktop.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
set_time_limit(0);
require __DIR__ . '/vendor/autoload.php';
$file = $_GET['file'];
$code = $_POST['code'];
$name = $_POST['name'];
$quantity = $_POST['quantity'];
$weight = $_POST['weight'];
$price = $_POST['price'];
$path = __DIR__ . '/../documents/' . $file;
if (!file_exists($path)) {
copy(__DIR__ . '/template.xlsx', $path);
}
//Номер штрих кода Наименование товара Кол-во Вес Цена закупки
try {
$excel = PHPExcel_IOFactory::load($path);
$excel->setActiveSheetIndex(0);
$sheet = $excel->getActiveSheet();
$row = 1;
while ($sheet->cellExists("A$row")) {
echo "A$row";
$row++;
}
$sheet->setCellValue("A$row", $code)
->setCellValue("B$row", $name)
->setCellValue("C$row", $quantity)
->setCellValue("D$row", $weight)
->setCellValue("E$row", $price);
$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
$writer->save($path);
} catch (Exception $e) {
die($e->getMessage());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment