VC uses EXCEL to create and save a new workbook document and delete a worksheet

Source: Internet
Author: User

_ Application excelapp;
_ Application excelprotectapp;
Workbooks workbooks;
_ Workbook;
Worksheets worksheets;
_ Worksheet;
// File opening options
Colevariant voptional (long) disp_e_paramnotfound, vt_error );
// COM Initialization
If (! Afxoleinit ())
{
Afxmessagebox (msg_library_ini_failed );
Return false;
}
// Excel
// Excel
If (! Excelapp. createdispatch ("Excel. application "))
{
Afxmessagebox (msg_excel_create_failed );
Return false;
}
If (! Excelprotectapp. createdispatch ("Excel. application "))
{
Afxmessagebox (msg_excel_create_failed );
Return false;
}
# Ifdef _ debug
Excelapp. setvisible (true );
Excelapp. setusercontrol (true );
# Endif
Workbooks = excelapp. getworkbooks ();
// Create a new workbook
Workbook = workbooks. Add (voptional );
Worksheets = Workbook. getworksheets ();
While (worksheets. getcount ()! = 1)
{
Worksheet = worksheets. getitem (colevariant (short) 1 ));

// Delete Worksheet
Worksheet. Delete ();
}

// Save the work

Workbook. saveas (colevariant) (strvalue + cstrfilename ),
Covoptional,
Covoptional, covoptional, c_accessmode, covoptional, covoptional,
Covoptional, covoptional, covoptional );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.