cplusplus.com: How to make an Excel style tables
ForumWindows Programminghow to make an Excell style table
Not logged in
how to make an Excell style table
Oct 10, 2011 at 9:27pm
Yeah, the title pretty much states it. I need to generate it dynamically too. Like the user enters the number of rows and columns.
Oct 11, 2011 at 12:05am
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
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
Just embed Excel with COM or use one of the native Grid controls
Oct 12, 2011 at 7:34pm
I don’t mean to hijack the thread, but how would you embed Excel? Is it complicated?
Oct 12, 2011 at 10:20pm
@ 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
Okay, thanks for the head-up, Computergeek01.
Oct 15, 2011 at 12:59pm
@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
And this is a shorter article which avoids MFC
How to edit listview subitems in Win32
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
However, someone has written an old-school (using WIN32 directly) grid control: BABYGRID.
Win32 Grid Control with Low Overhead (BABYGRID)
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
MFC Grid control 2.27
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
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.
General C++ Programming
© cplusplus.com, 2000-2016 – All rights reserved – v3.1
Spotted an error? contact us