Object model
Object model is almost same as object model in macros for MS Office.
Differences are only for initialization of application and "special" members such as parametrized properties, because they can not be used in some languages ( i.e. C# ).
Parametrized properties are exchanged with methods with "Get/Set" prefix.

All types and members are documented with "System.ComponentModel.DescriptionAttribute" type.
Some types & members has samples.


Create a application object
Application app = Application.CreateApplication();

Close a application object


Safe using a application object
using( Application app = Application.CreateApplication() ) {
    // do something


Working with MS Excel:
using MSExcel = TcKs.MSOffice.Excel;
// The thread which communicate with MS Office must have a same culture as the MS Office.
// It's a well-know bug for several versions of MS Office.
// This bug is not in MS Office MUI.
// My language mutation of MS Office is "en-US".
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo( "en-US" );

using ( MSExcel.Application app = MSExcel.Application.CreateApplication() ) {
	MSExcel.Workbook book1 = app.Workbooks.Open( this.txtOpen_FilePath.Text );
	MSExcel.Worksheet sheet1 = (MSExcel.Worksheet)book1.Worksheets[1];
	MSExcel.Range range_A1 = sheet1.GetRange( "A1" );
	MSExcel.Range range_B2 = sheet1.GetRange( "B2" );

	string message = "In cell 'A1' is '{0}' and in cell 'B2' is '{1}'.";
	message = string.Format( message, range_A1.Value, range_B2.Value );

	MessageBox.Show( message );

// Forced garbage collection. This is not necessary, but usefull.

Last edited Oct 6, 2008 at 6:23 PM by tencokacistromy, version 6


No comments yet.