mk-j / PHP_XLSXWriter

Lightweight XLSX Excel Spreadsheet Writer in PHP
MIT License
1.84k stars 665 forks source link

BUG: incorrect mime-type detection due to content written in wrong order... #252

Closed AzzaAzza69 closed 1 year ago

AzzaAzza69 commented 4 years ago

Having generated an xlsx from code (mimetype detected as application/zip) and also creating one in Excel (mimetype detected as application/vnd.openxmlformats-officedocument.spreadsheetml.sheet), writing the files in this order will fix it:

                            $zip->addFromString("[Content_Types].xml"     , self::buildContentTypesXML() );

                            $zip->addEmptyDir("_rels/");
                            $zip->addFromString("_rels/.rels", self::buildRelationshipsXML());

                            $zip->addEmptyDir("xl/");
                            $zip->addFromString("xl/workbook.xml"         , self::buildWorkbookXML() );
                            $zip->addEmptyDir("xl/_rels/");
                            $zip->addFromString("xl/_rels/workbook.xml.rels", self::buildWorkbookRelsXML() );

                            $zip->addEmptyDir("xl/worksheets/");
                            foreach($this->sheets as $sheet) {
                                            $zip->addFile($sheet->filename, "xl/worksheets/".$sheet->xmlname );
                            }
                            $zip->addFile($this->writeStylesXML(), "xl/styles.xml" );  //$zip->addFromString("xl/styles.xml"           , self::buildStylesXML() );

                            $zip->addEmptyDir("docProps/");
                            $zip->addFromString("docProps/core.xml", self::buildCoreXML());
                            $zip->addFromString("docProps/app.xml" , self::buildAppXML() );
AzzaAzza69 commented 4 years ago

188