Identifying Blank Excel Sheet through .NET code

A

Abhi Kumar

Hi All,

I am reading an excel sheet using OLEDB connection , now what I want t
know is how can I make out that the sheet whether the sheet is blank o
not ??

Here is my code
////////////////////////////////////////////////////////////////////////////////////

Dim connString As [String] = "Provider=Microsoft.Jet.OLEDB.4.0;"
"Data Source=" + excelFile + ";Extended Properties=Excel 8.0;"

objConn = New OleDb.OleDbConnection(connString)

Dim commandTxt As String = "Select * from [Sheet1$]"

command = New System.Data.OleDb.OleDbDataAdapter(commandTxt, objConn)

objConn.Open()
DS = New DataSet
command.Fill(DS)
////////////////////////////////////////////////////////////////////////////////


I tried this

Dim i as integer
i = DS.Tables(0).Rows.Count

if i > 1 then
end if

But the results were not as excepted and did not form any pattern
using which I could conclude that this condition gives me the exac
result


Thanx & Regards,
Abh
 
J

JMB

Normally I use one of these to test for blank sheets. I tested using Sheet3
so, of course, you will need to change that part of the code to whatever you
require.

Hope it helps!

If IsEmpty(Sheet3.UsedRange) Then _
'Do something

OR

If Application.CountA(Sheet3.Cells) = 0 Then _
'Do something
 
J

JMB

One more thought, are you just testing to ensure the cell contents are blank
or can the sheets have shapes/objects embedded in them. If so, you could
also add something similare to the following, but I am unsure if this would
capture all possible shapes/objects, etc (as I don't deal much with embedded
objects).


If Sheet3.Shapes.Count = 0 Then
'Do something
 
A

Abhi Kumar

Hi JMB,

I think to use Sheet.UsedRange or Sheet.Object requires that I have t
create an object of something like

Dim sheet as Excel.Worksheet

If this the case then , my point is that I want to avoid all sorts o
Excel Automation

Else
if I have misunderstood u pls elaborate the sulution a little more.

Regards,
Abh
 
J

JMB

No, I believe you are correct that it would require using Excel automation.

Sorry it does not help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top