Browse Source

Improve html rich text support

If contains only one text fragment with format, then it should be plain
text. And the format should be considered as Cell format
master
Debao Zhang 11 years ago
parent
commit
461f05281e
  1. 3
      examples/xlsx/richtext/main.cpp
  2. 2
      src/xlsx/xlsxworksheet.cpp

3
examples/xlsx/richtext/main.cpp

@ -27,6 +27,9 @@ int main()
xlsx.workbook()->setHtmlToRichStringEnabled(true); xlsx.workbook()->setHtmlToRichStringEnabled(true);
xlsx.write("B4", "<b>Hello</b> <font color=\"red\">Qt</font> <i>Xlsx</i>"); xlsx.write("B4", "<b>Hello</b> <font color=\"red\">Qt</font> <i>Xlsx</i>");
xlsx.write("B6", "<font color=\"red\"><b><u><i>Qt Xlsx</i></u></b></font>");
//![1] //![1]
//![2] //![2]

2
src/xlsx/xlsxworksheet.cpp

@ -621,6 +621,8 @@ int Worksheet::writeString(int row, int column, const RichString &value, const F
d->sharedStrings()->addSharedString(value); d->sharedStrings()->addSharedString(value);
Format fmt = format.isValid() ? format : d->cellFormat(row, column); Format fmt = format.isValid() ? format : d->cellFormat(row, column);
if (value.fragmentCount() == 1 && value.fragmentFormat(0).isValid())
fmt.mergeFormat(value.fragmentFormat(0));
d->workbook->styles()->addXfFormat(fmt); d->workbook->styles()->addXfFormat(fmt);
QSharedPointer<Cell> cell = QSharedPointer<Cell>(new Cell(value.toPlainString(), Cell::String, fmt, this)); QSharedPointer<Cell> cell = QSharedPointer<Cell>(new Cell(value.toPlainString(), Cell::String, fmt, this));
cell->d_ptr->richString = value; cell->d_ptr->richString = value;

Loading…
Cancel
Save