1
0
mirror of https://github.com/QtExcel/QXlsx.git synced 2025-01-30 05:02:52 +08:00

Merge branch 'dev88' into dev91

This commit is contained in:
Jay Two 2020-05-31 21:16:00 +09:00
commit ccee49dbbb
12 changed files with 80 additions and 67 deletions

View File

@ -40,6 +40,13 @@ public:
inline CellReference bottomLeft() const { return CellReference(bottom, left); }
inline CellReference bottomRight() const { return CellReference(bottom, right); }
inline void operator =(const CellRange &other)
{
top = other.top;
bottom = other.bottom;
left = other.left;
right = other.right;
}
inline bool operator ==(const CellRange &other) const
{
return top==other.top && bottom==other.bottom

View File

@ -126,7 +126,7 @@ bool Chartsheet::loadFromXmlFile(QIODevice *device)
if (reader.name() == QLatin1String("drawing")) {
QString rId = reader.attributes().value(QStringLiteral("r:id")).toString();
QString name = d->relationships->getRelationshipById(rId).target;
QString path = QDir::cleanPath(splitPath(filePath())[0] + QLatin1String("/") + name);
QString path = QDir::cleanPath(splitPath(filePath()).constFirst() + QLatin1String("/") + name);
d->drawing = QSharedPointer<Drawing>(new Drawing(this, F_LoadFromExists));
d->drawing->setFilePath(path);
}

View File

@ -132,10 +132,10 @@ QColor XlsxColor::fromARGBString(const QString &c)
{
Q_ASSERT(c.length() == 8);
QColor color;
color.setAlpha(c.mid(0, 2).toInt(0, 16));
color.setRed(c.mid(2, 2).toInt(0, 16));
color.setGreen(c.mid(4, 2).toInt(0, 16));
color.setBlue(c.mid(6, 2).toInt(0, 16));
color.setAlpha(c.midRef(0, 2).toInt(0, 16));
color.setRed(c.midRef(2, 2).toInt(0, 16));
color.setGreen(c.midRef(4, 2).toInt(0, 16));
color.setBlue(c.midRef(6, 2).toInt(0, 16));
return color;
}

View File

@ -744,7 +744,7 @@ bool ConditionalFormatting::saveToXml(QXmlStreamWriter &writer) const
it = rule->attrs.constFind(XlsxCfRuleData::A_formula1_temp);
if (it != rule->attrs.constEnd()) {
QString startCell = ranges()[0].toString().split(QLatin1Char(':'))[0];
const QString startCell = ranges().constFirst().toString().split(QLatin1Char(':')).constFirst();
writer.writeTextElement(QStringLiteral("formula"), it.value().toString().arg(startCell));
} else if ((it = rule->attrs.constFind(XlsxCfRuleData::A_formula1)) != rule->attrs.constEnd()) {
writer.writeTextElement(QStringLiteral("formula"), it.value().toString());

View File

@ -195,7 +195,8 @@ bool DocumentPrivate::loadPackage(QIODevice *device)
DocPropsCore props(DocPropsCore::F_LoadFromExists);
props.loadFromXmlData(zipReader.fileData(docPropsCore_Name));
for (const QString &name : props.propertyNames())
const auto propNames = props.propertyNames();
for (const QString &name : propNames)
q->setDocumentProperty(name, props.property(name));
}
@ -208,7 +209,8 @@ bool DocumentPrivate::loadPackage(QIODevice *device)
DocPropsApp props(DocPropsApp::F_LoadFromExists);
props.loadFromXmlData(zipReader.fileData(docPropsApp_Name));
for (const QString &name : props.propertyNames())
const auto propNames = props.propertyNames();
for (const QString &name : propNames)
q->setDocumentProperty(name, props.property(name));
}
@ -218,9 +220,9 @@ bool DocumentPrivate::loadPackage(QIODevice *device)
QList<XlsxRelationship> rels_xl = rootRels.documentRelationships(QStringLiteral("/officeDocument"));
if (rels_xl.isEmpty())
return false;
QString xlworkbook_Path = rels_xl[0].target;
QString xlworkbook_Dir = splitPath(xlworkbook_Path)[0];
QString relFilePath = getRelFilePath(xlworkbook_Path);
const QString xlworkbook_Path = rels_xl[0].target;
const QString xlworkbook_Dir = splitPath(xlworkbook_Path).constFirst();
const QString relFilePath = getRelFilePath(xlworkbook_Path);
workbook->relationships()->loadFromXmlData( zipReader.fileData(relFilePath) );
workbook->setFilePath(xlworkbook_Path);
@ -392,7 +394,8 @@ bool DocumentPrivate::savePackage(QIODevice *device) const
}
// save docProps app/core xml file
for (const QString &name : q->documentPropertyNames()) {
const auto docPropNames = q->documentPropertyNames();
for (const QString &name : docPropNames) {
docPropsApp.setProperty(name, q->documentProperty(name));
docPropsCore.setProperty(name, q->documentProperty(name));
}
@ -1332,14 +1335,14 @@ bool Document::autosizeColumnWidth(const CellRange &range)
return false;
}
QMap<int, int> colWidth = getMaximalColumnWidth(range.firstRow(), range.lastRow());
for (int key : colWidth.keys())
{
if( (key >= range.firstColumn()) && (key <= range.lastColumn()) )
const QMap<int, int> colWidth = getMaximalColumnWidth(range.firstRow(), range.lastRow());
auto it = colWidth.constBegin();
while (it != colWidth.constEnd()) {
if( (it.key() >= range.firstColumn()) && (it.key() <= range.lastColumn()) )
{
erg |= setColumnWidth(key, colWidth.value(key));
erg |= setColumnWidth(it.key(), it.value());
}
++it;
}
return erg;
@ -1354,14 +1357,14 @@ bool Document::autosizeColumnWidth(int column)
{
bool erg = false;
QMap<int, int> colWidth = getMaximalColumnWidth();
for (int key : colWidth.keys())
{
if( key == column)
const QMap<int, int> colWidth = getMaximalColumnWidth();
auto it = colWidth.constBegin();
while (it != colWidth.constEnd()) {
if( it.key() == column)
{
erg |= setColumnWidth(key, colWidth.value(key));
erg |= setColumnWidth(it.key(), it.value());
}
++it;
}
return erg;
@ -1378,14 +1381,14 @@ bool Document::autosizeColumnWidth(int colFirst, int colLast)
Q_UNUSED(colLast)
bool erg = false;
QMap<int, int> colWidth = getMaximalColumnWidth();
for (int key : colWidth.keys())
{
if( (key >= colFirst) && (key <= colLast) )
const QMap<int, int> colWidth = getMaximalColumnWidth();
auto it = colWidth.constBegin();
while (it != colWidth.constEnd()) {
if( (it.key() >= colFirst) && (it.key() <= colLast) )
{
erg |= setColumnWidth(key, colWidth.value(key));
erg |= setColumnWidth(it.key(), it.value());
}
++it;
}
return erg;
@ -1400,11 +1403,11 @@ bool Document::autosizeColumnWidth(void)
{
bool erg = false;
QMap<int, int> colWidth = getMaximalColumnWidth();
for (int key : colWidth.keys())
{
erg |= setColumnWidth(key, colWidth.value(key));
const QMap<int, int> colWidth = getMaximalColumnWidth();
auto it = colWidth.constBegin();
while (it != colWidth.constEnd()) {
erg |= setColumnWidth(it.key(), it.value());
++it;
}
return erg;

View File

@ -318,7 +318,7 @@ void DrawingAnchor::loadXmlObjectGraphicFrame(QXmlStreamReader &reader)
if (reader.name() == QLatin1String("chart")) {
QString rId = reader.attributes().value(QLatin1String("r:id")).toString();
QString name = m_drawing->relationships()->getRelationshipById(rId).target;
QString path = QDir::cleanPath(splitPath(m_drawing->filePath())[0] + QLatin1String("/") + name);
QString path = QDir::cleanPath(splitPath(m_drawing->filePath()).constFirst() + QLatin1String("/") + name);
bool exist = false;
QList<QSharedPointer<Chart> > cfs = m_drawing->workbook->chartFiles();
@ -359,7 +359,7 @@ void DrawingAnchor::loadXmlObjectPicture(QXmlStreamReader &reader)
if (reader.name() == QLatin1String("blip")) {
QString rId = reader.attributes().value(QLatin1String("r:embed")).toString();
QString name = m_drawing->relationships()->getRelationshipById(rId).target;
QString path = QDir::cleanPath(splitPath(m_drawing->filePath())[0] + QLatin1String("/") + name);
QString path = QDir::cleanPath(splitPath(m_drawing->filePath()).constFirst() + QLatin1String("/") + name);
bool exist = false;
QList<QSharedPointer<MediaFile> > mfs = m_drawing->workbook->mediaFiles();

View File

@ -31,9 +31,9 @@
QT_BEGIN_NAMESPACE_XLSX
const QString schema_doc = QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships");
const QString schema_msPackage = QStringLiteral("http://schemas.microsoft.com/office/2006/relationships");
const QString schema_package = QStringLiteral("http://schemas.openxmlformats.org/package/2006/relationships");
const QLatin1String schema_doc("http://schemas.openxmlformats.org/officeDocument/2006/relationships");
const QLatin1String schema_msPackage("http://schemas.microsoft.com/office/2006/relationships");
const QLatin1String schema_package("http://schemas.openxmlformats.org/package/2006/relationships");
//const QString schema_worksheet = QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships");
Relationships::Relationships()
{

View File

@ -130,7 +130,7 @@ bool RichString::isNull() const
*/
bool RichString::isEmtpy() const
{
for (const QString str : d->fragmentTexts) {
for (const QString &str : d->fragmentTexts) {
if (!str.isEmpty())
return false;
}

View File

@ -1364,22 +1364,24 @@ bool Styles::loadFromXmlFile(QIODevice *device)
QColor Styles::getColorByIndex(int idx)
{
if (m_indexedColors.isEmpty()) {
m_indexedColors<<QColor("#000000") <<QColor("#FFFFFF") <<QColor("#FF0000") <<QColor("#00FF00")
<<QColor("#0000FF") <<QColor("#FFFF00") <<QColor("#FF00FF") <<QColor("#00FFFF")
<<QColor("#000000") <<QColor("#FFFFFF") <<QColor("#FF0000") <<QColor("#00FF00")
<<QColor("#0000FF") <<QColor("#FFFF00") <<QColor("#FF00FF") <<QColor("#00FFFF")
<<QColor("#800000") <<QColor("#008000") <<QColor("#000080") <<QColor("#808000")
<<QColor("#800080") <<QColor("#008080") <<QColor("#C0C0C0") <<QColor("#808080")
<<QColor("#9999FF") <<QColor("#993366") <<QColor("#FFFFCC") <<QColor("#CCFFFF")
<<QColor("#660066") <<QColor("#FF8080") <<QColor("#0066CC") <<QColor("#CCCCFF")
<<QColor("#000080") <<QColor("#FF00FF") <<QColor("#FFFF00") <<QColor("#00FFFF")
<<QColor("#800080") <<QColor("#800000") <<QColor("#008080") <<QColor("#0000FF")
<<QColor("#00CCFF") <<QColor("#CCFFFF") <<QColor("#CCFFCC") <<QColor("#FFFF99")
<<QColor("#99CCFF") <<QColor("#FF99CC") <<QColor("#CC99FF") <<QColor("#FFCC99")
<<QColor("#3366FF") <<QColor("#33CCCC") <<QColor("#99CC00") <<QColor("#FFCC00")
<<QColor("#FF9900") <<QColor("#FF6600") <<QColor("#666699") <<QColor("#969696")
<<QColor("#003366") <<QColor("#339966") <<QColor("#003300") <<QColor("#333300")
<<QColor("#993300") <<QColor("#993366") <<QColor("#333399") <<QColor("#333333");
m_indexedColors = {
QColor(QRgba64::fromArgb32(0x000000)), QColor(QRgba64::fromArgb32(0xFFFFFF)), QColor(QRgba64::fromArgb32(0xFF0000)), QColor(QRgba64::fromArgb32(0x00FF00)),
QColor(QRgba64::fromArgb32(0x0000FF)), QColor(QRgba64::fromArgb32(0xFFFF00)), QColor(QRgba64::fromArgb32(0xFF00FF)), QColor(QRgba64::fromArgb32(0x00FFFF)),
QColor(QRgba64::fromArgb32(0x000000)), QColor(QRgba64::fromArgb32(0xFFFFFF)), QColor(QRgba64::fromArgb32(0xFF0000)), QColor(QRgba64::fromArgb32(0x00FF00)),
QColor(QRgba64::fromArgb32(0x0000FF)), QColor(QRgba64::fromArgb32(0xFFFF00)), QColor(QRgba64::fromArgb32(0xFF00FF)), QColor(QRgba64::fromArgb32(0x00FFFF)),
QColor(QRgba64::fromArgb32(0x800000)), QColor(QRgba64::fromArgb32(0x008000)), QColor(QRgba64::fromArgb32(0x000080)), QColor(QRgba64::fromArgb32(0x808000)),
QColor(QRgba64::fromArgb32(0x800080)), QColor(QRgba64::fromArgb32(0x008080)), QColor(QRgba64::fromArgb32(0xC0C0C0)), QColor(QRgba64::fromArgb32(0x808080)),
QColor(QRgba64::fromArgb32(0x9999FF)), QColor(QRgba64::fromArgb32(0x993366)), QColor(QRgba64::fromArgb32(0xFFFFCC)), QColor(QRgba64::fromArgb32(0xCCFFFF)),
QColor(QRgba64::fromArgb32(0x660066)), QColor(QRgba64::fromArgb32(0xFF8080)), QColor(QRgba64::fromArgb32(0x0066CC)), QColor(QRgba64::fromArgb32(0xCCCCFF)),
QColor(QRgba64::fromArgb32(0x000080)), QColor(QRgba64::fromArgb32(0xFF00FF)), QColor(QRgba64::fromArgb32(0xFFFF00)), QColor(QRgba64::fromArgb32(0x00FFFF)),
QColor(QRgba64::fromArgb32(0x800080)), QColor(QRgba64::fromArgb32(0x800000)), QColor(QRgba64::fromArgb32(0x008080)), QColor(QRgba64::fromArgb32(0x0000FF)),
QColor(QRgba64::fromArgb32(0x00CCFF)), QColor(QRgba64::fromArgb32(0xCCFFFF)), QColor(QRgba64::fromArgb32(0xCCFFCC)), QColor(QRgba64::fromArgb32(0xFFFF99)),
QColor(QRgba64::fromArgb32(0x99CCFF)), QColor(QRgba64::fromArgb32(0xFF99CC)), QColor(QRgba64::fromArgb32(0xCC99FF)), QColor(QRgba64::fromArgb32(0xFFCC99)),
QColor(QRgba64::fromArgb32(0x3366FF)), QColor(QRgba64::fromArgb32(0x33CCCC)), QColor(QRgba64::fromArgb32(0x99CC00)), QColor(QRgba64::fromArgb32(0xFFCC00)),
QColor(QRgba64::fromArgb32(0xFF9900)), QColor(QRgba64::fromArgb32(0xFF6600)), QColor(QRgba64::fromArgb32(0x666699)), QColor(QRgba64::fromArgb32(0x969696)),
QColor(QRgba64::fromArgb32(0x003366)), QColor(QRgba64::fromArgb32(0x339966)), QColor(QRgba64::fromArgb32(0x003300)), QColor(QRgba64::fromArgb32(0x333300)),
QColor(QRgba64::fromArgb32(0x993300)), QColor(QRgba64::fromArgb32(0x993366)), QColor(QRgba64::fromArgb32(0x333399)), QColor(QRgba64::fromArgb32(0x333333)),
};
m_isIndexedColorsDefault = true;
}
if (idx < 0 || idx >= m_indexedColors.size())

View File

@ -56,9 +56,9 @@ QStringList splitPath(const QString &path)
{
int idx = path.lastIndexOf(QLatin1Char('/'));
if (idx == -1)
return QStringList()<<QStringLiteral(".")<<path;
return { QStringLiteral("."), path };
return QStringList()<<path.left(idx)<<path.mid(idx+1);
return { path.left(idx), path.mid(idx+1) };
}
/*
@ -246,7 +246,7 @@ QString convertSharedFormula(const QString &rootFormula, const CellReference &ro
Q_UNUSED(rootCell)
Q_UNUSED(cell)
//Find all the "$?[A-Z]+$?[0-9]+" patterns in the rootFormula.
QList<std::pair<QString, int> > segments;
QVector<std::pair<QString, int> > segments;
QString segment;
bool inQuote = false;

View File

@ -609,7 +609,7 @@ bool Workbook::loadFromXmlFile(QIODevice *device)
AbstractSheet *sheet = addSheet(name, sheetId, type);
sheet->setSheetState(state);
QString strFilePath = filePath();
const QString fullPath = QDir::cleanPath(splitPath(strFilePath)[0] + QLatin1String("/") + relationship.target);
const QString fullPath = QDir::cleanPath(splitPath(strFilePath).constFirst() + QLatin1String("/") + relationship.target);
sheet->setFilePath(fullPath);
}
else if (reader.name() == QLatin1String("workbookPr"))
@ -652,7 +652,7 @@ bool Workbook::loadFromXmlFile(QIODevice *device)
XlsxRelationship relationship = d->relationships->getRelationshipById(rId);
QSharedPointer<SimpleOOXmlFile> link(new SimpleOOXmlFile(F_LoadFromExists));
const QString fullPath = QDir::cleanPath(splitPath(filePath())[0] +QLatin1String("/")+ relationship.target);
const QString fullPath = QDir::cleanPath(splitPath(filePath()).constFirst() + QLatin1String("/") + relationship.target);
link->setFilePath(fullPath);
d->externalLinks.append(link);
} else if (reader.name() == QLatin1String("definedName")) {

View File

@ -1592,7 +1592,7 @@ void WorksheetPrivate::saveXmlCellData(QXmlStreamWriter &writer, int row, int co
if (cell->hasFormula())
{
QString strFormula = cell->formula().d->formula;
Q_UNUSED(strFormula);
cell->formula().saveToXml(writer);
}
@ -1619,7 +1619,7 @@ void WorksheetPrivate::saveXmlCellData(QXmlStreamWriter &writer, int row, int co
if (cell->hasFormula())
{
QString strFormula = cell->formula().d->formula;
Q_UNUSED(strFormula);
cell->formula().saveToXml(writer);
}
@ -1735,7 +1735,7 @@ void WorksheetPrivate::saveXmlCellData(QXmlStreamWriter &writer, int row, int co
if (cell->hasFormula())
{
QString strFormula = cell->formula().d->formula;
Q_UNUSED(strFormula);
cell->formula().saveToXml(writer);
}
@ -2510,6 +2510,7 @@ void WorksheetPrivate::loadXmlSheetData(QXmlStreamReader &reader)
bool bIsDate1904 = q->workbook()->isDate1904();
QVariant vDatetimeValue = datetimeFromNumber( dValue, bIsDate1904 );
Q_UNUSED(vDatetimeValue);
// cell->d_func()->value = vDatetimeValue;
cell->d_func()->value = dValue; // dev67
}
@ -2696,7 +2697,7 @@ void WorksheetPrivate::loadXmlSheetFormatProps(QXmlStreamReader &reader)
{
Q_ASSERT(reader.name() == QLatin1String("sheetFormatPr"));
QXmlStreamAttributes attributes = reader.attributes();
const QXmlStreamAttributes attributes = reader.attributes();
XlsxSheetFormatProps formatProps;
bool isSetWidth = false;
@ -2937,7 +2938,7 @@ bool Worksheet::loadFromXmlFile(QIODevice *device)
{
QString rId = reader.attributes().value(QStringLiteral("r:id")).toString();
QString name = d->relationships->getRelationshipById(rId).target;
QString path = QDir::cleanPath(splitPath(filePath())[0] + QLatin1String("/") + name);
QString path = QDir::cleanPath(splitPath(filePath()).constFirst() + QLatin1String("/") + name);
d->drawing = QSharedPointer<Drawing>(new Drawing(this, F_LoadFromExists));
d->drawing->setFilePath(path);
}