1
0
mirror of https://github.com/QtExcel/QXlsx.git synced 2025-01-16 04:42:53 +08:00

Fix broken build

This commit is contained in:
Daniel Nicoletti 2024-08-08 15:50:08 -03:00
parent 9c704961d0
commit 11bafef832
2 changed files with 30 additions and 48 deletions

View File

@ -478,14 +478,12 @@ bool DocumentPrivate::saveCsv(QString mainCSVFileName) const
{
Q_Q(const Document);
int sheetIndexNumber = 0;
foreach (QString curretnSheetName, q->sheetNames())
{
int sheetIndexNumber = 0;
const auto sheetNames = q->sheetNames();
for (const auto &curretnSheetName : sheetNames) {
QXlsx::AbstractSheet *currentSheet = q->sheet(curretnSheetName);
if (NULL == currentSheet)
{
if (currentSheet == nullptr) {
continue;
}
@ -495,39 +493,32 @@ bool DocumentPrivate::saveCsv(QString mainCSVFileName) const
currentSheet->workbook()->setActiveSheet(sheetIndexNumber);
Worksheet *wsheet = (Worksheet *) currentSheet->workbook()->activeSheet();
if (NULL == wsheet)
{
Worksheet *wsheet = static_cast<Worksheet *>(currentSheet->workbook()->activeSheet());
if (wsheet == nullptr) {
continue;
}
QString strSheetName = wsheet->sheetName(); // sheet name
QVector<CellLocation> clList = wsheet->getFullCells(&maxRow, &maxCol);
QString strSheetName = wsheet->sheetName(); // sheet name
QVector<QVector<QString>> cellValues;
for (int rc = 0; rc < maxRow; rc++)
{
for (int rc = 0; rc < maxRow; rc++) {
QVector<QString> tempValue;
for (int cc = 0; cc < maxCol; cc++)
{
tempValue.push_back(QString(""));
for (int cc = 0; cc < maxCol; cc++) {
tempValue.push_back(QString{});
}
cellValues.push_back(tempValue);
}
for (int ic = 0; ic < clList.size(); ++ic)
{
CellLocation cl = clList.at(ic);
const QVector<CellLocation> clList = wsheet->getFullCells(&maxRow, &maxCol);
for (const auto &cl : clList) {
int row = cl.row - 1;
int col = cl.col - 1;
std::shared_ptr<Cell> ptrCell = cl.cell; // cell pointer
QVariant var = ptrCell->value();
QString str = var.toString();
QVariant var = ptrCell->value();
QString str = var.toString();
cellValues[row][col] = str;
}
@ -535,32 +526,28 @@ bool DocumentPrivate::saveCsv(QString mainCSVFileName) const
// TODO:
// (1) save as csv file name (using { mainCSVFileName + strSheetName })
QString csvFileName = mainCSVFileName + QString("_") + strSheetName + QString(".csv");
QString csvFileName = mainCSVFileName + u'_' + strSheetName + QLatin1String(".csv");
QFile csvFile(csvFileName);
if ( ! csvFile.open( QIODevice::WriteOnly ) )
{
if (!csvFile.open(QIODevice::WriteOnly)) {
continue;
}
// (2) save sheet values
// such as A,,B,,,,C,,,D,,
for (int rc = 0; rc < maxRow; rc++)
{
for (int cc = 0; cc < maxCol; cc++)
{
for (int rc = 0; rc < maxRow; rc++) {
for (int cc = 0; cc < maxCol; cc++) {
QString cellData = cellValues[rc][cc];
if ( cellData.size() >= 0 )
{
csvFile.write( cellData.toUtf8() ); // cell data
if (cellData.size() >= 0) {
csvFile.write(cellData.toUtf8()); // cell data
}
csvFile.write( QString(",").toLatin1() ); // delimeter
csvFile.write(","); // delimeter
}
csvFile.write( QString("\n").toLatin1() ); // CR
csvFile.write("\n"); // CR
csvFile.flush();
}
@ -571,7 +558,6 @@ bool DocumentPrivate::saveCsv(QString mainCSVFileName) const
} // foreach (QString curretnSheetName, q->sheetNames()) ...
return true;
}
@ -1383,16 +1369,13 @@ bool Document::saveAs(QIODevice *device) const
return d->savePackage(device);
}
bool Document::saveAsCsv(const QString mainCSVFileName) const
{
Q_D(const Document);
return d->saveCsv( mainCSVFileName );
return d->saveCsv(mainCSVFileName);
}
bool Document::isLoadPackage() const
{
Q_D(const Document);

View File

@ -607,18 +607,17 @@ bool Workbook::loadFromXmlFile(QIODevice *device)
AbstractSheet *sheet = addSheet(name, sheetId, type);
sheet->setSheetState(state);
if (relationship.target.startsWith("/")) {
if (relationship.target.startsWith(u'/')) {
QString fullPath = QDir::cleanPath(relationship.target.mid(1));
sheet->setFilePath(fullPath);
}else{
} else {
QString strFilePath = filePath();
// const QString fullPath = QDir::cleanPath(splitPath(strFilePath).constFirst() +
// QLatin1String("/") + relationship.target);
// const QString fullPath = QDir::cleanPath(splitPath(strFilePath).constFirst()
// + QLatin1String("/") + relationship.target);
const auto parts = splitPath(strFilePath);
QString fullPath =
QDir::cleanPath(parts.first() + QLatin1String("/") + relationship.target);
QString fullPath = QDir::cleanPath(parts.first() + u'/' + relationship.target);
sheet->setFilePath(fullPath);
}