2、 这种输入方式,适合后台输出,不需要打开EXCEL文件,不需要选择输出路径,只是后台自己默默的记录EXCEL文件。
[cpp]
CString sFile,sPath;
CString strChuType = "-";
CString strChuStatus = "-";
GetModuleFileName(NULL,sPath.GetBufferSetLength (MAX_PATH+1),MAX_PATH); //获取主程序所在路径,存在sPath中
sPath.ReleaseBuffer ();
int nPos;
nPos=sPath.ReverseFind ('\\');
sPath=sPath.Left (nPos);
sFile = sPath + "\\ServerOption";
sFile = sFile +"\\ChuStatusRecord";
sFile = sFile + "\\" + pGroup->GetNeName() +"(" +TheUser.GetCurrentUserName() + ")"+".xls";
HANDLE hFile = CreateFile(sFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
HRESULT hr = GetLastError();
if ( ERROR_ACCESS_DENIED == hr || ERROR_SHARING_VIOLATION == hr)
{
return ;
}
}
else
{
// 文件未被打开
CloseHandle(hFile);
}
CString strSheet, str;
CStringArray sampleArray, testRow;
CSpreadSheet SS(sFile, "CHU"); //新建Excel文件名及路径,TestSheet为内部表名
SS.BeginTransaction();
sampleArray.RemoveAll();
str.LoadString(IDS_EQUIPTYPE); //设备类型
sampleArray.Add(str);
str.LoadString(IDS_NE_NAME); //设备名称
sampleArray.Add(str);
str.LoadString(IDS_EQP_DLDIP); //设备地址
sampleArray.Add(str);
str.LoadString(IDS_SLOT); //槽号
sampleArray.Add(str);
str.LoadString(IDS_CHUNO); //话路编号
sampleArray.Add(str);
str.LoadString(IDS_CHNTYPE); //话路类型
sampleArray.Add(str);
str.LoadString(IDS_CHU_STATUS); //话路状态
sampleArray.Add(str);
str.LoadString(IDS_ALMLISTBEGINTIME); //开始时间
sampleArray.Add(str);
str.LoadString(IDS_ALMLISTENDTIME); //结束时间
sampleArray.Add(str);
SS.AddHeaders(sampleArray);
CHHCardBase* pCardBase = dynamic_cast(pGroup->DBase->GetSuperCardBase(ucSystemCardSlot));
if( pCardBase != NULL )
{
BYTE bCount = pParam;
int OFFSET = 6;
for (int index = 0; index < bCount ; index++)
{
BYTE bChuNo = pParam[OFFSET++];
BYTE bChuType = pParam[OFFSET++];
BYTE bChuStatus = pParam[OFFSET++];
CHHPort* pPort = pCardBase->GetPortByType( bChuNo, Port_CHU );
if( pPort == NULL )
continue;
CHHChuIfModule* pModule = dynamic_cast(pPort->GetModule( Mod_ChuIf ));
if( pModule == NULL )
continue;
str.Empty();
sampleArray.RemoveAll();
str = pGroup->GetSeriesName();
sampleArray.Add(str);
str = pGroup->GetNeName();
sampleArray.Add(str);
str = pGroup->GetNeAddressStr();
sampleArray.Add(str);
str.Format("%d", bSlot+1);
sampleArray.Add(str);
str.Format("CHU-%d", bChuNo +1);
sampleArray.Add(str);
strChuType = GetChuTypeString(bChuType);
if (bChuType == 0 || bChuType == 4 || bChuType == 5 ||bChuType == 6)
{
strChuStatus = GetChuStatusString(bChuStatus);
}
else
{
strChuStatus = "-";
}
sampleArray.Add(strChuType);
sampleArray.Add(strChuStatus);
CTime time;
time=CTime::GetCurrentTime();
str.Format("%d-%d-%d-%d:%d:%d",time.GetYear(),time.GetMonth(),time.GetDay(),time.GetHour(), time.GetMinute(), time.GetSecond());
sampleArray.Add(str);
sampleArray.Add("-");
int iRow = SS.GetTotalRows() + 1;
SS.AddRow(sampleArray, iRow, true);
int iExcelRow = pModule->GetExcelRow();
if (iExcelRow != 0)
{
SS.AddCell(str, 9, iExcelRow );
}
pModule->SetExcelRow(iRow);
}
SS.Commit();