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

Write excel warning by QXlsx new problem #15

Closed liufeijin closed 6 years ago

liufeijin commented 6 years ago

I got the warning when i write a excel (PLS refer attachment) as below codes

QXlsx::Document xlsx("d:/V1805133.xlsx"); if (!xlsx.isLoadPackage()) { qDebug() << "Failed to load data.xlsx";

}else{
    if(xlsx.selectSheet("A")){

        qDebug() << xlsx.read("A1"); // QVariant(QString, "A1DATA")
        qDebug() << xlsx.read("A2"); // QVariant(Invalid)
        qDebug() << xlsx.read("B1"); // QVariant(QString, "B1DATA")
        qDebug() << xlsx.read("B2"); // QVariant(QString, "B2DATA")

        xlsx.write("E5", "Hello ");

        xlsx.save();
    }
}

if the excel file include a drawing , after writing as above , the drawing will be lose.

liufeijin commented 6 years ago

very sad , maybe i must to try other lib.

liufeijin commented 6 years ago

i want to try Qlibxlsxwriter but fail as the zip.h can't find . and try to set it . fail

j2doll commented 6 years ago

Dear liufeijin:

liufeijin commented 6 years ago

Dear J2doll I found which different will case this bug ////////////////////////////////////////////// I rename the excel file V1805133.XLSX to V1805133.ZIP and extract to V1805133befor after writing by QXlsx (don't open and reapair by office) rename to V1805133.zip and extract to V1805133after.

I replace 1 file from v1805133before folder to v1805133after folder

1 /xl/drawing1.xml

the excel file will be normal .

So the problem is QXls writs the xml file in wrong format or lose some thing . i think this maybe can be fixed . Cloud you have a look ?

liufeijin commented 6 years ago

the file /xl/drawing1.xml is lose beleow

liufeijin commented 6 years ago

void DrawingTwoCellAnchor::saveToXml(QXmlStreamWriter &writer) const { writer.writeStartElement(QStringLiteral("xdr:twoCellAnchor")); writer.writeAttribute(QStringLiteral("editAs"), QStringLiteral("oneCell"));

saveXmlMarker(writer, from, QStringLiteral("xdr:from"));
saveXmlMarker(writer, to, QStringLiteral("xdr:to"));

saveXmlObject(writer);

writer.writeEmptyElement(QStringLiteral("xdr:clientData"));
writer.writeEndElement(); //xdr:twoCellAnchor

} is for writing /xl/drawing1.xml

the saveXmlObject(writer); has problem , it dosn't save any thing below is lost -

-

</xdr:nvSpPr>

</xdr:sp>

liufeijin commented 6 years ago

in xlsxdrawinganchor.cpp void DrawingTwoCellAnchor::saveToXml(QXmlStreamWriter &writer) const { writer.writeStartElement(QStringLiteral("xdr:twoCellAnchor")); writer.writeAttribute(QStringLiteral("editAs"), QStringLiteral("oneCell"));

saveXmlMarker(writer, from, QStringLiteral("xdr:from"));
saveXmlMarker(writer, to, QStringLiteral("xdr:to"));

saveXmlObject(writer);

writer.writeEmptyElement(QStringLiteral("xdr:clientData"));
writer.writeEndElement(); //xdr:twoCellAnchor

} to be add xdr:nvSpPr ... like as ( but below is xdr:nuPicPr)

writer.writeStartElement(QStringLiteral("xdr:nvPicPr")); writer.writeEmptyElement(QStringLiteral("xdr:cNvPr")); writer.writeAttribute(QStringLiteral("id"), QString::number(m_id)); writer.writeAttribute(QStringLiteral("name"), QStringLiteral("Picture %1").arg(m_id));

writer.writeStartElement(QStringLiteral("xdr:cNvPicPr"));
writer.writeEmptyElement(QStringLiteral("a:picLocks"));
writer.writeAttribute(QStringLiteral("noChangeAspect"), QStringLiteral("1"));
writer.writeEndElement(); //xdr:cNvPicPr

writer.writeEndElement(); //xdr:nvPicPr
liufeijin commented 6 years ago

i have repaired this error, and updated the code , PLS check

j2doll commented 6 years ago

Dear @liufeijin: