最迅速的是渲染阵列,以Excel 2007中,只是在台式机上安装谷歌云端硬盘应用访问数据。 Spreadsheets API无法创建文档,需要使用Docs API来完成;目前PHP的API封装不支持这两个端点 - 就像我可以修改这些文件一样。及时的努力:1小时。
更新:当我使用Excel2007渲染XLSX时,转换失败。当我用MS-Excel和“另存为”打开同一个文件时 - 即使在Drive API上,我也可以将其转换。
我注意到解压文件时,相比一些事情:
一)MS-Excel使用值 '0/1',而不是 '假/真'
二)目录“XL /工作表/ _rels'被删除了(可能没用?)。
c)XML的行尾从UNIX转换到DOS。
d)MS-Excel将所有空白单元格添加到XML-- PHPExcel没有写出。
e)关系ID似乎被移位......在代码中有+3的计算?
问题是生成的文件格式与Drive API的XML解析器不匹配。
我还不能完全确定什么是错的,生成的文件格式, 但修补呈现XLSX与MS-Excel的本地创建的XML文件的文件使得它的工作:
/* how-to patch the generated XLSX: */
$zip = new ZipArchive();
$zip->open($xlsx_path);
$zip->extractTo($export_dir.'temp');
$zip->close();
$this->deleteDir($export_dir.'temp/xl/worksheets/_rels');
$files =array(
'_rels/.rels',
'docProps/app.xml',
'docProps/core.xml',
'xl/workbook.xml',
'xl/_rels/workbook.xml.rels',
'xl/theme/theme1.xml'
);
foreach($files as $file){
copy($export_dir.'template/'.$file, $export_dir.'temp/'.$file);
}
unlink($xlsx_path);
if($zip->open($xlsx_path, ZIPARCHIVE::CREATE)) {
$source = str_replace('\\', '/', realpath($export_dir.'temp'));
if(is_dir($source) === true) {
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file) {
$file = str_replace('\\', '/', $file);
if(in_array(substr($file, strrpos($file, '/')+1), array('.', '..'))){continue;}
$file = realpath($file);
if(is_dir($file) === true){$zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));}
else if(is_file($file) === true){
$zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
}
}
}
else if(is_file($source) === true) {
$zip->addFromString(basename($source), file_get_contents($source));
}
$zip->close();
}
细胞格式不太适合 - 但转换&预览正在工作。
甚至可以从修补中跳过一些XML文件,而其他一些XML文件则会使其中断。
一些说明: - 1.您是否说过完全相同的文件可以通过Web界面进行上传/转换,但通过API失败50?如果是这样,请检查您的Base64编码是否正确。 2.您可以上传而无需转换。如果您尝试在网络界面中“转换为Google文档”,会发生什么情况? – pinoyyid 2012-09-05 02:09:46
如果我通过网页浏览器上传转换 - 它的工作原理,转换已保存在API上的文件不会转换(进度条卡住);我正在使用PHP的google-api包装器。 – 2012-09-05 14:51:54