Reputation: 163
I am trying to create webform and storing submitted data in excel sheet
below is the HTML code saved as"update1.html"
<form action=xcel.php method="post">
<p>
<lable>ENTER SAMPLE NAME</lable>
<input type="text" name="so">
<p>
<lable>ENTER STATUS</lable>
<input type="text" name="status">
</p>
<p><button>UPDATE</button></p>
</form>
and PHP script as "xcel.php"
<?php
$SO_ID=$_POST['so'];
$Status=$_POST['status'];
require_once 'Classes/PHPExcel.php';
require_once 'Classes/PHPExcel/IOFactory.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->PHPExcel_IOFactory::load("asheet.xlsx");
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue('A1', $SO_ID);
$objPHPExcel->getActiveSheet()->setCellValue('B1', $Status);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save("asheet.xlsx");
and in excel sheet i.e "asheet.xlsx" 2 column are there "so" and "status".
I need to take user input from web form and store that in the excel sheet like how we store data in database.
i am not getting proper formatted data in excel sheet.
any further information feel free to ask
thanks in advance
Upvotes: 1
Views: 3795
Reputation: 212412
OK, spoon-feeding time
EITHER
<?php
$SO_ID=$_POST['so'];
$Status=$_POST['status'];
$fp=fopen("/var/www/html/apps/asheet.xlsx","w");
fputcsv($fp, array($SO_ID, $Status), ';');
fclose($fp);
echo"thanks";
to write a csv file with a ;
delimiter, and pretend that it's an Excel file
OR
<?php
$SO_ID=$_POST['so'];
$Status=$_POST['status'];
require_once 'Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->getActiveSheet()->setCellValue('A1', $SO_ID);
$objPHPExcel->getActiveSheet()->setCellValue('B1', $Status);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save("/var/www/html/apps/asheet.xlsx");
Upvotes: 2