C++;Builder和Excel自动化,从哪里开始? 我想用C++ Builder 2009动态创建和填充Excel电子表格,但我不太确定如何去处理它。搜索web时,我将其范围缩小到使用OLE自动化。此外,我正在寻找一个文档或编程教程,可以让我开始。是否有一个简单的编程教程也能全面解释OLE自动化的概念?
要打开excel电子表格:C++;Builder和Excel自动化,从哪里开始? 我想用C++ Builder 2009动态创建和填充Excel电子表格,但我不太确定如何去处理它。搜索web时,我将其范围缩小到使用OLE自动化。此外,我正在寻找一个文档或编程教程,可以让我开始。是否有一个简单的编程教程也能全面解释OLE自动化的概念?,c++,excel,automation,c++builder,C++,Excel,Automation,C++builder,要打开excel电子表格: Variant excelApp = Unassigned; //EOleSysError is thrown if GetActiveObject does not succeed. i.e //if Excel is not currently open. try { excelApp = Variant::GetActiveObject("Excel.Application"); } catch(EOleSysError& e) { e
Variant excelApp = Unassigned;
//EOleSysError is thrown if GetActiveObject does not succeed. i.e
//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.h
和comobj.hpp