调用Excel出错,求帮助!!!
//---------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Comobj.hpp"
//---------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
String a="C:\\table.xlt";
Variant Ex = CreateOleObject("Excel.Application");
Ex.OlePropertyGet("workbooks").OleFunction("Add",a.w_str() );
Variant Wb = Ex.OlePropertyGet("ActiveWorkBook");
Variant Sheet = Wb.OlePropertyGet("ActiveSheet");
Sheet.OlePropertyGet("Cells",1,1).OlePropertySet("Value", 1);
Ex.OlePropertySet("Visible", true);
}
//---------------------------------------
String a = "C:\\table.xlt"; // 随便换文件名
Variant Ex = CreateOleObject("Excel.Application");
Ex.OlePropertyGet("workbooks").OleFunction("Add", WideString(a));