Я пытаюсь создать таблицы OpenDocument с помощью PHP. Это мой код:
$content_xml = '<?xml version="1.0" encoding="UTF-8"?><office:document-content ...';
$file = 'spreadsheet.ods'; // this one is beeing generated. It is not existent yet...
$zipfile = 'container.zip'; // this one already exists. It's in the same directory
// this script is in. I created the container.zip by unziping a usual .ods file,
// removing the content.xml and ziping again
$handle1 = fopen($zipfile, "r");
$handle2 = fopen($file, "w");
// writing the content of the `container.zip` to the `spreadsheet.ods`
fwrite($handle2, fread($handle1, filesize($zipfile)));
fclose($handle1);
fclose($handle2);
$zip = new ZipArchive();
$zip->open($file, ZIPARCHIVE::CREATE);
// adding the xml string to the zip file
$zip->addFromString('content.xml',$content_xml);
$zip->close();
header('Content-disposition: attachment; filename="'.$file.'"');
header('Content-Type: application/vnd.oasis.opendocument.spreadsheet');
header('Content-Length: ' . filesize($file));
readfile($file);
unlink($file);
Если я открываю сгенерированный файл с помощью OpenOffice - все выглядит нормально. Но MS Excel почему-то не может открыть файл. Я думаю, что строка XML в $content_xml
повреждена. Я не хочу никого беспокоить этой строкой - она огромна! Я получил это из простой электронной таблицы ods. Я только что отредактировал часть <office:body>...</office:body>
.
Мне интересно, хороший ли это способ создания электронных таблиц. Кто-нибудь знает учебник для этой задачи:
- делать все эти почтовые вещи
- структура простого content.xml в файле ods
Что касается «1. делать все эти zip-файлы»: здесь я создаю content.xml
и добавляю его в корень структуры .ods.
Configurations2 // Folder
META-INF // Folder
Thumbnails // Folder
meta.xml
mimetype
settings.xml
styles.xml
При выполнении
$zip->addFromString('content.xml',$content_xml);
Но как добавить файл НЕ в корень структуры, а (допустим) в Configurations2/images/Bitmamps
?