cplusplus.com: How to make an Excel style tables

cplusplus.com: How to make an Excel style tables

Search:
Go
ForumWindows Programminghow to make an Excell style table
Not logged in
registerlog in
how to make an Excell style table

Oct 10, 2011 at 9:27pm
smileeFace (3)
Yeah, the title pretty much states it. I need to generate it dynamically too. Like the user enters the number of rows and columns.

Thanks
Oct 11, 2011 at 12:05am
Computergeek01 (5472)
Ok, where are you stuck? After you strip away all of the cool functionality it brings, Excel is just an array of objects with their rendering contexts displayed in two dimensions.
Oct 11, 2011 at 11:54pm
freddie1 (1409)
The generic term for what you are describing is a ‘grid’. In Windows we call them grid controls. Actually, in terms of the stock controls provided by Windows itself, i.e., the standard Windows controls (buttons, text boxes, combo boxes, etc.), or the ‘common controls’, there aren’t any grids in the full sense of the term. The closest thing is the List View Common control. Many folks have modified versions of that that allow editing cells.

Alternately, you could buy a grid custom control or make your own (its rather complex). On the other hand, if you are a do it yourself sort and like to re-invent the wheel, as I do, – think ‘array of text boxes’.
Oct 12, 2011 at 1:21pm
george135 (268)
Just embed Excel with COM or use one of the native Grid controls
Oct 12, 2011 at 7:34pm
Lamblion (642)
I don’t mean to hijack the thread, but how would you embed Excel? Is it complicated?
Oct 12, 2011 at 10:20pm
Computergeek01 (5472)
@ Lamblion: Just ignore that user, they always make some comment telling the user to use COM objects weither or not COM is even needed for to solve the problem and he NEVER follows up after a post to help users any further.
Oct 13, 2011 at 1:15am
Lamblion (642)
Okay, thanks for the head-up, Computergeek01.
Oct 15, 2011 at 12:59pm
andywestken (3990)
@smileeface – when you say you want to make an Excel style table, do you just want a basic table that people can edit? Or do you need the spreadsheet functionality, too.

(And you don’t mention what tools you use: I’m presuming Visual C++ Express, except at the very end)

If the former, then freddie’s suggestion — of using a List View control — is a good one. It’s relatively straight forward (if you know your way round the common controls and Windows GUI programming) to put together an editable table. The standard way is to use a single edit control (or combobox, etc) which is moved to cover the active cell.

CodeProject.com and CodeGuru.com have various articles illustrating this approach. One which looks reasonably clear is (it’s an MFC project, but should be translatable into normal, Petzold-style Windows code):

Editing Sub-Items in List Control
http://www.codeproject.com/KB/list/editing_subitems_in_listcontrol.aspx

And this is a shorter article which avoids MFC

How to edit listview subitems in Win32
http://www.codeproject.com/KB/list/ListsiEdit.aspx

There are asorted things you need to do to get everything to look right. for example, you’ve got to set the font used by the Edit control to match that of the List View control.

“Just” (?) embedding Excel into you app would only be a sensible way to go if you needed Excel’s full capabilities. If you have a full version of Visual C++ (rather than the Express version) then ATL and MFC both provide classses to help with this. Writing a COM container app from the ground up is not a trivial exercise (if COM, embedding, IDispatch, etc. are all new to you, this is probably not the way to go). The following article show what you’ve still got to do after you’re written your COM container application (it uses MFC)

How to embed and automate an Excel worksheet by using MFC and Visual C++ 2005 or Visual C++ .NET
http://support.microsoft.com/kb/311546

However, someone has written an old-school (using WIN32 directly) grid control: BABYGRID.

Win32 Grid Control with Low Overhead (BABYGRID)
http://www.codeguru.com/Cpp/controls/controls/gridcontrol/article.php/c5277

BABYGRID does get mixed reviews, but I’ve used it for small apps successfully. It’s prob. not the way to go if you need to handle loads of data (some people complain about its performancne).

Finally, if you do have a full version of Visual Studio, with MFC, then the following articles might be of interest.

The Ultimate Grid Home Page
http://www.codeproject.com/KB/MFC/UltimateGrid.aspx

MFC Grid control 2.27
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx

Regards,

Andy

PS If you use another GUI framework — like Qt, wxWidgets, FLTK, … — then other possibilities open up.
Last edited on Oct 15, 2011 at 2:26pm
Oct 15, 2011 at 1:15pm
andywestken (3990)
PPS I was assuming you were talking about non-.Net Windows programming. If you’re using C++/CLI, then you could use DataGrid or DataGridView (Search MSDN for info).

Last edited on Oct 15, 2011 at 1:19pm
Topic archived. No new replies allowed.
C++
Information
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Home page | Privacy policy
© cplusplus.com, 2000-2016 – All rights reserved – v3.1
Spotted an error? contact us

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s