Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/catoth/html2opendocument
Converting simple HTML to Opendocument Text (ODT) or Spreadsheets (ODS)
https://github.com/catoth/html2opendocument
Last synced: about 2 months ago
JSON representation
Converting simple HTML to Opendocument Text (ODT) or Spreadsheets (ODS)
- Host: GitHub
- URL: https://github.com/catoth/html2opendocument
- Owner: CatoTH
- License: mit
- Created: 2016-01-30T19:40:24.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-07-15T07:30:15.000Z (over 1 year ago)
- Last Synced: 2024-11-10T07:42:32.687Z (about 2 months ago)
- Language: PHP
- Homepage:
- Size: 95.7 KB
- Stars: 10
- Watchers: 4
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
This is a simple PHP-library to create create OpenDocument Text- and Spreadsheet-files (ODT / ODS) from HTML-formatted text.
It does not support formulae / calculations in spreadsheets. The focus lies on formatted text.
Please note that this library is mainly developed for [Antragsgrün](https://github.com/CatoTH/antragsgruen). For most other projects trying to write ODT and ODS files, [PhpSpreadsheet](https://phpspreadsheet.readthedocs.io/) will probably be the better choice.
## Example Scripts
A demo script for the OpenDocument Text converter using the default template:
```php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php');$html = '
This is a demo for the converter.
The converter supports the following styles:
- Lists (UL / OL)
- STRONG
- U (underlined)
- S (strike-through)
-
EM (emphasis / italic) -
INS (Inserted text) -
DEL(Deleted text) - Line
breaks with BR
You can also use BLOCKQUOTE, though it lacks specific styling for now';
$html2 = '
You might be interested
in the fact that this converter
also supports
line numbering
for selected paragraphs
Dummy Line
Dummy Line
Dummy Line
Dummy Line
Dummy Line
$odt = new \CatoTH\HTML2OpenDocument\Text();
$odt->addHtmlTextBlock('
Test Page
');$odt->addHtmlTextBlock($html, false);
$odt->addHtmlTextBlock('
Line Numbering
');$odt->addHtmlTextBlock($html2, true);
$odt->finishAndOutputOdt('demo.odt');
```
A demo script for the OpenDocument Spreadsheet converter using the default template:
```php
use CatoTH\HTML2OpenDocument\Spreadsheet;
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php');
$ods = new \CatoTH\HTML2OpenDocument\Spreadsheet();
// Setting to landscape mode with custom page margins
$ods->setMargins("20mm", "10mm", "10mm", "20mm");
$ods->setPageOrientation("297mm", "210mm", "landscape");
// Plain text
$ods->setCell(0, 0, Spreadsheet::TYPE_TEXT, 'Plain text with native formatting');
$ods->setCellStyle(0, 0, [], ['fo:font-weight' => 'bold']);
// Print a number as an actual number, just a little bit bigger
$ods->setCell(1, 0, Spreadsheet::TYPE_NUMBER, 23);
$ods->setCellStyle(1, 0, [], [
'fo:font-size' => '16pt',
'fo:font-weight' => 'bold',
]);
$ods->setMinRowHeight(1, 1.5);
// Print a number as text
$ods->setCell(2, 0, Spreadsheet::TYPE_TEXT, '42');
// Draw a border around two of the cells
$ods->drawBorder(1, 0, 2, 0, 1);
// Now we use HTML, and we need a bit more space for that
$html = '
The converter supports the following styles:
- STRONG
- U (underlined)
- S (strike-through)
-
EM (emphasis / italic) - Inserted text
Deleted text- Line
breaks with BR - Lists (UL / OL) cannot be displayed as lists, but will be flattened to paragraphs
You can also use BLOCKQUOTE, though it lacks specific styling for now';
$ods->setMinRowHeight(3, 10);
$ods->setColumnWidth(1, 20);
$ods->setCell(3, 1, Spreadsheet::TYPE_HTML, $html);
$ods->finishAndOutputOds('demo.ods');
```
## License
This library is licensed under the [MIT license](http://opensource.org/licenses/MIT)