Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worksheet::writeDate() is very slow. Add a separate dateToNumber() function to improve speed. #322

Open
archibalduk opened this issue Dec 30, 2023 · 2 comments

Comments

@archibalduk
Copy link

archibalduk commented Dec 30, 2023

The following line in Worksheet::writeDate() is causing a bottleneck when writing fairly large numbers of QDates to a worksheet:

double value = datetimeToNumber(QDateTime(dt, QTime(0,0,0)), d->workbook->isDate1904());

The solution is to exclude QDateTime from the calculation when dealing with QDates. So the above line in Worksheet::writeDate() would be replaced with this:

double value = dateToNumber(dt);

The new dateToNumber() function in xlsxutility.cpp would be as follows:

qint64 dateToNumber(const QDate &dt) const
{
    const QDate epoch(1899, 12, 31);
    const QDate excel_date(epoch.daysTo(dt));

    // Account for Excel erroneously treating 1900 as a leap year
    if (excel_date > 59) // 59 = 28-Feb-1900
        return excel_date + 1;
    else
        return excel_date;
}

I'm not 100% clear on the Workbook::isDate1904() function, but the above approach works in my own extension of QXlsx. Outputting ~250,000 cells containing QDates now takes about 12 seconds instead of around 5-10 minutes.

@dfaure-kdab
Copy link
Contributor

Why not make a proper merge request out of this idea?

@dfaure-kdab
Copy link
Contributor

Or better, can you check if #323 solves your problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants