VC下删除Excel⼯作表BOOL DeleteExcelSheet(CString sExcelFilePath, CString sSheetName)
{
_Worksheet m_wsExcelSingle;
Worksheets m_wsExcels;
_Workbook m_wbExcelSingle;
Workbooks m_wbExcels;
_Application m_appExcel;
//创建Excel 2000服务器(启动Excel)
if (!m_appExcel.CreateDispatch("Excel.Application",NULL))
{
MessageBox(NULL,"创建Excel服务失败!","提⽰",MB_OK|MB_ICONWARNING);
return FALSE;
}
m_appExcel.SetVisible(false);
m_appExcel.SetAlertBeforeOverwriting(FALSE);//禁⽤覆盖提⽰
m_appExcel.SetDisplayAlerts(FALSE);//禁⽌显⽰警告提⽰
m_wbExcels.AttachDispatch(m_appExcel.GetWorkbooks(),true);
m_wbExcelSingle.AttachDispatch(m_wbExcels.Add(_variant_t(sExcelFilePath)));
//得到Worksheets
m_wsExcels.AttachDispatch(m_wbExcelSingle.GetWorksheets(),true);工程造价是干啥的
m_wsExcelSingle.AttachDispatch(m_wsExcels.GetItem(_variant_t(sSheetName)),true);
//我在测试时此处已注释部份不⽤要也成功,如果不成功则加上
/
思想政治工作制度*m_rangeExcel.AttachDispatch(m_wsExcelSingle.GetUsedRange(), TRUE);
m_rangeExcel.Clear();
m_wbExcelSingle.SaveAs( COleVariant(sExcelFilePath),
_variant_t(vtMissing),
1公顷等于多少亩_variant_t(vtMissing),
_variant_t(vtMissing),
_variant_t(vtMissing),
_variant_t(vtMissing),
0,
_variant_t(vtMissing),
_variant_t(vtMissing),
_variant_t(vtMissing),
_variant_t(vtMissing));茂名景点
*/
m_wsExcelSingle.Delete();
m_wbExcelSingle.SaveAs( COleVariant(sExcelFilePath),
_variant_t(vtMissing),河南景区
_variant_t(vtMissing),
_variant_t(vtMissing),
_variant_t(vtMissing),
_variant_t(vtMissing),
0,
_variant_t(vtMissing),
_variant_t(vtMissing),
_variant_t(vtMissing),
_variant_t(vtMissing));
//释放对象
//COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
//m_wbExcelSingle.Close( covOptional, COleVariant( sExcelFilePath ), covOptional ); //m_wbExcels.Close();
//m_rangeExcel.ReleaseDispatch();
m_wsExcelSingle.ReleaseDispatch();
m_wsExcels.ReleaseDispatch();
m_wbExcelSingle.ReleaseDispatch();
保释金退还吗m_wbExcels.ReleaseDispatch();
m_appExcel.ReleaseDispatch();
m_appExcel.Quit();
return TRUE;
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论