PHPOffice / PHPPresentation

A pure PHP library for reading and writing presentations documents
https://phpoffice.github.io/PHPPresentation
Other
1.31k stars 520 forks source link

Charts are broken / doesn't validate against Office 2013 XML #382

Closed simplyray closed 3 years ago

simplyray commented 7 years ago

I'm using the latest 0.9.0 release but the file generated from the Sample_05_Chart.php is broken and Powerpoint 2016 needs to repair the file before opening it (which removes the charts completly).

Sample_05_Chart.pptx

I've tried to validate the generated *.pptx file against Office 2013 XML formats and it throws 218 errors. Seems like every value for the attribute 'val' is a string having a percentage sign behind it instead of Int32

Progi1984 commented 7 years ago

@simplyray Thanks for the issue.

Where can i find the xsd for validating pptx file against Office 2013 XML formats ? (And may be Office 2007 & 2010)

simplyray commented 7 years ago

@Progi1984 I've used the Open XML SDK Tool from Microsoft. It also includes validation for 2007 and 2010)

validation

Progi1984 commented 7 years ago

Todo :

Progi1984 commented 7 years ago

PR relative to this issue : #390

larryb-redflare commented 7 years ago

See comment on #353 PhpPresentation\Writer\PowerPoint2007\PptCharts Line 102 outputs a % which cause invalid XML

$objWriter->writeElementIf($hPercent != null, 'c:hPercent', 'val', $hPercent . '%');

dlollman commented 6 years ago

@Progi1984 Do you know when this fix will be released?

Currently unable to do any bar charts without ppt being broken and need repairing (but no chart showing up).

Happy to test in any way I can.

Progi1984 commented 6 years ago

@dlollman You can test this branch and give your feedback.

dlollman commented 6 years ago

@Progi1984 Thanks, no good for that branch for me. Using Powerpoint for mac (microsoft). Relevant code I am using to test this out:

$current_slide++;
    // Slide 5 (REDACTED)
    // Create slide
    ////echo date('H:i:s') . ' Create slide '.$current_slide.EOL;
    $slides[$current_slide] = $objPHPPresentation->createSlide();
    $slides[$current_slide]->setName('REDACTED');
    $slides[$current_slide]->setBackground($oBkgImageSlide);

    $richtext = $slides[$current_slide]->createRichTextShape()
            ->setHeight($slide_style["data_slide"]["dimensions"]["height"])
            ->setWidth($slide_style["data_slide"]["dimensions"]["width"])
            ->setOffsetX($slide_style["data_slide"]["dimensions"]["offsetx"])
            ->setOffsetY($slide_style["data_slide"]["dimensions"]["offsety"]);
    $textRun = $richtext->createTextRun('REDACTED');
    $textRun->getFont()->setSize($slide_style["data_slide"]["font"]["size"])
                        ->setItalic($slide_style["data_slide"]["font"]["italic"])
                        ->setColor(new Color($slide_style["data_slide"]["font"]["color"]));
    //add bar chart
    $oFill = new Fill();
    $oFill->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFE06B20'));
    $oShadow = new Shadow();
    $oShadow->setVisible(true)->setDirection(45)->setDistance(10);
    $series1Data = array('Jan' => 133, 'Feb' => 99, 'Mar' => 191, 'Apr' => 205, 'May' => 167, 'Jun' => 201, 'Jul' => 240, 'Aug' => 226, 'Sep' => 255, 'Oct' => 264, 'Nov' => 283, 'Dec' => 293);
    $series2Data = array('Jan' => 266, 'Feb' => 198, 'Mar' => 271, 'Apr' => 305, 'May' => 267, 'Jun' => 301, 'Jul' => 340, 'Aug' => 326, 'Sep' => 344, 'Oct' => 364, 'Nov' => 383, 'Dec' => 379);
    // Create a bar chart (that should be inserted in a shape)
    echo date('H:i:s') . ' Create a bar chart (that should be inserted in a chart shape)'.EOL;
    $barChart = new Bar();
    $barChart->setGapWidthPercent(158);
    $series1 = new Series('2009', $series1Data);
    $series1->setShowSeriesName(true);
    $series1->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new StyleColor('FF4F81BD'));
    $series1->getFont()->getColor()->setRGB('00FF00');
    $series1->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new StyleColor('FFE06B20'));
    $series2 = new Series('2010', $series2Data);
    $series2->setShowSeriesName(true);
    $series2->getFont()->getColor()->setRGB('FF0000');
    $series2->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new StyleColor('FFC0504D'));
    $series2->setLabelPosition(Series::LABEL_INSIDEEND);
    $barChart->addSeries($series1);
    $barChart->addSeries($series2);
    // Create a shape (chart)
    echo date('H:i:s') . ' Create a shape (chart)'.EOL;
    $shape = $slides[$current_slide]->createChartShape();
    $shape->setName('PHPPresentation Monthly Downloads')
        ->setResizeProportional(false)
        ->setHeight(550)
        ->setWidth(700)
        ->setOffsetX(120)
        ->setOffsetY(80);
    $shape->setShadow($oShadow);
    $shape->setFill($oFill);
    $shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
    $shape->getTitle()->setText('PHPPresentation Monthly Downloads');
    $shape->getTitle()->getFont()->setItalic(true);
    $shape->getTitle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
    $shape->getPlotArea()->getAxisX()->setTitle('Month');
    $shape->getPlotArea()->getAxisY()->getFont()->getColor()->setRGB('00FF00');
    $shape->getPlotArea()->getAxisY()->setTitle('Downloads');
    $shape->getPlotArea()->setType($barChart);
    $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
    $shape->getLegend()->getFont()->setItalic(true);
