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();
3、适合用于将界面上的内容所见及所得的输出,可以设置单元格的的合并,大小,字体,颜色等等;
[cpp]
void CFileRecord::OutPutToExcelForMFD(GROUP* pGroup)
{
// TODO: Add extra validation here
//用m_ExlApp对象创建Excel2003进程
if(!m_ExlApp.CreateDispatch("Excel.Application",NULL))
{
AfxMessageBox("创建Excel服务失败!");
return;
}
//设置为可见
m_ExlApp.SetVisible(TRUE);
///////////////////下面得到应用程序所在的路径///////////////////
CString theAppPath,sPath, strSheet;
GetModuleFileName(NULL,sPath.GetBufferSetLength (MAX_PATH+1),MAX_PATH);
sPath.ReleaseBuffer ();
int nPos;
nPos=sPath.ReverseFind ('\\');
sPath=sPath.Left (nPos);
theAppPath = sPath + "\\System\\";
////////////////////////////////////////////////////////////////
CString TempPath="";
TempPath=theAppPath+"Template.xls";//EXCEL模板的路径
m_ExlBooks.AttachDispatch(m_ExlApp.GetWorkbooks(),TRUE);
m_ExlBook.AttachDispatch(m_ExlBooks.Add((_variant_t)TempPath),TRUE);//加载EXCEL模板
m_ExlSheets.AttachDispatch(m_ExlBook.GetSheets(),TRUE);//加载Sheet页面
//添加新的Sheet页面
m_ExlSheets.Add(vtMissing,vtMissing,_variant_t((long)1),vtMissing);
//删除第二个Sheet页面
m_ExlSheet.AttachDispatch(m_ExlSheets.GetItem(_variant_t((long)2)),TRUE);
m_ExlSheet.Delete();
//把第一个Sheet页面的名字改变为TestSheet
m_ExlSheet.AttachDispatch(m_ExlSheets.GetItem(_variant_t((long)1)),TRUE);
strSheet.LoadString(IDS_CHUFACTORYSETTING);
m_ExlSheet.SetName(strSheet);
///////合并第一行单元格A1至D1//////
//加载要合并的单元格
m_ExlRge.AttachDispatch(m_ExlSheet.GetRange(_variant_t("A1"),_variant_t("H2")),TRUE);
m_ExlRge.Merge(_variant_t((long)0));
////////设置表格内容////////
m_ExlRge.AttachDispatch(m_ExlSheet.GetCells(),TRUE);//加载所有单元格
m_ExlRge.SetItem(_variant_t((long)1),_variant_t((long)1),_variant_t(strSheet));
DBASE