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

Fix broken builds #346

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 23 additions & 40 deletions QXlsx/source/xlsxdocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -495,72 +493,61 @@ 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;
}

// 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();
}
Expand All @@ -571,7 +558,6 @@ bool DocumentPrivate::saveCsv(QString mainCSVFileName) const

} // foreach (QString curretnSheetName, q->sheetNames()) ...


return true;
}

Expand Down Expand Up @@ -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);
Expand Down
15 changes: 7 additions & 8 deletions QXlsx/source/xlsxworkbook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,19 +607,18 @@ 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);
}
} else if (reader.name() == QLatin1String("workbookPr")) {
Expand Down
Loading