dbzhang800 / QtXlsxWriter

.xlsx file reader and writer for Qt5
http://qtxlsx.debao.me
Other
1.24k stars 632 forks source link

comment of a cell #52

Open chinqkung opened 10 years ago

chinqkung commented 10 years ago

Hi, is there a way to read/write the comment of a cell?

fverneau commented 9 years ago

Hi, Me too. I don't find how to add a comment into a cell.

VSRonin commented 9 years ago

From the ISO standard it looks like it's not too difficult to implement, it looks something like

<comments>
<authors>
<author>Bob</author>
<author>CBR</author>
</authors>
<commentList>
<comment ref="D4" authorId="0">
<text>
<r>
<rPr>
<b/>
<sz val="8"/>
<color indexed="81"/>
<rFont val="Calibri"/>
<charset val="1"/>
<scheme val="minor"/>
</rPr>
<t>Bob:</t>
</r>
<r>
<rPr>
<sz val="8"/>
<color indexed="81"/>
<rFont val="Calibri"/>
<charset val="1"/>
<scheme val="minor"/>
</rPr>
<t xml:space="preserve">Why such high expense?</t>
</r>
</text>
</comment>
</commentList>
</comments>

This xml sample displays a comment by "Bob" (bolded) that says, "Why such high expense?" (non bolded).

I'll try and implement it

VSRonin commented 9 years ago

Update: https://github.com/VSRonin/QtXlsxWriter/commit/90c8ca52447a2abe068fec6c7db7059cdcc289b2 I implemented the classes that store comments and save them to the file. now I need to create the shapes that hold the comments to display them (the yellow boxes by default). After that I'll implement the loading from file and finally the styling of the comments.

If you have comments on what I wrote so far I'm totally open to suggestions and critiques.

VSRonin commented 9 years ago

A problem is halting the further development of the issue. To position the comment box (and size it) correctly I need to read the rows height and columns width in points. to be clear, I'd need the return value of range("A1").Width in excel VBA. For more details see comments on the commit: https://github.com/VSRonin/QtXlsxWriter/commit/c0eec00f75a9f5043476ca39533618d40debd023

Any suggestion is appreciated.

In the meantime I'll work on the loading of the data.

If you want to test the code so far add the new files to the project (I use VS so I'm not familiar enough with .pro files to mess with them) and run this test main:

#include <QtCore>
#include "xlsxdocument.h"
#include "xlsxrichstring.h"
#include "xlsxcomment.h"
#include "xlsxcommentformat.h"
int main()
{
    QXlsx::Document xlsx;
    xlsx.write("A1", "Hello Qt!");
    xlsx.write("A2", 12345);
    xlsx.write("A3", "=44+33");
    xlsx.write("A4", true);
    xlsx.write("A5", "http://qt-project.org");
    xlsx.write("A6", QDate(2013, 12, 27));
    xlsx.write("A7", QTime(6, 30));
    QXlsx::RichString commentText;
    QXlsx::Format bolder;
    bolder.setFontBold(true);
    commentText.addFragment("Testing:", bolder);
    commentText.addFragment("\nTest Comment", QXlsx::Format());
    QXlsx::Comment aComment("My Name", commentText);
    auto comFor = aComment.format();
    comFor.setBackgroundColor(Qt::red);
    comFor.setTextAlign(Qt::AlignVCenter);
    aComment.setFormat(comFor);
    xlsx.writeComment("C5", aComment);
    xlsx.writeComment("B3", "My Name", QXlsx::RichString("Another\nComment"));
    xlsx.save();
    return 0;
}