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