changeset 39:41cd27a64365

Write empty columns for XSLX to avoid strange 0 formatting Excel shows a pretty large bar for zero values
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 15 Apr 2016 15:24:07 +0200
parents bec3ba3fcbc3
children 7458f113314c
files src/converter.cpp
diffstat 1 files changed, 33 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/converter.cpp	Mon Apr 11 14:59:25 2016 +0200
+++ b/src/converter.cpp	Fri Apr 15 15:24:07 2016 +0200
@@ -230,8 +230,9 @@
                 if (!ok) {
                     mErrors << "Unparsable number in string: " + choiceMatch.captured();
                 }
-                makeBar(html, percent, col2Width, doc, mFmt == Format_PDF);
-                xlsx.write(row, 2, percent);
+                makeBar(html, percent, doc);
+                xlsx.write(row, 2, percent == 0 ? QVariant() : percent);
+                const QString numStr = choiceMatch.captured("num");
                 const QString numVotesString = QString("%1% | %2 Number of votes").
                            arg(choiceMatch.captured(3)).arg(choiceMatch.captured(2));
                 html << mChoiceVotesStyle.arg(numVotesString.toHtmlEscaped());
@@ -243,6 +244,36 @@
                 row++;
                 lastChoiceRow++;
             }
+            choiceMatch = choiceAltEx.match(input, cursor);
+            bool additionalFound = false;
+            while (choiceMatch.hasMatch() && choiceMatch.capturedStart() <= cursor + 1) {
+                additionalFound = true;
+                const QString choice = choiceMatch.captured(1);
+                cursor = choiceMatch.capturedEnd();
+                /* Alternative answer that is just a list of strings */
+                qDebug() << choiceAltEx.captureCount();
+                qDebug() << choiceMatch.captured(2);
+                qDebug() << choiceMatch.capturedTexts();
+                qDebug() << "Caputured unfilled choice: " << choice;
+                html << mChoiceTextStyle.arg(choice.toHtmlEscaped());
+                makeBar(html, 0, doc);
+                xlsx.write(row, 2, QVariant());
+                const QString numVotesString = QStringLiteral("Keine eingegangenen Antworten");
+                html << mChoiceVotesStyle.arg(numVotesString.toHtmlEscaped());
+                xlsx.write(row, 3, numVotesString, mChoiceVotesFmt);
+                xlsx.setRowHeight(row, CHOICE_ROW_HEIGHT);
+                row++;
+                lastChoiceRow++;
+                choiceMatch = choiceAltEx.match(input, cursor);
+                QRegularExpressionMatch realMatch = choiceEx.match(input, cursor);
+                if (choiceMatch.hasMatch() && choiceMatch.capturedStart() == realMatch.capturedStart()) {
+                    /* We have a real match so back to the other pattern. */
+                    break;
+                }
+            }
+            if (additionalFound) {
+                goto repeat;
+            }
             bars.addRange(QString("B%1:B%2").arg(firstChoiceRow).arg(lastChoiceRow));
 //            xlsx.groupRows(firstChoiceRow - 2, lastChoiceRow - 1, false);
         } else if (answerLine == QStringLiteral(TEXT_IDENTIFIER)) {
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)