0

I have a maser sheet containing multiple sheets. I want to editing DATA sheet shown in the image and I can edit but when i edit the DATA sheet then the data and pivot tables and styling and formatting in Main repot and pivot sheets gets blank . how to stop being formatting and styling gets blank. I am using laravel with maatwebiste.

below is the originalsheet

enter image description here

but when i store and download the updated sheet the sheet gets blank

enter image description here

this is data sheet

enter image description here

 Excel::selectSheetsByIndex(2)->load($final_file_path, function($reader) {
    $reader->sheet('Data', function($sheet) {                                     
       $select_arrays = ['85213','Age','40-49','2019-12-01','111111','Not Stated','Not Stated'];
       $sheet->appendRow($select_arrays);

 }, 'UTF-8')->store('xlsx', storage_path('/'), true);

Above code is working fine but when store to the path all formatting pivots are removed

manjinder
  • 95
  • 1
  • 11

1 Answers1

0

Earlier I was using maatwebiste that does not support Pivot but now in my solution I used COM library used for excel.

Converting excel to pdf using PHP

The solution for the above problem mentioned below:-

// WORKBOOK AND WORKSHEET OBJECTS
$wbk = $xlapp->Workbooks->Open("C:\\xampp\htdocs\php-excel1\PivotReportMockUp.xlsx");
$wks = $wbk->Worksheets(2);
$wks1 = $wbk->Worksheets(1);

// SET CELL VALUE
$wks->Range("B2")->Value = "85552";
$wbk->save();

// OUTPUT WORKSHEET TO PDF
$xlTypePDF = 0;
$xlQualityStandard = 0;
$OpenAfterPublish= True; //`enter code here`
$IgnorePrintAreas = True;

try {
   $wks1->ExportAsFixedFormat($xlTypePDF, "C:\\xampp\htdocs\php-excel1\PivotReport.pdf", $xlQualityStandard,$OpenAfterPublish,$IgnorePrintAreas);

} catch(com_exception $e) {
    echo $e->getMessage()."\n";
    exit;

}
manjinder
  • 95
  • 1
  • 11