Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to detect an empty cells in Excel file using getRows method?

Posted on 2003-03-27
4
Medium Priority
?
311 Views
Last Modified: 2013-12-25
Hi. I have an annoying trouble trying to detect an empty cells in Excel file using getRows() method.
Here's the working code. It just reads an Excel file and then writes data directly to html page.
I just want to detect empty cell by value and write "EMPTY CELL" phrase instead of writing empty space.
But cell comparison to empty string ("") does not work -- :(

Can you help me to detect empty cells?

CODE: Please look for "HERE'S MY TROUBLE" string to see my trouble's area:

<%
     Set oConn = Server.CreateObject("ADODB.Connection")
     strConn = "Driver={Microsoft Excel Driver (*.xls)}; DBQ=D:\Projects\goodsdata-6.xls;"
     oConn.Open strConn

     strCmd = "SELECT * from GoodsData" ' GoodsData is named set of cells in Excel worksheet
     Set oRS = Server.CreateObject("ADODB.Recordset")
     oRS.Open strCmd, oConn

     Dim cell
     cell = oRS.GetRows ()

     Response.Write ("<table bgcolor='#778899' border='1' cellpadding='4' cellspacing='0'><tr><td>")

     For rowNum = 0 To oRS.Fields.Count
          For colNum = 0 To 10
'HERE'S MY TROUBLE:
               If cell ( colNum, rowNum ) = "" Then
                    Response.write "EMPTY CELL </td><td>"              
               Else
                    Response.write cell( colNum, rowNum ) & "</td><td>"
               End If              
          Next
          Response.write ("</td></tr><tr><td>")
     Next

     Response.Write ("</td></tr></table><p>")
%>

Maybe, I go wrong way? Thanks in advance..
0
Comment
Question by:Rostichka
4 Comments
 
LVL 27

Accepted Solution

by:
Dabas earned 100 total points
ID: 8220268
See if any of Excel's IS functions helps you.
I thought there was an IsEmpty somewhere but cannot find it in my Object Browser. But there are several other IS functions such as IsText and IsNumber. Maybe a combination of those two might help you out.

Dabas
0
 
LVL 3

Assisted Solution

by:WRNewman
WRNewman earned 100 total points
ID: 8220466
if cell(x,y).value > chr(0) then

Detects if there is a value in the cell
If there is nothing then it will be ASCII 0 ie  Null

This has worked for me more times than I can remember
0
 
LVL 4

Assisted Solution

by:P1
P1 earned 100 total points
ID: 8221249
First off, you have data in Recordset Format from an Excel spreadsheet and not Excel cell's data.

i.e.
Select Case rs.Fields.Item(j).Type
  Case adSmallInt         '2  
       If rs.Fields.Item(j).Value = 0 Then  
             
'You can aggregate simular types to make this easier.
'You two basic types, numbers and strings. BTW Dates are numbers.
'Just depends on the datatypes being imported.

Regards,  P1
0
 
LVL 1

Expert Comment

by:ayufans
ID: 9272371
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points split between Dabas, WRNewman and P1

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

ayufans
Cleanup Volunteer
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question