将word中的数据导入数据库

shining_yyds 2012-04-26 05:01:38
请教大家,有谁做过程序能把word中数据直接导入到oracle数据库中。因为有上千张word表,手写的话很麻烦。
word中信息都是表格,比如
能不能编写程序直接把我让d字段保存到数据库。?
...全文
435 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2012-04-26
  • 打赏
  • 举报
回复
将数据导入到oracle数据库请参考:
OCI Programming Basics
This chapter introduces you to the basic concepts involved in programming with the OCI. This chapter covers the following topics:

Overview of OCI Programming
OCI Program Structure
OCI Data Structures
Handles
Descriptors
OCI Programming Steps
OCI Environment Initialization
Processing SQL Statements
Commit or Rollback
Terminating the Application
Error Handling
Additional Coding Guidelines
Using PL/SQL in an OCI Program
OCI Globalization Support
OCI Database Globalization Support Functions
Overview of OCI Programming
赵4老师 2012-04-26
  • 打赏
  • 举报
回复
1.在VC中新建一控制台程序,选支持MFC(当然,你也可以不选择支持MFC的,不过会很麻烦)
2.按CTRL+W调出MFC ClassWizard,Add Class->From a type library,选择你的word的类型库
(例如我的是word2003,安装在e盘,我的路径是"e:\edittools\microsoft office\office11\msword.olb"),
选择完毕后,在弹出的窗口中选择要让classwizard生成的包装类,在本例中要用到
_Application,
Documents,
_Document,
Range
这四个类,选中他们后按OK
3.进入你的main函数所在的cpp文件,加入头文件引用
#include "msword.h" //引用刚才classwizard生成的idispatch包装类
4.加入代码
……
// console_word.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "console_word.h"
#include "msword.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
printf(_T("Fatal Error: MFC initialization failed!\n"));
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
if (CoInitialize(NULL) != S_OK)
{
AfxMessageBox("初始化COM支持库失败!");
return -1;
}

_Application wordApp;
Documents docs;
_Document doc;
Range aRange;
COleVariant vTrue((short)TRUE), vFalse((short)FALSE), vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
CString txt;

wordApp.CreateDispatch("Word.Application",NULL);
wordApp.SetVisible(FALSE);
docs=wordApp.GetDocuments();
doc=docs.Open(COleVariant("c:\\new\\测试.doc"),vFalse,vTrue,vFalse,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt);
aRange=doc.Range(vOpt,vOpt);
txt=aRange.GetText();
AfxMessageBox(txt);//这里GetText得到的就是word文件的纯文本了,你可以将其写到txt文件中
printf("[%s]\n",txt.GetBuffer(txt.GetLength()));//里面的换行不是\r\n而是\r,所以需要输出重定向到文本文件看结果。
aRange.ReleaseDispatch();
doc.Close(vOpt,vOpt,vOpt);
doc.ReleaseDispatch();
docs.ReleaseDispatch();
wordApp.Quit(vOpt,vOpt,vOpt);
wordApp.ReleaseDispatch();

CoUninitialize();
}

return nRetCode;
}


shining_yyds 2012-04-26
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
肯定可以的。你用程序把数据从word中读取出来,然后在写到oracle中。
[/Quote]那么怎么才能从word读取,读取到什么地方,怎么才能写到oricle呢
W170532934 2012-04-26
  • 打赏
  • 举报
回复
肯定可以的。你用程序把数据从word中读取出来,然后在写到oracle中。
luciferisnotsatan 2012-04-26
  • 打赏
  • 举报
回复
google COM组件

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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