2
Contributors
15
Replies
51
Views
1 Year
Discussion Span
Last Post by cereal
Featured Replies
  • 1
    cereal 1,419   1 Year Ago

    For excel or doc files refer to the other PHPOffice projects: * https://github.com/PHPOffice The code would be similar, where instead of calling PhpPresentation you would load PhpWord or PhpExcel. In the source code of the IOFactory class you can see which drivers are supported: * https://github.com/PHPOffice/PHPWord/blob/master/src/PhpWord/IOFactory.php#L28 * https://github.com/PHPOffice/PHPExcel/blob/master/Classes/PHPExcel/IOFactory.php#L66 For more … Read More

  • 1
    cereal 1,419   1 Year Ago

    You have to require the autoload script. But I see that also the [Common](https://github.com/PHPOffice/Common) library is needed. The easiest way to install this package is through [composer](https://getcomposer.org/). Can you use it? Composer is a packager manager for PHP, it gives you access to many libraries listed in: * https://packagist.org/ * … Read More

  • 2
    cereal 1,419   1 Year Ago

    > I see that php presentation and word has bug. May I ask you a question if there is some other way that i can view my office document file locally with my wamp server?? I don't know how this will performe in production servers, but as local solution you … Read More

0

No, not through copy(), that will change only the extension. You can try PHPOffice/PHPPresentation:

For example:

$filename  = '/path/to/file.pptx';
$new_name  = '/destination/path/file.odp';
$phpPPTX   = \PhpOffice\PhpPresentation\IOFactory::load($filename);
$odpWriter = \PhpOffice\PhpPresentation\IOFactory::createWriter($phpPPTX, 'ODPresentation');
$odpWriter->save($new_name);
0

What is this means\PhpOffice\PhpPresentation\IOFactory::load and this \PhpOffice\PhpPresentation\IOFactory::createWriter.Does this will also work on .docx, .doc or .ppt, .xls and other office extensions. Please elaborate. Thank you

Edited by jeffersonalomia

1

For excel or doc files refer to the other PHPOffice projects:

The code would be similar, where instead of calling PhpPresentation you would load PhpWord or PhpExcel. In the source code of the IOFactory class you can see which drivers are supported:

For more information look at their developer documentation.

IOFactory::load() is a static method to load a resource file, the createWriter() method is used, in this case, to convert the loaded file to another format, the segment \PhpOffice\PhpPresentation\ is the namespace in which the IOFactory class is loaded:

Edited by cereal

0

Does \PhpOffice\PhpPresentation\ is a directory or folder inbthe zip file that i have downloaded on github?

0

No, the namespace does not reflect a path into the filesystem. It's used to:

provide a way in which to group related classes, interfaces, functions and constants.

Check the link I provided in my previous post, it explains with examples how the namespace work.

In any case, if you load correctly the library you don't have to worry about the namespace unless you're using PHP lower than 5.3.

0

How and where did you get this stuff
\PhpOffice\PhpPresentation\IOFactory::load($file)

I am new here. please explain on an easy way. thank you

0

Sorry but sad to say that its too complicated to understand those namespace explanation in php.com becausr im not that pro in php

1

You have to require the autoload script. But I see that also the Common library is needed. The easiest way to install this package is through composer. Can you use it?

Composer is a packager manager for PHP, it gives you access to many libraries listed in:

Once installed it's easy to start using PHPOffice:

composer require phpoffice/phppresentation dev-master

This will install also the dependencies packages.

In order to do this manually create a src directory, then download both master zip files:

go into each src directory and copy the Common and the PHPPresentation folders into the src directory you generated, then use a script like this:

<?php

    require_once './src/PhpPresentation/Autoloader.php';
    \PhpOffice\PhpPresentation\Autoloader::register();

    require_once './src/Common/Autoloader.php';
    \PhpOffice\Common\Autoloader::register();

    $filename  = './samples/resources/Sample_12.pptx';
    $new_name  = './file.odp';
    $phpPPTX   = \PhpOffice\PhpPresentation\IOFactory::load($filename);
    $odpWriter = \PhpOffice\PhpPresentation\IOFactory::createWriter($phpPPTX, 'ODPresentation');
    $odpWriter->save($new_name);

You can see a live example here:

Which can be downloaded. To see it at work just type php index.php into the terminal, it will convert the sample file into odp.

0

I tried all what youve said and it work. odp and odt file now can read by viewerJS.However theres a bug on the output. when i convert a docx file to odt which contains a table or shapes. Theres an error saying Division by zero in PhpWord\Writer\ODText\Style\Paragraph.php on line 41.

Also. some odp and odt contents are missing after converting. The odp and odt contents doesnt equal to the original file which is the pptx and docx.

Why is that happen?

0

Do i still need PhpPresentation-develop.zip that i have downloaded?

No, you should use the master version as this is usually the stable version. The develop version introduce some new features but is not stable and it can change, in general develop packages shouldn't be used in production, unless you understand which issues can produce.

However theres a bug on the output. when i convert a docx file to odt which contains a table or shapes. Theres an error saying Division by zero in PhpWord\Writer\ODText\Style\Paragraph.php on line 41.

For library related errors check their documentation:

And if it does not help, then submit a bug report (with full details) to their issues section:

0

I see that php presentation and word has bug. May I ask you a question if there is some other way that i can view my office document file locally with my wamp server?? thank you

2

I see that php presentation and word has bug. May I ask you a question if there is some other way that i can view my office document file locally with my wamp server??

I don't know how this will performe in production servers, but as local solution you could install LibreOffice and perform an headless conversion from command line, something like:

exec("soffice --invisible --headless --convert-to odt file.docx");

More info here: https://help.libreoffice.org/Common/Starting_the_Software_With_Parameters

For the options: just switch from -- to - in case of Windows environment.

In reference to the bugs I would submit them to PHPOffice, these libraries have a user large base, so it's possible that your issues have already be covered and you could get some help or temporary workarounds.

Votes + Comments
Headless thinking. What a concept. +1
perseverence +1
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.