Jump to content
  • Advertisement
Sign in to follow this  
Jonte Jinx Carrera

c++ and Excel?

This topic is 1190 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi!
I am working on a Inventory and loot system for a Text-based RPG.
I want to use an excel spreadsheet in order to list my items and stats modifiers.
My goal to be able to read and write items and variables to the spreadsheet and make an easy and more accessable way of editing the loot system.
My thought is to have some sort of Random generated stat to all items and a drop rate system.
Kind of like the drop system in diablo 1.
Are there any tutorials that might shine a bit more light on the subject?
So far I've only found tutorials on how to read/write strings to excel files, but never a tutorial on how to handle integers in such way.
I've also heard that managing .xlsx are quite hard and that i should use .csv instead.
Since i'm more of like a beginner at programming (I've managed to make a fully working text-based RPG though. Trying to advance by finding
different solutions and making the game more complicated such as in-game currency rates.) i need to find something that isn't to advanced to understand.

Share this post


Link to post
Share on other sites
Advertisement
Don't use excel.

You're going to be using a sledgehammer to crack a peanut. A simple ini file will suffice and it won't require the same level of development.

Also to read excel you usually need to use COM which means that the user of your game will need a license for office. In my opinion that's a big assumption to make because office isn't essential.

Also office is about as performant as a snail stuck in salty treacle. It won't scale for a game inventory.

Share this post


Link to post
Share on other sites
Following nobodynews, herw's what you could do (/ what I do):

- make stuff, order data in your Excel file
- copy paste all columns and rows to an ascii file (or export/ use csv)
- simply read in the ascii file, for example with a standard ifstream

This works pretty easy and fine, just make sure not to put rubbish between the logical data.
A column switch in excel is exactly like a tab in ascii and a row like a newline

Share this post


Link to post
Share on other sites
Don't make your game read Excel files. Way too complicated. Do what the previous posters said and export from Excel to a CSV file or something simple like that. Then convert THAT into a binary form that your game actually loads.

Share this post


Link to post
Share on other sites

It is also possible to create a custom exporter for Excel, if csv doesn't cut it for some reason.

 

Office plugin development can now be done for free - first, download the Visual Studio 2013 Community Edition, and then the Office Tools for VS 2013.

 

That said, the CSV way is somewhat easier if it fits your needs :)

Edited by Nik02

Share this post


Link to post
Share on other sites

The xlsx format is not impossible to work with either. It is effectively a zip file that contains XML files (and media) that describe the document contents.

 

The format is not as trivial to read as a flat file, though. One of the reasons for the complexity is that you have a "shared string" table which is used to look up strings for the cell values. The values of cells that have a type of "s" need to be looked up from said table using an ordinal number stored with the cell.

 

All this means that you can't simply enumerate over the sheets like flat records. Which is what a format like CSV trivially enables.

Edited by Nik02

Share this post


Link to post
Share on other sites
Sure if you want to just read the raw content, using tools for excel is fine. However if you want formulas to be evaluated as you read cell values you must use excel itself via interop or COM. Excels xml format is dog ugly and not straightforward at all. As others have said you are best sticking with csv.

Share this post


Link to post
Share on other sites
Excel does cache calculated values with the cell entities, but I agree: Csv or similar would probably work better in this case.

Share this post


Link to post
Share on other sites

As previous commenters stated, excel may not be the right format for your data. I also think, that CSV or a custom format (maybe XML/JSON mixed with CSV) would be a better choice.

 

But for future reference (or if you really want to use excel for you inventory system), there exists a Qt5 library for reading and writing from/to excel spreadsheets (.xlsx files): QtXlsx. The library doesn't need office to read spreadsheets and is distributed under the MIT license (see its documentation), so you don't have to worry about licensing issues. I have not tried the library, but it looks capable enough to parse spreadsheets correctly. It depends on you if you want to introduce Qt5 as a dependency though.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!