dlollman commented 6 years ago

@Progi1984 is there anything else I can try here to help out?

Progi1984 commented 6 years ago

@dlollman You can help to fix this comment #382#issuecomment-346697422

dlollman commented 6 years ago

@Progi1984 That comment has a commit referencing a change for sample 20 which seems to not have any bearing on sample 5 (charts), can you confirm what you want me to do?

Thanks so much

Progi1984 commented 6 years ago

@dlollman With this branch, Sample 05 generate slides without charts, you can start by fixing it :) Thank you for advance

Progi1984 commented 6 years ago

I just found the problem for charts in pptx But I must find why it's not valid now.

Progi1984 commented 6 years ago

Open XML is so hard to validate... I'm looking for a lasting solution for OpenXML which support Office 2007 / 2010 / 2013 / 2016 / 2019... (#510)

Actually, I only found schema for Office 2010 so it's not lasting. If i found for Office 2007, I will release this PR.

Progi1984 commented 6 years ago

@Zetkolink @pcholewa From #507 @phpsb @mhasanshahid From #505 @phpsb @dlollman @amitrajput92 @larryb-redflare From #353

If anything has informations about schema (XSD) for validating Office 2007 files, I'm interested.

larryb-redflare commented 6 years ago

Have you tried ....

https://www.microsoft.com/en-us/download/confirmation.aspx?id=4463

Progi1984 commented 6 years ago

@larryb-redflare Thank you. But no information inside :

This download provides documentation in CHM and HTML format for schemas used in the 2007 Microsoft Office system including the following products:

  • Microsoft Office Outlook 2007
  • Microsoft Office OneNote 2007
  • Microsoft Office Visio 2007

Important The download also includes the the Ribbon extensibility schema, customUI.xsd.

larryb-redflare commented 6 years ago

I know higher in the thread someone linked to the Micsoroft XML SDK kit 2.5; maybe the older one v2.0 might help if you don't already have it ...

https://www.microsoft.com/en-ie/download/details.aspx?id=5124

First line of blurb says ,... Open XML is an open ECMA 376 standard and is also approved as the ISO/IEC 29500 standard that defines a set of XML schemas for representing spreadsheets, charts, presentations, and word processing documents. Microsoft Office Word 2007, Excel 2007, and PowerPoint 2007 all use Open XML as the default file format.

