QtExcel / QXlsx

Excel file(*.xlsx) reader/writer library using Qt 5 or 6. Descendant of QtXlsxWriter.
https://qtexcel.github.io/QXlsx/
MIT License
1.17k stars 358 forks source link

Header and Footer are not read in and saved from existing excel file #39

Closed WalSpek closed 5 years ago

WalSpek commented 5 years ago

If you read in an existing excel file with header and/or footer, they where not saved correctly.

I have changed following functions: LoadFromXmlFile:

        } else if(reader.name() == QLatin1String("headerFooter")){                  
            while (reader.readNextStartElement())
            {
                if (reader.name() == QLatin1String("oddHeader"))
                    d->ModdHeader = reader.readElementText();

                if (reader.name() == QLatin1String("oddFooter"))
                        d->MoodFooter = reader.readElementText();
            }

saveToXmlFile:

// headerFooter
if( !d->ModdHeader.isNull() || !d->MoodFooter.isNull())
{
    writer.writeStartElement(QStringLiteral("headerFooter")); // headerFooter  

    if (!d->ModdHeader.isNull())
    {
        writer.writeStartElement(QStringLiteral("oddHeader"));
        writer.writeAttribute(QStringLiteral("xml:space"), QStringLiteral("preserve"));
        writer.writeCharacters(d->ModdHeader);
        writer.writeEndElement();// t

        // writer.writeTextElement(QStringLiteral("oddHeader"), d->ModdHeader);
    }

    if (!d->MoodFooter.isNull())
    {
        writer.writeTextElement(QStringLiteral("oddFooter"), d->MoodFooter);
    }

    writer.writeEndElement();// headerFooter
}

after this changes you can read/write existing files with header and/or footer

Walter

j2doll commented 5 years ago

Thanks for reporting. It seems to be an unresolved bug. https://github.com/QtExcel/QXlsx/issues/18

j2doll commented 5 years ago

I'm working on a branch called dev40. Please test dev40.

WalSpek commented 5 years ago

I have tested the dev40 regarding my issues and they are OK!

I have 2 further issues found, please see the attachment.

Thank you for cooperating in this issues!

Mit freundlichen Grüßen

Best regards

Walter Eglseer, MBA

Geschäftsleitung / Managing Director

Spektra LED Gmbh

Licht- und EnergieDienstleistungen

Erlau 5

4770 Andorf

Austria

Mobil: +43 699 11 34 35 36

email: w.eglseer@spektraled.at mailto:email:%20w.eglseer@spektraled.at

http://www.spektraled.at/ http://www.spektraled.at

HINWEIS: Dies ist eine vertrauliche Nachricht und nur für den Adressaten bestimmt. Es ist nicht erlaubt, diese Nachricht zu kopieren oder Dritten zugaenglich zu machen. Sollten Sie irrtuemlich diese Nachricht erhalten haben, bitte ich um Ihre Mitteilung per E-Mail oder unter der oben angegebenen Telefonnummer.

Privileged/Confidential Information may be contained in this message. If you are not the addressee indicated in this message (or responsible for delivery of the message to such person), you may not copy or deliver this message to anyone. In such case, you should destroy this message, and notify us immediately. If you or your employer does not consent to Internet E-Mail messages of this kind, please advise us immediately. Opinions, conclusions and other information expressed in this message are not given or endorsed by my firm or employer unless otherwise indicated by an authorized representative.

Von: Jay Two notifications@github.com Gesendet: Samstag, 1. Juni 2019 16:56 An: QtExcel/QXlsx QXlsx@noreply.github.com Cc: WalSpek w.eglseer@spektraled.at; Author author@noreply.github.com Betreff: Re: [QtExcel/QXlsx] Header and Footer are not read in and saved from existing excel file (#39)

I'm working on a branch called dev40. Please test dev40.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/QtExcel/QXlsx/issues/39?email_source=notifications&email_token=AMG6MXM7RZOGCWQDVUT44MTPYKEXNA5CNFSM4HR54RA2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWXCFJA#issuecomment-497951396 , or mute the thread https://github.com/notifications/unsubscribe-auth/AMG6MXOAUVFUSOBZDT6MF73PYKEXNANCNFSM4HR54RAQ . https://github.com/notifications/beacon/AMG6MXKOKUF5UCNEXWEXZY3PYKEXNA5CNFSM4HR54RA2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWXCFJA.gif

Changes for Dev40:

xlsxdrawinganchor: // Q_ASSERT will only occure in Debugg Mode

QPoint DrawingAnchor::loadXmlPos(QXmlStreamReader &reader) { Q_ASSERT(reader.name() == QLatin1String("pos") || // function is called from different Elements reader.name() == QLatin1String("off"));

QPoint pos;
QXmlStreamAttributes attrs = reader.attributes();
pos.setX(attrs.value(QLatin1String("x")).toString().toInt());
pos.setY(attrs.value(QLatin1String("y")).toString().toInt());
return pos;

}

xlsxcell: // If you open an Excel Sheet with the xlsxwriter including a formula which is not valid actually (Division with 0) // the formula will not be saved correctly when you save the Excel file with the xlsxwriter // A simple solution I made is to ignore the ErrorType when it's a Formula....

Cell::CellType Cell::cellType() const { Q_D(const Cell);

if (hasFormula() && d->cellType == Cell::ErrorType) // ignore ErrorType on Formula
    return Cell::NumberType;
else
    return d->cellType;

}

j2doll commented 5 years ago

I merged dev40 branch to master branch. I'll close this issue.