吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 602|回复: 3
收起左侧

[求助] QT程序有导出的代码,那能编出导入的代码吗?

  [复制链接]
冥界3大法王 发表于 2022-8-23 10:54
[C++] 纯文本查看 复制代码
//Export table in CSV. TODO: Display a dialog where the user choose what column to export and in which encoding
bool ExportCSV(dsint rows, dsint columns, std::vector<QString> headers, std::function<QString(dsint, dsint)> getCellContent)
{
    BrowseDialog browse(nullptr, QApplication::translate("ExportCSV", "Export data in CSV format"), QApplication::translate("ExportCSV", "Enter the CSV file name to export"), QApplication::translate("ExportCSV", "CSV files (*.csv);;All files (*.*)"), QApplication::applicationDirPath() + QDir::separator() + "db", true);
    browse.setWindowIcon(DIcon("database-export.png"));
    if(browse.exec() == QDialog::Accepted)
    {
        FILE* csv;
        bool utf16;
        csv = _wfopen(browse.path.toStdWString().c_str(), L"wb");
        if(csv == NULL)
        {
            GuiAddLogMessage(QApplication::translate("ExportCSV", "CSV export error\n").toUtf8().constData());
            return false;
        }
        else
        {
            duint setting;
            if(BridgeSettingGetUint("Misc", "Utf16LogRedirect", &setting))
                utf16 = !!setting;
            else
                utf16 = false;
            if(utf16 && ftell(csv) == 0)
            {
                unsigned short BOM = 0xfeff;
                fwrite(&BOM, 2, 1, csv);
            }
            dsint row, column;
            QString text;
            QString cell;
            if(headers.size() > 0)
            {
                for(column = 0; column < columns; column++)
                {
                    cell = headers.at(column);
                    if(cell.contains('"') || cell.contains(',') || cell.contains('\r') || cell.contains('\n'))
                    {
                        if(cell.contains('"'))
                            cell = cell.replace("\"", "\"\"");
                        cell = "\"" + cell + "\"";
                    }
                    if(column != columns - 1)
                        cell = cell + ",";
                    text = text + cell;
                }
                if(utf16)
                {
                    text = text + "\r\n";
                    if(!fwrite(text.utf16(), text.length(), 2, csv))
                    {
                        fclose(csv);
                        GuiAddLogMessage(QApplication::translate("ExportCSV", "CSV export error\n").toUtf8().constData());
                        return false;
                    }
                }
                else
                {
                    text = text + "\n";
                    QByteArray utf8;
                    utf8 = text.toUtf8();
                    if(!fwrite(utf8.constData(), utf8.size(), 1, csv))
                    {
                        fclose(csv);
                        GuiAddLogMessage(QApplication::translate("ExportCSV", "CSV export error\n").toUtf8().constData());
                        return false;
                    }
                }
            }
            for(row = 0; row < rows; row++)
            {
                text.clear();
                for(column = 0; column < columns; column++)
                {
                    cell = getCellContent(row, column);
                    if(cell.contains('"') || cell.contains(',') || cell.contains('\r') || cell.contains('\n'))
                    {
                        if(cell.contains('"'))
                            cell = cell.replace("\"", "\"\"");
                        cell = "\"" + cell + "\"";
                    }
                    if(column != columns - 1)
                        cell = cell + ",";
                    text = text + cell;
                }
                if(utf16)
                {
                    text = text + "\r\n";
                    if(!fwrite(text.utf16(), text.length(), 2, csv))
                    {
                        fclose(csv);
                        GuiAddLogMessage(QApplication::translate("ExportCSV", "CSV export error\n").toUtf8().constData());
                        return false;
                    }
                }
                else
                {
                    text = text + "\n";
                    QByteArray utf8;
                    utf8 = text.toUtf8();
                    if(!fwrite(utf8.constData(), utf8.size(), 1, csv))
                    {
                        fclose(csv);
                        GuiAddLogMessage(QApplication::translate("ExportCSV", "CSV export error\n").toUtf8().constData());
                        return false;
                    }
                }
            }
            fclose(csv);
            GuiAddLogMessage(QApplication::translate("ExportCSV", "Saved CSV data at %1\n").arg(browse.path).toUtf8().constData());
            return true;
        }
    }
    else
        return false;
}

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

xfmjn 发表于 2022-8-23 12:40
读取数据本身不是问题。问题是只看这个实现,看不到将读取后的数据导入到表格的接口。
 楼主| 冥界3大法王 发表于 2022-8-23 13:15
xfmjn 发表于 2022-8-23 12:40
读取数据本身不是问题。问题是只看这个实现,看不到将读取后的数据导入到表格的接口。

@xfmjn
数据就是x64dbg中的断点窗口显示的东西
MarioCrane 发表于 2022-8-29 22:34
csv啊,逗号分隔文档,格式就是逗号和换行符。按行读,用逗号分隔就好了。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-1 07:17

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表