Hard to read empty cells -- suggest new Text property

Oct 13, 2010 at 5:08 AM

I am reading a spreadsheet where many of the cells can be empty.  Cells[x,x].Value returns null and I would have to add code to handle this case when I don't really care. 

I would like to suggest adding the "Text" property to excelRangeBase.cs as follows

        /// <summary>
        /// Get/set the text value of a Cell.  Return "" instead of null for empty cells
        /// </summary>
        public string Text {
            get {
                object o = _worksheet.Cell(_fromRow, _fromCol).Value;
                if (o == null) {
                    return "";
                }
                return o.ToString();
            }
            set {
                Value = value;
            }
        }

..Eugene..

Coordinator
Oct 13, 2010 at 5:05 PM

Hi,

The next version will add an enumerator to the ExcelRange class. You can then use a foreach-loop or Linq to iterate only created cells.

Something like this to get all created cells from column A...

foreach(var cell in worksheet.Cells["A:A"])

...

Check out the the new Linq sample in the source.

Jan

Oct 13, 2010 at 5:46 PM

I am looking forward to the new version.  You have done a fantastic job with this.

If possible, I would like you to add "Text" to your main-line code.  I suspect it will be handy for a lot of other users as well.

I am using an Excel spreadsheet as the backing store for a small highly structured database.  There are a lot of reasons for doing this.  First and formost it's easy for the user.  Nothing more to install (SQL, Access, Jet, etc...)  The biggest benefit is that the user can update their data using Excel instead of the more limited (one record at a time) GUI of the application -- things like "search & replace" are possible.  The user can also use complex formulas to transform the data if needed.  BUT, manual editing results in blank cells.  The "Text" technique is perfect for quickly reading the data in a predictable way.

In the past, using Microsoft's tools, I have to either wrap their code in a new class, or call a method to handle the null or other problems with the cell data.  With access to the source code, it's nice to just add a property that does exactly what I need -- much as one does with their own code.

..Eugene..

 

Coordinator
Oct 15, 2010 at 6:49 AM

OK, I'll see what I can do