|
Thank you two prawns, the problem is solved, haha. I post my code for future communication. Show ugliness:
#include <vcl.h>
#pragma hdrstop
#include "Comobj.hpp"
#include "Unit1.h"
// ------------------------------------------------ ---------------------------
#pragma package (smart_init)
#pragma resource "* .dfm"
#define PG OlePropertyGet
#define PS OlePropertySet
#define FN OleFunction
#define PR OleProcedure
TForm1 * Form1;
// ------------------------------------------------ ---------------------------
__fastcall TForm1 :: TForm1 (TComponent * Owner)
: TForm (Owner)
{
}
// ------------------------------------------------ ---------------------------
void __fastcall TForm1 :: Button1Click (TObject * Sender)
{
Variant ExcelApp, WorkBook1, Sheet1, Range;
bool bExcelRun = true;
HWND h = NULL;
h = FindWindow (0, "Microsoft Excel-Data Template 1");
if (h == NULL)
{
try
{
GetActiveOleObject ("Excel.Application");
}
catch (...)
{
bExcelRun = false;
}
if (bExcelRun == false)
{
ExcelApp = Variant :: CreateObject ("Excel.Application");
}
else
{
ExcelApp = Variant :: GetActiveObject ("Excel.Application");
}
ExcelApp.PS ("Visible", (Variant) true);
ExcelApp.PG ("WorkBooks"). FN ("Add", "F:\\mydata\\data template.xlt");
}
else
{
ExcelApp = Variant :: GetActiveObject ("Excel.Application");
WorkBook1 = ExcelApp.PG ("ActiveWorkBook");
}
WorkBook1 = ExcelApp.PG ("ActiveWorkBook");
Sheet1 = WorkBook1.PG ("ActiveSheet");
Sheet1.PG ("Cells", 10,10) .PS ("Value", 100.05);
}
Ha ha. |
|