/////////////////////////////////////////////////////////////////////////////
//===========================================================================
#import "C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE12\\MSO.DLL" \
rename( "RGB", "MSORGB" ) \
rename( "DocumentProperties","MSODocumentProperties" )
//using namespace Office;
#import "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA6\\VBE6EXT.OLB"
//using namespace VBIDE;
#import "C:\\Program Files\\Microsoft Office\\OFFICE12\\EXCEL.EXE" \
rename( "DialogBox", "ExcelDialogBox" ) \
rename( "RGB", "ExcelRGB" ) \
rename( "CopyFile", "ExcelCopyFile" ) \
rename( "ReplaceText", "ExcelReplaceText" ) \
exclude("IFont") \
exclude("IPicture")
/////////////////////////////////////////////////////////////////////////////
//===========================================================================
#include <string>
#include <cx/StringUtility.h>
/////////////////////////////////////////////////////////////////////////////
//===========================================================================
void Export_Excel_1 (void)
{
std::string target_filepath_a = "D:\\a.xlsx";
_bstr_t target_filepath;
_variant_t cell_item_value;
target_filepath = cx::string_to_wstring( target_filepath_a ).c_str();
cell_item_value = _bstr_t(L"2:2=Export_Excel_1");
Excel::_ApplicationPtr pApplication;
Excel::_WorkbookPtr pWorkbook;
Excel::_WorksheetPtr pWorksheet;
pApplication.CreateInstance ( _T("Excel.Application") );
pApplication->PutDisplayAlerts ( 0, VARIANT_FALSE );
pApplication->Workbooks->Add ( _variant_t ( Excel::xlWBATWorksheet ) );
/*Excel::XlWBATemplate::xlWBATWorksheet*/
pWorkbook = pApplication->Workbooks->Item [1];
pWorksheet = pWorkbook->Sheets->Item[1];
pWorksheet->Cells->Item[2][2] = cell_item_value;
pWorksheet->Cells->Item[2][3] = cell_item_value;
pWorksheet->Cells->Item[2][4] = cell_item_value;
pWorksheet->SaveAs ( target_filepath );
pWorkbook->Close ( VARIANT_FALSE );
pApplication->Quit ();
}
//===========================================================================
void Export_Excel_2 (void)
{
std::string source_filepath_a = "D:\\a.xlsx";
std::string target_filepath_a = "D:\\b.xlsx";
_bstr_t source_filepath;
_bstr_t target_filepath;
_variant_t cell_item_value;
_variant_t option ((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
source_filepath = cx::string_to_wstring( source_filepath_a ).c_str();
target_filepath = cx::string_to_wstring( target_filepath_a ).c_str();
cell_item_value = _bstr_t(L"3:2=Expor_tExcel_2");
Excel::_ApplicationPtr pApplication;
Excel::_WorkbookPtr pWorkbook;
Excel::_WorksheetPtr pWorksheet;
pApplication.CreateInstance( _T("Excel.Application") );
pApplication->PutDisplayAlerts ( 0, VARIANT_FALSE );
pWorkbook = pApplication->Workbooks->Open( source_filepath,
option, option, option, option, option,
option, option, option, option, option, option, option );
pWorksheet = pWorkbook->Sheets->Item[ 1 ];
pWorksheet->Name = L"Export_Excel_2";
pWorksheet->Cells->Item[3][2] = cell_item_value;
pWorksheet->Cells->Item[3][3] = cell_item_value;
pWorksheet->Cells->Item[3][4] = cell_item_value;
pWorksheet->Cells->Item[4][2] = cell_item_value;
pWorksheet->Cells->Item[4][3] = cell_item_value;
pWorksheet->Cells->Item[4][4] = cell_item_value;
#if 1 // overwrite
pWorkbook->Close ( VARIANT_TRUE );
#else
pWorksheet->SaveAs ( target_filepath );
pWorkbook->Close ( VARIANT_FALSE );
#endif
pApplication->Quit ();
}