PHPOffice / PHPExcel

ARCHIVED
Other
11.46k stars 4.19k forks source link

veryHidden state crashes MS Excel while trying to print #1072

Open echterhoff opened 7 years ago

echterhoff commented 7 years ago

Hi,

I have just encountered a problem I can't really pin point. probably know the reason.

Let me first explain the circumstances. I work with a "template xlsm". So I have prototyped an Excel document with some macro stuff and a tab called "_log". Die underscore character marks "private" tabs.

Now I load the template and add dynamically created sheets. At the end, before writing the file, I run through the sheets and set their states (the private-ones) to veryHidden.

Everything fine. It compiles, opens, works. But printing immediatly crashes the whole Excel application.

If I reset the state through the VBA IDE to hidden and reset it to veryHidden. I can surprisingly print it again.

I have taken a look at the xml. The first lines are from a pure PHPExcel created file.

    <workbookPr codeName="ThisWorkbook" />
    <bookViews>
        <workbookView activeTab="3" autoFilterDateGrouping="1" firstSheet="0" minimized="0" showHorizontalScroll="1" showSheetTabs="1" showVerticalScroll="1" tabRatio="600" visibility="visible" />
    </bookViews>
    <sheets>
        <sheet name="_log" sheetId="1" state="veryHidden" r:id="rId4" />
        <sheet name="V1" sheetId="2" r:id="rId5" />
        <sheet name="V2" sheetId="3" r:id="rId6" />
        <sheet name="V10" sheetId="4" r:id="rId7" />
    </sheets>

Now here is the same part after I simply saved the file in Excel and then extracted it.

    <workbookPr codeName="ThisWorkbook" defaultThemeVersion="124226" />
    <mc:AlternateContent xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
        <mc:Choice Requires="x15">
            <x15ac:absPath url="C:\Users\lars\Desktop\" xmlns:x15ac="http://schemas.microsoft.com/office/spreadsheetml/2010/11/ac" />
        </mc:Choice>
    </mc:AlternateContent>
    <bookViews>
        <workbookView xWindow="0" yWindow="600" windowWidth="21300" windowHeight="10140" firstSheet="1" activeTab="3" />
    </bookViews>
    <sheets>
        <sheet name="_log" sheetId="1" state="veryHidden" r:id="rId1" />
        <sheet name="V1" sheetId="2" r:id="rId2" />
        <sheet name="V2" sheetId="3" r:id="rId3" />
        <sheet name="V10" sheetId="4" r:id="rId4" />
    </sheets>

I found the property firstSheet="0" kind strange and dived into your sources, just to initialize the value to 1. Problem solved. Excel is able to print the sheet with no problems. Since you know your code the best and much more about what this initialization with 0 means, I hope it is okay if I don't take the effort to fork, fix and let you pull my changes.

Have a good one and thanks for your work and effort.

Oh, and in case you need a xls document to let excel crash on print, I can send you mine. ;-)

Lars

echterhoff commented 7 years ago

Oh, by the way... Seems like Excel can't handle the combination of the probably wrong firstSheet="0" plus the veryHidden-State of the first worksheet in combination with the print document initialization. If there is no veryHidden sheet present, the document prints out of the box, just as intended.