c++ builder Excel Ole 在上一个sheet 之后创建新工作sheet
c++ builder Excel Ole Create new worksheet after the last sheet
我想添加一个新的工作表,而不是在工作表标签的开头,而是在结尾。但我只能设法让它在前面工作。
workSheet = workSheets.OleFunction("Add");
如何更改这行代码以使其添加到最后?
Worksheets.Add()
方法有可选的Before
和After
参数:
Before
An object that specifies the sheet before which the new sheet is added.
After
An object that specifies the sheet after which the new sheet is added.
...
If Before
and After
are both omitted, the new sheet is inserted before the active sheet.
需要设置After参数
Excel::_WorksheetPtr newSheet;
if (const auto sheetsCount = m_book->Worksheets->GetCount(); sheetsCount == 0)
newSheet = m_app->Worksheets->Add();
else
{
IDispatchPtr dispatch = m_app->Worksheets->GetItem(sheetsCount); // Number of sheet, not index
newSheet = m_app->Worksheets->Add(vtMissing, dispatch.GetInterfacePtr(), 1);
}
return newSheet;
我想添加一个新的工作表,而不是在工作表标签的开头,而是在结尾。但我只能设法让它在前面工作。
workSheet = workSheets.OleFunction("Add");
如何更改这行代码以使其添加到最后?
Worksheets.Add()
方法有可选的Before
和After
参数:
Before
An object that specifies the sheet before which the new sheet is added.After
An object that specifies the sheet after which the new sheet is added....
If
Before
andAfter
are both omitted, the new sheet is inserted before the active sheet.
需要设置After参数
Excel::_WorksheetPtr newSheet;
if (const auto sheetsCount = m_book->Worksheets->GetCount(); sheetsCount == 0)
newSheet = m_app->Worksheets->Add();
else
{
IDispatchPtr dispatch = m_app->Worksheets->GetItem(sheetsCount); // Number of sheet, not index
newSheet = m_app->Worksheets->Add(vtMissing, dispatch.GetInterfacePtr(), 1);
}
return newSheet;