VC 操作 EXCEL---插入工作表(Insert.Sheet)方法

看到的资料

http://bbs.csdn.net/topics/198565

自己总结一下

 

//插入到nIndex工作表之前

void InsertSheet(int nIndex)

{

sheets = book.GetSheets();

COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);

COleVariant covBefore;

covBefore.vt = VT_DISPATCH;

covBefore.pdispVal = sheets.GetItem(COleVariant((short)nIndex));

sheets.Add(covBefore, covOptional, covOptional, covOptional);

covBefore.pdispVal->Release();

}

 

//插入到nIndex工作表之后

void InsertSheet(int nIndex)

{

sheets = book.GetSheets();

COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);

COleVariant covAfter;

covAfter.vt = VT_DISPATCH;

covAfter.pdispVal = sheets.GetItem(COleVariant((short)nIndex));

sheets.Add(covOptional, covAfter, covOptional, covOptional);

covAfter.pdispVal->Release();

}

 

默认是只插入一个表, 可以同时插入多个表

void InsertSheet(int nIndex,int nCount)

{

sheets = book.GetSheets();

COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);

COleVariant covBefore;

covBefore.vt = VT_DISPATCH;

covBefore.pdispVal = sheets.GetItem(COleVariant((short)nIndex));

sheets.Add(covBefore, covOptional, COleVariant((long)nCount), covOptional);

covBefore.pdispVal->Release();

}

转载于:https://www.cnblogs.com/doudongchun/p/3699610.html

你可能感兴趣的:(VC 操作 EXCEL---插入工作表(Insert.Sheet)方法)