How to write macro in Excel

Please  follow below steps to write Macro.

Step 1: Create a new Excel Application
Step 2: Press Alt + F11,it will open code behind window.


Step 3: By right clicking -ThisWorkbook- select Insert -> Module


Step 4: Write Hello world Program.

Sub Helloworld()
MsgBox "Hello World!!!"
End Sub

Step 5: Press F5.Msgbox will shown as   "Hello World!!!"




How to access worksheet in excel using VBA

By declaring variable as Worksheet, we can access worksheet and cell in excel.
Dim sht1 As Worksheet
Set sht1 = Worksheets(1)
sht1.Cells(1,1) = "Hello World"

How to transform XML into XHTML using XSLT through XslCompiledTransform class


XSLT (XSL Transformations):

XML - based language used for the transformation of XML documents into HTML documents. The transformation may happen dynamically either on the client or on the server.

XslCompiledTransform class:

The XslCompiledTransform class is an XSLT processor that supports the XSLT 1.0 syntax. It is a new implementation and includes performance gains when compared to the obsolete XslTransform class.

Example :

"Data.Xml" file

<xml version="1.0" ?>
<books>
<book>
<id> 1 <id>
<name> XML Concepts <name>
<author > AUTHOR1 < author>
<price > 40.00 <price>
<book>
< book>
< id> 2 <id>
<name> Website Programmingname <name>
<author> AUTHOR2 <author>
<price> 50.00 <price >
<book>
<book>
<id> 3 <id>
<name> LINQ Concepts <name>
<author> AUTHOR3 <author>
<price> 10.00 <price>
<book>
<books>


Data.XSLT file

<xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl=http://www.w3.org/1999/XSL/Transform>
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<head>
<title>How to use XslCompiledTransform Class in asp.net</title>
</head>
<body>
<h2 style="color:DarkOrange; font-style:italic;">
XSLT - Using XslCompiledTransform
&lt;/h2>
<hr width="370" align="left" color="Orange" />
<br />
<table border="1" cellpadding="5" cellspacing="0" bordercolor="CornFlowerBlue">
<tr bgcolor="DodgerBlue" style="color:White; font-weight:bold">
<td align="center">Name of Book</td>
<td>Name of Author</td>
<td>Book Price</td>
</tr>
<xsl:for-each select="books/book">
<tr bgcolor="Snow" style="color:Black; font-weight:normal; font-style:italic;">
<td height="10">
<xsl:value-of select="name"/>
</td>
<td height="10">
<xsl:value-of select="author"/>
</td>
<td height="10" style="font-weight:bold;">
<xsl:value-of select="price"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
<xsl:template>
<xsl:stylesheet>




Transform XML into HTML using XslCompiledTransform class:




using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;

public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string xmlFilePath = Request.PhysicalApplicationPath + @"App_Data\Data.xml";
string xsltPath = Request.PhysicalApplicationPath + @"App_Data\Data.xslt";
XPathDocument xPathDoc = new XPathDocument(xmlFilePath);
XslCompiledTransform transform = new XslCompiledTransform();
transform.Load(xsltPath);
transform.Transform(xPathDoc, null, Response.Output);
}
}




Output of Above page is :

In .NET how to achieve Multiple Inheritance using Interface

Diamond Problem :

The Diamond problem is related to object oriented languages that allow multiple inheritance.As we know C# does not support multiple inheritance of classes, but it does support multiple inheritance through interfaces. Therefore, the same ambiguity may arise unless explicit interface implementation is used. Going explicitly, we can have different implementations to the same method. The problem is solved.




namespace
MulipleInheritance
{


public interface IntBC
{
void Display();
}


public interface IntA : IntBC
{
new void Display();
}


public interface IntB : IntBC
{
new void Display();
}


// C class implements the IntA and IntB interfaces
public class C : IntA, IntB
{
// explicitly implement the Display() method of the IntA interface
void IntA.Display()
{
Console.WriteLine("IntA implementation of Display()");
}
// implement the Display() method of the IntB interface
public void Display()
{
Console.WriteLine("IntB implementation of Display()");
}
}


public class
MainClass
{
public static void Main()
{
C ObjC = new C();
Console.WriteLine("Calling ObjC.Display()");
ObjC.Display();
// cast ObjC to IntB
IntA RefIntA = ObjC as IntA;
Console.WriteLine("Calling RefIntA.Display()");
RefIntA.Display();
// cast ObjC to IntA
IntB RefIntB = ObjC as IntB;
Console.WriteLine("Calling RefIntB.Display()");
RefIntB.Display();
}
}


}

Output :

Calling ObjC.Display()
IntB implementation of Display()
Calling RefIntA.Display()
IntA implementation of Display()
Calling RefIntB.Display()
IntB implementation of Display()

In Class C, first Display() method is explicitly implemented for IntA Interface. Explicit implementation is not needed for the second Display() method, because previous statement already did that and the method implementation is automatically assumed to IntB interface. In order to call explicit implementation method casting is required.



Why Multiple inheritance is not supported in .NET

Multiple Inheritance:

Multiple inheritance may allow you to write compact code but it has some program difficulties like "diamond problem" for example

Diamond problem :



class
BaseClass
{
public abstract void Display();
}

class A : BaseClass
{
public override void Display()
{
Debug.WriteLine("First Child A");
}
}

class B : BaseClass
{
public override void Display()
{
Debug.WriteLine("Second Child B");
}
}

//Now Suppose that c# support multiple inheritance

class C : A, B
{
}

public class MainClass
{
public static void main()
{
C ObjC =new C();
ObjC.Display();
}
}

By excuting ObjC.Display() method Diamond problem is generated. It means which Display method going to executed.