Add date1904 option for workbook
Excel for Windows uses a default epoch of 1900 and Excel for Mac uses an epoch of 1904. However, Excel on either platform will convert automatically between one system and the other. QtXlsxWriter stores dates in the 1900 format by default.
This commit is contained in:
@@ -45,6 +45,7 @@ Workbook::Workbook(QObject *parent) :
|
||||
m_window_height = 9660;
|
||||
|
||||
m_strings_to_numbers_enabled = false;
|
||||
m_date1904 = false;
|
||||
m_activesheet = 0;
|
||||
m_firstsheet = 0;
|
||||
m_table_count = 0;
|
||||
@@ -77,6 +78,23 @@ void Workbook::save(const QString &name)
|
||||
package.createPackage(name);
|
||||
}
|
||||
|
||||
bool Workbook::isDate1904() const
|
||||
{
|
||||
return m_date1904;
|
||||
}
|
||||
|
||||
/*
|
||||
Excel for Windows uses a default epoch of 1900 and Excel
|
||||
for Mac uses an epoch of 1904. However, Excel on either
|
||||
platform will convert automatically between one system
|
||||
and the other. QtXlsxWriter stores dates in the 1900 format
|
||||
by default.
|
||||
*/
|
||||
void Workbook::setDate1904(bool date1904)
|
||||
{
|
||||
m_date1904 = date1904;
|
||||
}
|
||||
|
||||
/*
|
||||
Enable the worksheet.write() method to convert strings
|
||||
to numbers, where possible, using float() in order to avoid
|
||||
@@ -148,6 +166,8 @@ void Workbook::saveToXmlFile(QIODevice *device)
|
||||
// writer.writeAttribute("codeName", "{37E998C4-C9E5-D4B9-71C8-EB1FF731991C}");
|
||||
|
||||
writer.writeEmptyElement("workbookPr");
|
||||
if (m_date1904)
|
||||
writer.writeAttribute("date1904", "1");
|
||||
writer.writeAttribute("defaultThemeVersion", "124226");
|
||||
|
||||
writer.writeStartElement("bookViews");
|
||||
|
||||
+4
-1
@@ -48,6 +48,9 @@ public:
|
||||
Format *addFormat();
|
||||
// void addChart();
|
||||
void defineName(const QString &name, const QString &formula);
|
||||
bool isDate1904() const;
|
||||
void setDate1904(bool date1904);
|
||||
bool isStringsToNumbersEnabled() const;
|
||||
void setStringsToNumbersEnabled(bool enable=true);
|
||||
|
||||
void save(const QString &name);
|
||||
@@ -59,13 +62,13 @@ private:
|
||||
QList<Worksheet *> worksheets() const;
|
||||
SharedStrings *sharedStrings();
|
||||
Styles *styles();
|
||||
bool isStringsToNumbersEnabled() const;
|
||||
void saveToXmlFile(QIODevice *device);
|
||||
|
||||
SharedStrings *m_sharedStrings;
|
||||
QList<Worksheet *> m_worksheets;
|
||||
Styles *m_styles;
|
||||
bool m_strings_to_numbers_enabled;
|
||||
bool m_date1904;
|
||||
|
||||
int m_x_window;
|
||||
int m_y_window;
|
||||
|
||||
Reference in New Issue
Block a user