关于如何用VC读取word表格的问题
我现在是在做利用VC 实现WORD表格与ACCESS数据库相互转换的系统 ,在读取WORD表格数据,并转换到ACCES出了问题,怎么样读取WORD文档的表格数据?
我只能写出读取WORD文本的程序 但是肯定不行的 请大家帮忙改正下 我需要读取表格数据,对应到ACCESS里面 我有 m_strId, m_strName, m_nScore
void CDb005Dlg::OnButtonRead()
{
// TODO: Add your control notification handler code here
CLSID clsid;
HRESULT hr;
hr = CLSIDFromProgID(L"Word.Application",&clsid);
if(FAILED(hr))
{
AfxMessageBox(_T("您没有安装OFFICE"));
return;
}
IUnknown *pUnknown=NULL;
IDispatch *pDispatch=NULL;
_Application app=NULL;
hr = GetActiveObject(clsid, NULL, &pUnknown);
if(FAILED(hr))
{
AfxMessageBox(_T("没有正在运行中的MS WORD"));
return;
}
hr = pUnknown->QueryInterface(IID_IDispatch, (LPVOID *)&app);
if(FAILED(hr))
{
pUnknown->Release();
AfxMessageBox(_T("没有取得Application"));
return;
}
pUnknown->Release();
pUnknown = NULL;
Selection Sel = app.GetSelection();
if(!Sel)
{
Sel.ReleaseDispatch();
AfxMessageBox(_T("没有正在编辑的MS WORD"));
return;
}
Sel.WholeStory(); //全部选择
CString str = Sel.GetText(); //取得文本
m_strReada = str; //显示到编辑窗中
UpdateData(FALSE);
Sel.ReleaseDispatch();
app.ReleaseDispatch();
///////
if(m_nOperate == 1) //增加
{
UpdateData(TRUE);
if(m_strId.IsEmpty())
{
AfxMessageBox(_T("学生学号不能为空."));
return;
}
if(m_strName.IsEmpty())
{
AfxMessageBox(_T("学生姓名不能为空."));
return;
}
CString strSql;
strSql.Format(_T("Insert into StudentInfo values('%s','%s',%d)"), m_strId, m_strName, m_nScore);
try
{
m_pConnection->Execute(_bstr_t(strSql), 0, adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(_T("增加记录失败!"));
}
AfxMessageBox(_T("增加记录成功!"));
FreshList();
}