Click here to Skip to main content
13,088,305 members (54,774 online)
Rate this:
Please Sign up or sign in to vote.
Hi everyone,
Can anybody tell me that how can I open a excel worksheet as mdi form in C#.

I searched code project but didn't find anything worthy.

My search results:Hosting an Excel application in an MDI Form[^]

Please help me as soon as possible.
Posted 9-Oct-12 0:38am
This is not how it works. What do you mean by "open"? Open as what? There is no "Excel control" (as well as "Word" and the like) -- they are proprietary to Office. You can simulate Excel-like grid and fill it with Excel data using Office interop.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You could not find anything worthy just because there is no such thing. Please see my comment to the question. Even if some kind of "Excel control" existed, it would be a part of Office, not Windows, so it could not be a part of .NET FCL (Framework Class Library,[^]).

I suggested you to simulate Excel-like behavior using System.Windows.Forms.DataGridView:[^].

As you tag the versions of .NET from 1.0 (however, I suggest you should not consider anything prior v.2.0), I'm not discussing WPF which was introduced in v.3.0.

In this way, you would need to develop functionality by yourself, with this component being close enough for spreadsheet application; and all you need for Excel interop would be data exchange. You can find enough of sample code from the article you found. If you have questions, you can also ask the author to answer them. If you load the page you've referenced in your question and locate "Comments and Discussions", you can click "Add a Comment or Question" to ask your question and give the author a chance to reply.

The alternative way could be using third-party open-source library working with Excel data format without the interop. For example, consider LibreOffice:[^],[^].

To use the source code in your .NET projects, you will need to use P/Invoke:[^],[^].

This CodeProject article can also be useful:
Essential P/Invoke[^].

Alternatively to P/Invoke, you can use a mixed-mode project written in C++/CLI. It can contain unmanaged code, but you can wrap some code in "ref" managed classes or structures, and make them public to be accessible by other .NET assemblies. This way, the resulting executable module would become a .NET Assembly which you can use as any other assembly in your .NET project. Please see:[^],[^],[^].

Finally, I would recommend you to avoid MDI. You don't want the suffering from this outdated and inconvenient UI style and scare off your users. Do yourself a great favor: do not use MDI at all. You can do much easier to implement design without it, with much better quality. MDI is highly discouraged even by Microsoft, in fact, Microsoft dropped it out of WPF and will hardly support it. More importantly, you will scare off all your users if you use MDI. Just don't. I can explain what to do instead.
First, please see:[^],
How to Create MDI Parent Window in WPF?[^],
as well as my past answers where I also explain what to do instead:
Question on using MDI windows in WPF[^],
MDIContainer giving error[^],
How to set child forms maximized, last childform minimized[^].

Maciej Los 9-Oct-12 14:52pm
Excellent! My 5!
Thank you, Maciej.
Mohammad A Rahman 9-Oct-12 20:08pm
great :)
Thank you, Mohammad.
Akkywadhwa 10-Oct-12 6:03am
Sergey Alexandrovich Kryukov 10-Oct-12 10:54am
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 9 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100