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

BCB操作Excel,Variant有关问题

2012-02-22 
BCB操作Excel,Variant问题小弟初次用BCB操作Excel,想使用Variant网上有不少兄台用Variant的OlePropertyGet

BCB操作Excel,Variant问题
小弟初次用BCB操作Excel,想使用Variant
网上有不少兄台用Variant的OlePropertyGet等方法的例子,有没有哪位大哥能提供OlePropertyGet,OlePropertySet,OleFunction,OleProcedure的所有(或常用)参数列表。像 "Open ", "Visible "之类的。
还有,Excel.Application与WorkBook,   ActiveWorkBook,   Sheet等的顺序小弟总是弄不大清楚,有没有哪位达人指点指点。
在线急等,谢谢!

[解决办法]
晕。。。
菜单:工具-》宏-》录制新宏
[解决办法]
我的BCB是英文版的,没找到你说的那个菜单:工具-》宏-》录制新宏

这个说的是在 Excel 中操作,然后编写代码
[解决办法]

//---------------------------------------

//功能:实现指定文件夹下的所有excel文件的内容导出
//入参:指定文件夹下的某一excel文件名
void TForm1::ExportFromExcel(String S_filename)
{
Variant ExcelApp,
WorkBook1,
WorkSheet1;

int i;
WorkSheet1=Unassigned;
WorkBook1=Unassigned;
ExcelApp=Unassigned;

try
{
ExcelApp=Variant::CreateObject( "Excel.Application ");
}
catch(...)
{
MessageBox(Handle, "无法启动Excel! ", "信息提示 ",MB_ICONSTOP|MB_OK);
return;
}
ExcelApp.OlePropertySet( "Visible ",false);
ExcelApp.OlePropertyGet( "WorkBooks ").OleProcedure( "Open ",S_filename.c_str());
WorkBook1=ExcelApp.OlePropertyGet( "ActiveWorkBook ");
WorkSheet1=ExcelApp.OlePropertyGet( "ActiveSheet ");

int nRow=WorkSheet1.OlePropertyGet( "UsedRange ").OlePropertyGet( "Rows ").OlePropertyGet( "Count "); //求出表格有多少行
WideString wteststr;
WideString wtemp = " ";
String steststr = " ",
wtosstr = " " ;
String sPictureDir = Edit5-> Text + "\\ ";
String sSavePictureDir = Edit1-> Text.SubString(1, Edit1-> Text.LastDelimiter( "\\ ") );
String sourename = " ";
String lastname = " ";
int beginnum = Edit4-> Text.ToInt();
for(i = beginnum;i <=nRow;i++)
{
lastname = sSavePictureDir + IntToStr(i) + "\\ ";
if(!DirectoryExists(lastname))
{
CreateDir(lastname);
}
steststr=WorkSheet1.OlePropertyGet( "Cells ",i,(Edit2-> Text.UpperCase().operator [](1) - 'A '+1));
wteststr=WorkSheet1.OlePropertyGet( "Cells ",i,(Edit3-> Text.UpperCase().operator [](1) - 'A '+1)).operator WideString();

if(wteststr == wtemp)
{
continue;
}
wchar_t *wch;
string result = " ";
//LPSTR WideToAnsi(LPCWSTR src);
for(int j = 1; j <= wteststr.Length(); j++)
{
lastname = sSavePictureDir + IntToStr(i) + "\\ ";
sourename = sPictureDir;
wch = wteststr.SubString(j,1);
result = WideToAnsi(wch);
//ShowMessage(result.c_str());
//if(result == "? ")
//{
// ShowMessage( "Error ");


// continue;
//}
String PitureName = " ";
BYTE ch = 0x00;
if(result.length() == 1)
{
ch = result.operator [](0);
PitureName = IntToHex(ch,2);
sourename = sourename + "0\\ " + PitureName + ".bmp ";
lastname = lastname + PitureName + ".bmp ";
//ShowMessage(sourename.c_str());
//ShowMessage(lastname.c_str());
CopyFile(sourename.c_str(),lastname.c_str(), false);
}
else
{
ch = result.operator [](0);
PitureName = IntToHex(ch,2);
sourename = sourename + PitureName + "\\ ";
ch = result.operator [](1);
PitureName += IntToHex(ch,2);
sourename = sourename + PitureName + ".bmp ";
lastname = lastname + PitureName + ".bmp ";
//ShowMessage(sourename.c_str());
//ShowMessage(lastname.c_str());
CopyFile(sourename.c_str(),lastname.c_str(), false);
}
}
}
WorkBook1.OleProcedure( "Close ");
ExcelApp.OleFunction( "Quit ");
}
//--------------------------------------

热点排行