C # Excel Programming Problems

Source: Internet
Author: User

1. When programming, sometimes the worksheets interface is used and sometimes the sheets interface is used. Under what conditions are they used? What is the difference?

Answer: worksheets refers to the table that you are currently inactive, and sheets is the current active table. Each sheet is a workbook, and each sheet forms a sheet, that is, a worksheet. If you open both book1 and book2, But you operate book1, you can write sheets to which book1 belongs, while book2 is worksheets.

Another explanation is that sheets is the set of sheets in the active workbook, while worksheets is the set of worksheet objects in the active workbook. Each worksheet object represents a worksheet.

2. _ workbook and workbook are used in Excel programming. However, workbook exists. What is the difference between them?

In fact, there is no big difference between the two. Both are interfaces. Workbook inherits _ worbook and workbookevents_event, providing the ability to access workbook events.

That is, publicinterfaceworksheet:
_ Worksheet, docevents_event
3. Commonly Used variables for Excel operations

Private excel. Application m_objexcel = NULL; // Excel Process
Private excel. workbooks m_objbooks = NULL; // workbook set
Private excel. _ workbook m_objbook = NULL; // The current active workbook.
Private excel. Sheets m_objsheets = NULL; // a set of worksheets
Private excel. _ worksheet m_objsheet = NULL; // the worksheet of the current activity
Private excel. Range m_objrange = NULL; // represents an area, that is, a Range
Private object m_objopt = system. reflection. Missing. value; // use this instance of the missing class to indicate missing values. For example, when you call a method with default parameter values

 

Variable assignment

M_objexcel = new excel. Application ();
M_objexcel.visible = false;
M_objexcel.displayalerts = false;

If (m_objexcel.version! & Quot; 11.0 & quot ;)
{
MessageBox. Show (& quot; your Excel version is not 11.0 (Office 2003), and operations may fail. & Quot ;);
M_objexcel.quit ();
Return;
}

M_objbooks = (Excel. workbooks) m_objexcel.workbooks;
If (templatefilepath. Equals (string. Empty ))
{
M_objbook = (Excel. _ workbook) (m_objbooks.add (m_objopt ));
}
Else
{
M_objbook = m_objbooks.open (templatefilepath, m_objopt,
M_objopt, m_objopt );
}
M_objsheets = (Excel. Sheets) m_objbook.worksheets;
M_objsheet = (Excel. _ worksheet) (m_objsheets.get_item (1 ));

 

4, Excel Object Model http://msdn.microsoft.com/zh-cn/library/wss56bz7.aspx

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.