how to make an Excell style table

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
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.
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'.
Just embed Excel with COM or use one of the native Grid controls
I don't mean to hijack the thread, but how would you embed Excel? Is it complicated?
@ 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.
Okay, thanks for the head-up, Computergeek01.
@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
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
Topic archived. No new replies allowed.