excel 자동화 작업

2988 단어 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

좋은 웹페이지 즐겨찾기