Created
September 10, 2014 03:45
-
-
Save 77web/7a131deb89650fe6203b to your computer and use it in GitHub Desktop.
最小限のexcelファイルを新規作成する試作品
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$contentTypeXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | |
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"> | |
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/> | |
<Default Extension="xml" ContentType="application/xml"/> | |
<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/> | |
<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/> | |
<Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/> | |
</Types>'; | |
$workbookXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | |
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"> | |
<sheets><sheet name="hoge" sheetId="1" r:id="rId1"/></sheets> | |
</workbook>'; | |
$workbookRelXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | |
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"> | |
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/> | |
</Relationships>'; | |
$coreXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | |
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
<dc:creator>Excel.Generator</dc:creator> | |
</cp:coreProperties>'; | |
$relsXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | |
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"> | |
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/> | |
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/> | |
</Relationships>'; | |
$sheetXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | |
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"> | |
<sheetData/> | |
</worksheet>'; | |
if (file_exists('output.xlsx')) { | |
unlink('output.xlsx'); | |
} | |
$zip = new \ZipArchive; | |
$zip->open('output.xlsx', \ZipArchive::CREATE); | |
// required files | |
$zip->addFromString('_rels/.rels', $relsXml); | |
$zip->addFromString('[Content_Types].xml', $contentTypeXml); | |
$zip->addFromString('docProps/core.xml', $coreXml); | |
$zip->addFromString('xl/workbook.xml', $workbookXml); | |
$zip->addFromString('xl/_rels/workbook.xml.rels', $workbookRelXml); | |
// sheet file | |
$zip->addFromString('xl/worksheets/sheet1.xml', $sheetXml); | |
$zip->close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment