Here my snippet code
require_once 'readernew.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('CP1251');
$data->read('InOut.xlsx');
$res = $data->sheets;
var_dump($data);
but it give the error like filename is not readable without the password protection
will you please help to access .xlsx file
You can use PHPExcel to read XLSX.
<?php
$objPHPExcel = PHPExcel_IOFactory::load('InOut.xlsx');
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
var_dump($sheetData);
Related
I am having trouble reading the .xls file. Values are read as null and in unknown characters. The file is downloaded from an ftp server and it comes protected
$path = 'doc/20180719-ASK FIDC_EVOLUCAO_COTA.xls';
$inputFileType = PHPExcel_IOFactory::identify($path);
$reader = PHPExcel_IOFactory::createReader($inputFileType);
$reader->setReadDataOnly(true);
$reader->setInputEncoding('ISO-8859-1');
//$reader->setDelimiter("\t");
$excel = $reader->load($path);
var_dump($excel);
echo $inputFileType;
$writer = PHPExcel_IOFactory::createWriter($excel, 'CSV');
$writer->setUseBOM(true);
$writer->save('data.csv');
echo 'File saved to csv format';
The converted file looks like the image:
I am creating excel file with single worksheet using PHPExcel.
I have managed to do this but the issue came after when I created it ones then it didn't get clear so when I am creating it again the the previous data came along with the new data.
So I am just want to clear the excel file before using it again.
Here is the code:
require_once APPPATH.'third_party/PHPExcel.php';
require_once APPPATH.'third_party/PHPExcel/IOFactory.php';
//Getting Data form database
$bTob_gstdata = $this->reports_model->get_bTob_gstdata($date_from, $date_to);
//Sample Excel File (which is clear already Just contain the structure)
$filename = 'assets/btob_base_excel.xls';
$objPHPExcel = PHPExcel_IOFactory::load($filename);
echo $filetype = PHPExcel_IOFactory::identify($filename);
$excel2 = PHPExcel_IOFactory::createReader($filetype);
$excel2 = $excel2->load('assets/btob_base_excel.xls'); // Empty Sheet
$excel2->setActiveSheetIndex(0);
$t=0;
$total_invoice_count = 0;
$recipients_count = array();
$invoice_count = array();
for($k=5;$k<(count($bTob_gstdata)+5);$k++)
{
//Adding Data in Excel WorkSheet
$excel2->getActiveSheet()
->setCellValue('A'.$k, $bTob_gstdata[$t]["dist_gstin"]);
$t++;
}
$excel2->getActiveSheet()->setCellValue('A3', (count($recipients_count)));
$excel2->getActiveSheet()->setCellValue('B3', (count($invoice_count)));
$excel2->getActiveSheet()->setCellValue('D3', '=SUM(D5:D'.(count($bTob_gstdata)+5).')');
$excel2->getActiveSheet()->setCellValue('J3', '=SUM(J5:J'.(count($bTob_gstdata)+5).')');
$excel2->setActiveSheetIndex(0);
$objWriter = PHPExcel_IOFactory::createWriter($excel2, $filetype);
$objWriter->save('btocl_gst_report.xls'); //Saving the excel file
header("location:".base_url("btob_gst_report.xls")); // Downloading the excel file
I want to clear the created excel file to Reuse
Can anybody help to solve this issue, i am new for PHPExcel Libraries,
I want to delete image which is on excel file using PHPExcel.
I did some code here but i am getting error of
Notice: main(): ArrayIterator::next(): Array was modified outside object and internal position
<?php
require_once '../Classes/PHPExcel/IOFactory.php';
require_once '../Classes/PHPExcel.php';
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load(files/test.xlsx);
$objPHPExcel->setActiveSheetIndex(1);
$objPHPExcel = $objPHPExcel->getActiveSheet(1)->getDrawingCollection();
foreach ($objPHPExcel as $key => $drawing){
$objPHPExcel->offsetUnset($key);
}
$objReader = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objReader->save('excel-files/new_test.xlsx');
?>
I want to automatically generate new excel file if i run this code:
//file.php
$arrtweet[] = array(....);
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load("file/ABCDay-1.xlsx");
$objSheet = $objPHPExcel->getActiveSheet();
$objSheet->setTitle('Data ABC Day-1');
$objSheet->getCell('A1')->setValue('User_ID');
$objSheet->getCell('C1')->setValue('Content');
$objSheet->getCell('D1')->setValue('Timestamp');
$objPHPExcel->getActiveSheet()->fromArray($arrtweet, NULL, 'A2');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,"Excel2007");
$objWriter->save("file/ABCDay-1.xlsx");
What I want is:
PHP will automatically generate new excel file if I run that codes for day-2,day-3...,day-N
. Is that possible? Can you help me? thank you so much :')
I am uploading .xlsx using PHPexcel and it was working fine, but when I used comment for some cells then its not working.
$exfile1 = $_FILES["my_file"]["tmp_name"];
$objPHPExcel = PHPExcel_IOFactory::load($exfile1);
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
var_dump($sheetData);