首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

调用Excel失误,求帮助!

2013-09-06 
调用Excel出错,求帮助!!!//---------------------------------------#include vcl.h#pragma hdrstop#inc

调用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);
}
//---------------------------------------

执行后报错,但将c盘下的table.xlt模板文件重命名为两位的ta.xlt,a="C:\\ta.xlt"就可以调用模板,好像是字符串转换的问题,如果换比较长的路径该怎么改,请高手指教。 excel string
[解决办法]
OLE专业户来也!!!
String a = "C:\\table.xlt"; // 随便换文件名
Variant Ex = CreateOleObject("Excel.Application");
Ex.OlePropertyGet("workbooks").OleFunction("Add", WideString(a));

热点排行