如何从.xls [excel]文件中读取文本[records]并在vc ++ mfc中显示到editbox中。 [英] How to read text[records] from a .xls[excel] file and display into editbox in vc++ mfc.

查看:122
本文介绍了如何从.xls [excel]文件中读取文本[records]并在vc ++ mfc中显示到editbox中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是vc ++ mfc的新手。我必须从excel文件中逐列读取记录并执行一些操作。我可以写txt文件。

你能为我提供这个.txt和.xls格式吗。

这个特定记录。

Pl帮助我。

提前致谢。



我尝试过:



Hi everyone,
I'm new in vc++ mfc. I have to read records[column by column] from an excel file and perform some action. I can write txt file.
Can you provide me this for .txt and .xls format.
on that particular records.
Pl help me.
Thanks in advance.

What I have tried:

void writeHistoryFile(CString openTime, CString action,CString actionTime,CString count)
{
	globalCount = atoi(count);
	CString LogPath = utils::getTempFolder();
	FILE* wFile = NULL;
	wFile = fopen(LogPath + "\\AnakageHistory.ll","a");
	if (wFile != NULL)
	{
		fprintf(wFile,openTime);
		fprintf(wFile,"\n");
		fprintf(wFile,"User did \""+action+"\" action on = "+actionTime);
		fprintf(wFile,"\n");
		fprintf(wFile,count);
		fprintf(wFile,"\n");
		CString success = isRegistedSuccess?"true":"false";
		fprintf(wFile,"Ragistration = "+success);
		fprintf(wFile,"\n");
		fprintf(wFile,"--------------------------------------------------");
		fprintf(wFile,"\n");
		fclose(wFile);
	}
}

推荐答案

首先编写用于与Excel交互的C ++代码不是初学者的任务,所以准备了很多学习和一些像COM这样的东西。



基本任务是通过COM dll导入Excel界面并使用正确的命名空间。之后,您可以按指定的方式访问Excel文件。看一下 BasicExcel 这篇文章学习它。



旁边的提示:使用C#,与Excel的交互更容易。原因是,在C#中,您在.net-runtime中无缝使用COM接口。文章 Excel Reader 显示了它的易用性。它显示了net-runtime和C#的强大功能。
At first writing C++ code for interaction with Excel isnt a beginners task, so be prepared for a lot to learn and some weired stuff like COM.

The basic tasks are importing the Excel interface via a COM dll and using the correct namespace. After that you can access an Excel file in the specified way. Take a look at the article BasicExcel to learn it.

A tip beside: with C# the interaction with Excel is a lot easier. The reason is, that in C# you are in the .net-runtime which seamlessly use the COM-interface. The article Excel Reader shows how easy it works. It shows the power of the net-runtime and C#.


Excel文件是二进制而不是文本。



我知道四种读取和写入Excel文件的方法:



  • 使用Excel自动化(COM / OLE Dispatch)与Excel类型库。这需要在运行应用程序的计算机上安装Excel,并在开发计算机上安装Excel类型库。请参阅使用Visual C ++的Office Automation [ ^ ]。

  • 使用ODBC。 Open Database Connectivity是一种独立于操作系统的数据库管理标准。使用Excel ODBC驱动程序,它可用于读取和写入Excel文件。因为它是一个数据库接口,所以它处理Excel文件中的表格,如数据库文件中的表格。 Windows安装程序安装了所需的Excel ODBC驱动程序。

  • 使用ADO(OLE DB)。 ActiveX数据对象就像ODBC一样,是一个数据库接口,处理Excel文件中的表格,如数据库文件中的表格。它比ODBC更新。这需要Windows安装程序安装的ADO DLL。 ADO也可以使用ODBC驱动程序使用不同的连接字符串连接到Excel文件。

  • 使用提供读取和写入 ExcelFormat库 [ ^ ]。

Excel files are binary and not text.

I know four methods to read and write Excel files:

  • Using Excel Automation (COM / OLE Dispatch) with the Excel type library. This requires an installed Excel on the machine running your application and the Excel type library on the development machine. See Office Automation Using Visual C++[^].
  • Using ODBC. Open Database Connectivity is an operating system independent standard for database management. With Excel ODBC drivers, it can be used to read and write Excel files. Because it is a database interface, it handles sheets from an Excel file like tables in a database file. The required Excel ODBC driver is installed by the Windows Setup.
  • Using ADO (OLE DB). ActiveX Data Objects is like ODBC a database interface, handling sheets from an Excel file like tables in a database file. It is more up-to-date than ODBC. This requires the ADO DLL wich is installed by Windows Setup. ADO may be also used to connect to Excel files using the ODBC drivers using a different connect string.
  • Using a library that provides reading and writing Excel files like the ExcelFormat Library[^].

    这篇关于如何从.xls [excel]文件中读取文本[records]并在vc ++ mfc中显示到editbox中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