Progi1984 commented 6 years ago

@larryb-redflare & all :)

ECMA 376 is here : https://www.ecma-international.org/publications/standards/Ecma-376.htm

Office 2007 is based on the first version and schemas are in the part 4 :

Badly, I don't succeed to use schemas.

In the 2nd edition (Office2010 : ECMA-376, Second Edition, Part 4 - Transitional Migration Features.zip\OfficeOpenXML-XMLSchema-Transitional.zip), you have a pml.xsd which makes all good imports. In the first edition (Office Open XML 1st edition Part 4 (PDF).zip\OfficeOpenXML-XMLSchema.zip), there is not any main file for PresentationML (PML).

Note :

Progi1984 commented 6 years ago

@larryb-redflare A solution could be to create my own xsd based from ECMA 376 -1st edition...

pcholewa commented 6 years ago

will the problem be solved?

Progi1984 commented 6 years ago

@pcholewa No, but we are open to pull requests & help :)

Progi1984 commented 5 years ago

After a lot of search, I must create my own XSD with merging all xsd.

http://jmvanel.free.fr/xsd/README.html http://www.adrianmouat.com/bit-bucket/2013/11/xml-schema-validation/

pcholewa commented 5 years ago

@Progi1984 Any chance that you will to do it?

Progi1984 commented 5 years ago

@pcholewa I will try to work on it when I get some free time.

pcholewa commented 5 years ago

@Progi1984 thx for info

Progi1984 commented 5 years ago

ecma_house.zip

To integrate in the branch

Progi1984 commented 5 years ago

I may have fixed this file for PowerPoint2007 files... I must check each rendering in Office.

Progi1984 commented 5 years ago

@Zetkolink @pcholewa From #507 @mhasanshahid From #505 @dlollman @amitrajput92 @larryb-redflare From #353

Hi here, The PR has been finally fixed... Could you test on develop branch and give me some feedback ?

JavierDelSolar commented 5 years ago

Hi, im trying to create charts, i have the same problem... somebody can?

CarmenR13 commented 5 years ago

Hi, I´m using the develop branch to run Sample_05_Chart but the Stacked Bar and the Stacked Percentage Bar charts are removed from the resulting pptx file.

I'm getting the following errors:

image

Any help?

AlexanderKulia commented 5 years ago

Hi, is there any way to make charts work? I tried creating a few, but I always get "Repairment needed" message. Interestingly enough, in Sample_05_Chart two slides are actually created: a 3D pie chart and a non-3D pie chart, other slides are blank. Any idea why?

MehdiAroui commented 4 years ago

@dsjkaa same problem here, any solution ?

ingo-lorenz commented 4 years ago

Is there already a solution for this problem? You cannot use generated PPTX files with charts in current Office versions.

I have already tested the dev-master.

Thanks to you

Ingo

akmalirfan commented 4 years ago

For my case, I fixed this issue (partially, at least) by changing the source code in 0.9.0 release following the latest source code (at the time of writing) in develop branch. This means, the developers are already working on it but it is not ready for release yet.

Particularly, I changed the code for writing c:hPercent in PptCharts.php by deleting the percent symbol and the code for writing a:alpha in AbstractDecoratorWriter.php by deleting the percent symbol and multiply the $alpha by 1000.

These files can be found in /src/PhpPresentation/Writer/PowerPoint2007/

Now, when I exported the .pptx, the chart can be viewed when I opened it using PowerPoint Online. It might still does not pass the validation but at least, the chart is visible now. That is what important to me.

Lastly, thank you to the developers and all contributors for this library.

EDIT: Or you can just simply use the develop branch by specifying "dev-develop" in your composer.json. And also, for the file generated using develop branch, I found no validation error when validating it using Open XML SDK 2.5.

Progi1984 commented 3 years ago

Hi all, I think it is fixed on develop branch. Could you check it @akmalirfan @ingo-lorenz @MehdiAroui @AlexanderKulia ?

akmalirfan commented 3 years ago

Yes it is. Thanks @Progi1984