首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

妖哥请进来看看,小弟我尝试用你的文章说明的方法进行操作有误

2012-03-18 
妖哥请进来看看,我尝试用你的文章说明的方法进行操作有误 - C++ Builder / Windows SDK/API妖哥,我看了你

妖哥请进来看看,我尝试用你的文章说明的方法进行操作有误 - C++ Builder / Windows SDK/API
妖哥,我看了你的《用OLE操作EXCEL》这篇文章后,自己也尝试着去写了下
首先自己建立个EXCEL的模板,然后通过程序调用添加数据,代码如下:

C/C++ code
TSetExcel::TSetExcel(){    try    {        m_ExcelApp = Variant::CreateObject ("Excel.Application");    }    catch(...)    {        MessageBox(NULL, "运行Excel出错,请确认安装了Office!", "警告", MB_OKCANCEL);        return;    }    m_ExcelApp.OlePropertySet("Visible", (Variant)false);    m_ExcelApp.OlePropertySet("Windowstate", 3);        //最大化显示    m_ExcelApp.OlePropertySet("StatusBar", "你好,欢迎使用本EXCEL!");    m_ExcelApp.OlePropertySet("Caption", "数据报表");}//---------------------------------------TSetExcel::~TSetExcel(){}//---------------------------------------int TSetExcel::LoadFile(const std::string &FileName){    if ( FileName == "" )        return 1;    m_ExcelApp.OlePropertyGet("workbooks").OleFunction("Open",FileName.c_str());    m_Workbooks     = m_ExcelApp.OlePropertyGet("ActiveWorkBook");    m_Workbooks.OlePropertyGet("Sheets", 1).OleProcedure("Select"); //check the first sheet.    m_Sheet        = m_Workbooks.OlePropertyGet("ActiveSheet");    m_Range        = m_Sheet.OlePropertyGet("Range","A1:A30");    m_RowCount    = m_Sheet.OlePropertyGet("UsedRange").OlePropertyGet("Rows").OlePropertyGet("Count");    m_ColCount    = m_Sheet.OlePropertyGet("UsedRange").OlePropertyGet("Columns").OlePropertyGet("Count");    return 0;}//---------------------------------------int  TSetExcel::SetValue(const int Row, const int Col, const std::string &str){    if ( Row > m_RowCount || Col > m_ColCount )        return 1;//[color=#FF0000]下面这条语句提示错误:First chance exception at $7c812afb.exception class EoleSysError with message'找不到成员.'[/color]    m_Sheet.OlePropertyGet("Cells", Row, Col).OleProcedure("Value", str.c_str());    return 0;}//---------------------------------------void TSetExcel::SaveFile(const std::string &FilePath){    m_Workbooks.OleFunction("SaveAs", FilePath.c_str());    m_ExcelApp.Exec(Procedure("Quit"));}


[解决办法]
m_Sheet.OlePropertyGet("Cells", Row, Col).OleProcedure("Value", str.c_str());

这一句中, Value是Cells的一个属性, 而不是过程. 所以要改成:

C/C++ code
m_Sheet.OlePropertyGet("Cells", Row, Col).OlePropertySet("Value", str.c_str()); 

热点排行