C ++ Builder和Excel自动化,从哪里开始?

我想用C ++ builder 2009dynamic地创build和填充excel电子表格,但是我不完全确定如何去做。 在网上search,我已经缩小到使用OLE自动化。 此外,我正在寻找一个文件或编程教程,可以让我开始。 有没有一个简单的编程教程,也彻底解释了OLE自动化的概念?

打开Excel电子表格:

Variant excelApp = Unassigned; //EOleSysError is thrown if GetActiveObject does not succeed. ie //if Excel is not currently open. try { excelApp = Variant::GetActiveObject("Excel.Application"); } catch(EOleSysError& e) { excelApp = Variant::CreateObject("Excel.Application"); //open excel } excelApp.OlePropertySet("ScreenUpdating", true); 

获取当前的单元格指针:

 Variant excelCell = excelSheet.OlePropertyGet("Cells"); 

为excel添加值:

 // create a vararray of 5 elements starting at 0 int bounds[2] = {0, 4}; Variant variantValues = VarArrayCreate(bounds, 1, varVariant); variantValues.PutElement(5, 0); variantValues.PutElement(5, 1); variantValues.PutElement(5, 2); variantValues.PutElement(5, 3); variantValues.PutElement(5, 4); Variant cellRange = excelCell.OlePropertyGet( "Range", excelCell.OlePropertyGet("Item", rowindex, columnindex), // start cell excelCell.OlePropertyGet("Item", rowindex2, columnindex2) // finishing cell ); // place array into excel cellRange.OlePropertySet( "Value", excelApp.OleFunction("Transpose", variantValues) ); 

我希望这可以让你开始,你可能需要包括vcl.hcomobj.hpp