To open an Excel spreadsheet:
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);
To get the current cell pointer:
Variant excelCell = excelSheet.OlePropertyGet("Cells");
To add values ββto excel:
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),
excelCell.OlePropertyGet("Item", rowindex2, columnindex2)
);
cellRange.OlePropertySet(
"Value",
excelApp.OleFunction("Transpose", variantValues)
);
Hope this helps you, you probably have to turn on vcl.hand comobj.hpp.
source
share