excel自动化操作

写道
此文章不断更新中……

 

将汉字写入excel中时产生乱码,将wxWidgets更新为2.9.4版本后乱码消失。 

 

#include <wx/msw/ole/automtn.h>


wxAutomationObject excelObject, rangeObject;
if (!excelObject.GetInstance(wxT("Excel.Application")))
{
    // Start Excel if it is not running
    if (!excelObject.CreateInstance(wxT("Excel.Application")))
    {
        wxMessageBox(wxT("Could not create Excel object."));
        return;
    }
}

if (!excelObject.PutProperty(wxT("Visible"), true))
{
    wxMessageBox(wxT("Could not make Excel object visible"));
}
const wxVariant workbooksCountVariant = excelObject.GetProperty(wxT("Workbooks.Count"));
if (workbooksCountVariant.IsNull())
{
    wxMessageBox(wxT("Could not get workbooks count"));
    return;
}
const long workbooksCount = workbooksCountVariant;
if (workbooksCount == 0)
{
    const wxVariant workbook = excelObject.CallMethod(wxT("Workbooks.Add"));
    if (workbook.IsNull())
    {
        wxMessageBox(wxT("Could not create new Workbook"));
        return;
    }
}

//excelObject.PutProperty(wxT("ActiveCell.Font.Bold"), wxVariant(true));
if (!excelObject.PutProperty(wxT("ActiveCell.Value"),wxT("wxWidgets automation test!")))
{
    wxMessageBox(wxT("Could not set active cell value."));
    return;
}
if (!excelObject.PutProperty(wxT("ActiveCell.Font.Name"),wxVariant(wxT("Arial Black"))))//wxVariant(true)) )
{
    wxMessageBox(wxT("Could not put Bold property to active cell."));
    return;
}
//    wxVariant params[2];
//    params[0]=1L;// Row number
//    params[1]=1L;// Column number
//    excelObject.GetObject(rangeObject,wxT("cells"),2,params);
//    rangeObject.PutProperty(wxT("value"),wxVariant(wxT("在固定行列添加属性")));
wxVariant rng[1];
rng[0] = wxVariant(wxT("C3"));
excelObject.GetObject(rangeObject, wxT("Range"), 1,rng);
rangeObject.CallMethod(wxT("Activate"));
excelObject.PutProperty(wxT("ActiveCell.Value"), wxT("在固定行列添加属性"));

 

 

 

参考:

1、http://forums.wxwidgets.org/viewtopic.php?f=32&t=26026

2、http://blog.csdn.net/eaglewood2005/article/details/5289230

3、http://hi.baidu.com/renyucjs/blog/item/d34c4529ab42e23a349bf7f5.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值