Card Index Viewer

This is a discussion on Card Index Viewer within the C# Programming forums, part of the General Programming Boards category; I have around 6k MTG cards indexed in excel07, with the name and quantity from specific sets. I've been wondering ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    11

    Card Index Viewer

    I have around 6k MTG cards indexed in excel07, with the name and quantity from specific sets. I've been wondering if I could create a windows app with C# that would simply list the card names off the excel file in a scroll box, and when clicked on it would load the image off gatherer.wizards.com, and list the quantity below the image.
    I just don't know how to go about this, I can make the window, but I need an idea on how I should code it.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    What does the Excel data look like? It's relatively easy to read data in from Excel.

    As far as the rest is concerned, I would create a Card struct or class that has properties like Name, Quantity, URL (if necessary), etc.

    Then the pseuo-ish code would look like:

    Code:
    foreach(Row row in excelWorkSheet.Rows)
    {
      Card card = new Card();
      card.Name = row[0];
      card.Quantity = row[1];
      listBoxCards.Items.Add(card);
    }
    Then just make sure you override ToString() in your Card struct or class so it's displayed correctly in the ListBox. Something like:
    Code:
    public override string ToString()
    {
      return Name;
    }
    Last edited by itsme86; 04-25-2011 at 10:46 PM.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    11
    Thanks for your input! I'll try to start with this on the upcoming weekend.

  4. #4
    Registered User
    Join Date
    Sep 2009
    Posts
    11
    Are there any tutorials on reading a .xlsx file into C#?
    I found some ways through google but they're not working for me.
    edit : I found excel object library 12.0.
    Last edited by netto; 05-02-2011 at 02:21 PM.

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    I'm interested in seeing the data in Excel. Any way you can post a snippet of a dozen or so rows?
    If you understand what you're doing, you're not learning anything.

  6. #6
    Registered User
    Join Date
    Sep 2009
    Posts
    11
    Quote Originally Posted by itsme86 View Post
    I'm interested in seeing the data in Excel. Any way you can post a snippet of a dozen or so rows?
    http://img405.imageshack.us/img405/4641/mtgindex.png

  7. #7
    Registered User
    Join Date
    Sep 2009
    Posts
    11
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using XL = Microsoft.Office.Interop.Excel;
    
    namespace MTG_INDEX_VIEWER
    {
        public partial class Main : Form
        {
            public Main()
            {
                InitializeComponent();
            }
    
            private void Main_Load(object sender, EventArgs e)
            {
    
            }
    
            private void readxls_Click(object sender, EventArgs e)
            {
                XL.Application xlApp;
                XL.Workbook xlWorkBook;
                XL.Worksheet xlWorkSheet;
                XL.Range range;
    
                string str;
                int rCnt = 0;
                int cCnt = 0;
    
                xlApp = new XL.ApplicationClass();
                xlWorkBook = xlApp.Workbooks.Open("MTGindex.xlsx", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
                xlWorkSheet = (XL.Worksheet)xlWorkBook.Worksheets.get_Item(1);
    
                range = xlWorkSheet.UsedRange;
    
                for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
                {
                    for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++)
                    {
                        str = (string)(range.Cells[rCnt, cCnt] as XL.Range).Value2;
                        MessageBox.Show(str);
                    }
                }
    
                xlWorkBook.Close(true, null, null);
                xlApp.Quit();
    
                releaseObject(xlWorkSheet);
                releaseObject(xlWorkBook);
                releaseObject(xlApp);
            }
            private void releaseObject(object obj)
            {
                try
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                    obj = null;
                }
                catch (Exception ex)
                {
                    obj = null;
                    MessageBox.Show("Unable to release the Object " + ex.ToString());
                }
                finally
                {
                    GC.Collect();
                }
            } 
        }
    }
    It says MTGindex.xlsx not found, but its in the project folder?

  8. #8
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    Make sure it's in the same folder as the executable (e.g. MTGApp\bin\Release\MTGindex.xlsx)

    If you can't get the Excel thing to work, you can always save the file as a .csv instead. Then it's as easy to read as any other text file.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Viewer
    By cs05pp2 in forum C Programming
    Replies: 3
    Last Post: 10-26-2007, 04:33 AM
  2. ? about this> index::index () : type_intex()
    By bobk544 in forum C++ Programming
    Replies: 5
    Last Post: 09-30-2005, 02:59 PM
  3. Source Code Viewer\ascii Viewer
    By Hexxx in forum C Programming
    Replies: 4
    Last Post: 11-24-2003, 09:06 PM
  4. DLL Viewer?
    By CProgrammer2K3 in forum Tech Board
    Replies: 4
    Last Post: 02-08-2003, 07:03 AM
  5. Bit map viewer
    By Bajanine in forum Windows Programming
    Replies: 5
    Last Post: 11-03-2002, 12:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21