qt xlsx 怎样读取EXcel内的多个sheet

wzfgf1 2019-05-22 10:49:55
qt xlsx 怎样读取EXcel内的多个sheet ,哪位大神上代码
...全文
2229 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
开心大爆炸 2020-04-14
  • 打赏
  • 举报
回复
https://github.com/QtExcel/QXlsx/wiki
第五个示例: Read all sheets data
这里有个代码,不知道是否能满足你的要求。
weixin_42220591 2019-12-24
  • 打赏
  • 举报
回复
excel.selectSheet(const QString &name);
excel.sheetNames();
用这俩个搞定了。
nnnhbobo123 2019-05-22
  • 打赏
  • 举报
回复
我也想知道,遇到这个问题,先做个记录,看看有没有人看处理
浮一大白开水 2019-05-22
  • 打赏
  • 举报
回复
sheet就是getSheet(。。。)
浮一大白开水 2019-05-22
  • 打赏
  • 举报
回复
我在QT中使用的xllib,
void CAdvertisingProcess::importexcel()
{
	QFileInfo user_info(m_importxlsPath);

	QString user_ffix = user_info.suffix();
	if ((QString::compare(user_ffix, QString("xls"), Qt::CaseInsensitive) == 0) || (QString::compare(user_ffix, QString("xlsx"), Qt::CaseInsensitive) == 0))
	{
		QString user_absolute = user_info.absoluteFilePath();

		Book* book = xlCreateBook();
		if (book)
		{
			QByteArray pathba = user_absolute.toLocal8Bit();
			if (book->load(pathba.data()))
			{
				Sheet* sheet = book->getSheet(0);
				if (sheet)
				{
					int row = 0;
					int col = 0;
					while (1)
					{
						ADVERTISING_INFO userdata;
						col = 7;
						++row;
						const char* s = sheet->readStr(row, col);

						QString empno = QString::fromLocal8Bit(s);
						if (empno.size() == 0)
						{
							break;
						}
						userdata.XQ = empno;

						col++;

						s = sheet->readStr(row, col);
						userdata.LD = QString::fromLocal8Bit(s);
						col++;

						s = sheet->readStr(row, col);
						userdata.DY = QString::fromLocal8Bit(s);
						col++;

						s = sheet->readStr(row, col);
						userdata.DT = QString::fromLocal8Bit(s);

						m_dataList.append(userdata);
					}

					ShowMessageBoxSlot(QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("用户导入完成"));

					UpdateAdInfo();
				}
				else
				{
					ShowMessageBoxSlot(QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("导入失败,文件异常"));
				}
			}
			else
			{
				qDebug() << "At first run generate !" << endl;
				ShowMessageBoxSlot(QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("导入失败,文件异常"));
			}

			book->release();
		}
		else
		{
			ShowMessageBoxSlot(QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("导入失败,文件异常"));
		}

	}
	else
	{
		ShowMessageBoxSlot(QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("导入失败,文件异常"));
	}
}
puthon 2019-05-22
  • 打赏
  • 举报
回复
可以试一下用QAxObject来读:
 QAxObject * worksheet = workbook->querySubObject("Worksheets(int)", 1);
我之前写过把excel文件读到sqlite的代码,读入直接用QAxObject,写操作用的一个开源库(很方便)你可以参考一下:https://blog.csdn.net/pyuxing/article/details/82903767#2excel_15

21,494

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