604
社区成员
发帖
与我相关
我的任务
分享
wb.OleFunction("Open", WideString(getFilePath()));
为何这里要转为宽字符?ShellExecute(NULL,"open",getFilePath().c_str(),NULL,NULL,SW_SHOWNORMAL);
ex = Variant::GetActiveObject("Excel.Application");
wb = ex.OlePropertyGet("ActiveWorkBook");
试了双击xls或xlsx,打开都没问题。
调用ShellExecute open xls或xlsx,就是不行,真奇怪。。。
求大神帮忙。
// 校验 ,返回值代表是否完成校验,并非通过校验
bool bom::check(TStrings* log)
{
log->Add("======================");
log->Add("开始校验:" + getFilePath());
clear();
// if (GetExcelApp_IsRun())
// {
// log->Add("error:请关闭所有Excel文档后,再执行此操作!");
// return false;
// }
Variant ex,wb;
try
{
ex = Variant::CreateObject("Excel.Application");
}
catch(...)
{
log->Add("error:无法启动Excel");
return false;
}
ex.OlePropertySet("Visible", true);
// 不显示警告提示框
//ex.OlePropertySet("DisplayAlerts", false);
wb = ex.OlePropertyGet("WorkBooks");
try
{
wb.OleFunction("Open", WideString(getFilePath()));
}
catch(...)
{
log->Add("error:无法打开Excel文件");
try
{
ex.OleFunction("Quit");
ex = Unassigned;
}
catch(...)
{return false;}
return false;
}
int bomid = 1;
int line = 1;
AnsiString pp, code, name, spec, num, pos;
Variant sheet, cell;
try
{
sheet = ex.OlePropertyGet("ActiveWorkBook").OlePropertyGet("sheets", 1);
do {
do {
Application->ProcessMessages();
cell = sheet.OlePropertyGet("Cells",line,1);
pp = cell.OlePropertyGet("Value");
line++;
} while (pp != String(bomid) && pp.Length() > 0);
if (pp == String(bomid))
{
code = sheet.OlePropertyGet("Cells",line,2).OlePropertyGet("Value");
name = sheet.OlePropertyGet("Cells",line,3).OlePropertyGet("Value");
spec = sheet.OlePropertyGet("Cells",line,4).OlePropertyGet("Value");
num = sheet.OlePropertyGet("Cells",line,7).OlePropertyGet("Value");
pos = sheet.OlePropertyGet("Cells",line,8).OlePropertyGet("Value");
mate* pm = new mate(line, bomid, code, name, spec, num.ToIntDef(0), pos);
//pm->check(log);
_verMates.push_back(pm);
bomid++;
}
} while (pp.Length() > 0);
}
catch (...)
{
log->Add("error:获取物料信息出错。Line:" + String(line) + ",bomid:" + String(bomid));
return false;
}
ex.OlePropertyGet("ActiveWorkBook").OleFunction("Close",false);
ex.OleFunction("Quit");
ex = Unassigned;
return true;
}