473,465 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Excel: Check for borders of cells in all workbooks (vb.net)

Hi,

For a project at school we have to automate the assignment of seats in
classrooms to students during the exams.
The lady who previously did everything manually kept the layouts of the
classrooms in an excel-document: 1 sheet per classroom, and she marked
the cells which represent the seats with a border.
The problem however is that she sometimes merged cells together to get a
better layout.

Problems with current code:
-Very, very slow: vb takes 30 minutes to read 63 classrooms (the check
for the border is the bottleneck)
-If there is a merged area (ie. A1:A4) with a border, then A1, A2, A3
and A4 will be flagged as a seat when it actually just has to be A1
"cell" is a custom helper object to make traveling the cells easier: I
can set it to a row and column, it gives a range back as a string, and I
can move it to the left, right, up, down, etc...

My current code (checking the borders inside a sheet):
(I hope the layout remains somewhat readable)

'Read per row, a maximum of 47 rows
For row As Integer = 1 To 47
'read per column
'numCols= worksheet.UsedRange.Columns.Count
For col As Integer = 1 To numCols
'Check border of cells
Dim borders As Excel.Borders _
= CType(worksheet.Range(cell.getRange), _

Excel.Range).MergeArea.Borders
'borders.LineStyle = 1 gives error at a mergearea
If borders.Item(Excel.XlBordersIndex.xlEdgeBottom).Li neStyle = 1 _
And borders.Item(Excel.XlBordersIndex.xlEdgeLeft).Line Style = 1 _
And borders.Item(Excel.XlBordersIndex.xlEdgeRight).Lin eStyle = 1 _
And borders.Item(Excel.XlBordersIndex.xlEdgeTop).LineS tyle = 1 _
Then
'Current cell is a seat
End If 'Border = 1
cell.goRight()
Next 'Read per column
cell.setCol("A")
cell.goDown()
Next 'Read per row
Nov 20 '05 #1
1 5825
Small correction of comment in code:
'borders.LineStyle = 1 gives error at a mergearea
If borders.Item(Excel.XlBordersIndex.xlEdgeBottom).Li neStyle = 1 _
And borders.Item(Excel.XlBordersIndex.xlEdgeLeft).Line Style = 1 _
And borders.Item(Excel.XlBordersIndex.xlEdgeRight).Lin eStyle = 1 _
And borders.Item(Excel.XlBordersIndex.xlEdgeTop).LineS tyle = 1 _
Then
* 'Borders.Linestyle = 1' does NOT give an error, but gives false when
it checks a mergeArea. But it is however more than twice as fast than
checking each border seperately (is there a way to drop further checks
in an "AND" when the first one is false? Or can this only be done
through nested if's?).
* Checking each border separately returns each cell inside a mergeArea
with a border as a seat (this would be because of my own "Cell" object)
Glen Vermeylen wrote: Hi,

For a project at school we have to automate the assignment of seats in
classrooms to students during the exams.
The lady who previously did everything manually kept the layouts of the
classrooms in an excel-document: 1 sheet per classroom, and she marked
the cells which represent the seats with a border.
The problem however is that she sometimes merged cells together to get a
better layout.

Problems with current code:
-Very, very slow: vb takes 30 minutes to read 63 classrooms (the check
for the border is the bottleneck)
-If there is a merged area (ie. A1:A4) with a border, then A1, A2, A3
and A4 will be flagged as a seat when it actually just has to be A1
"cell" is a custom helper object to make traveling the cells easier: I
can set it to a row and column, it gives a range back as a string, and I
can move it to the left, right, up, down, etc...

My current code (checking the borders inside a sheet):
(I hope the layout remains somewhat readable)

'Read per row, a maximum of 47 rows
For row As Integer = 1 To 47
'read per column
'numCols= worksheet.UsedRange.Columns.Count
For col As Integer = 1 To numCols
'Check border of cells
Dim borders As Excel.Borders _
= CType(worksheet.Range(cell.getRange), _

Excel.Range).MergeArea.Borders
'borders.LineStyle = 1 gives error at a mergearea
If borders.Item(Excel.XlBordersIndex.xlEdgeBottom).Li neStyle = 1 _
And borders.Item(Excel.XlBordersIndex.xlEdgeLeft).Line Style = 1 _
And borders.Item(Excel.XlBordersIndex.xlEdgeRight).Lin eStyle = 1 _
And borders.Item(Excel.XlBordersIndex.xlEdgeTop).LineS tyle = 1 _
Then
'Current cell is a seat
End If 'Border = 1
cell.goRight()
Next 'Read per column
cell.setCol("A")
cell.goDown()
Next 'Read per row

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: | last post by:
Hi All, I want to new a Excel project from .NET using c#. I go to File/New/Project/ there is no office projects to choose. I want to know why? I installed Visual studio .Net 2003 and office...
1
by: chris | last post by:
Hi there, I load an excel file from an asp.net page and try to read it into a dataset. The problem is that it tells me: Database or object is read-only It only needs to be read only. Here is the...
2
by: Shawn | last post by:
Does anybody know how to embed an Excel Worksheet into a (vb .net) form? I want the worksheet to appear as though it's a control on the form with all the functionality of a worksheet. I don't...
2
by: Larry Jones | last post by:
I want to place information from an active Excel spreadsheet to a VB.net form. I just want to place numbers from an Excel cell in a standard VB.net text box. Does anyone have sample code to...
0
by: pp | last post by:
I have copied this code from Excel VBA, to use in a VB.net application: Dim r as Excel.Range r=Cells.Find(What:="02/01/2001 22:00:00", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart,...
3
by: Mr.Doubt | last post by:
I'm trying to run a Excel macro, which uses SOLVER.XLA Add-In, in VB.NET application. When the macro is executed I get the following error message "Solver: An unexpected internal error occured,...
3
by: nikila | last post by:
Hi, I have to create excel pivot tables from vb.net. Already I am creating excel file using oledb connection. I want to use the same to create the excel pivot tables. Can anyone please help me...
4
by: TCook | last post by:
Hey All, I've seen lots of stuff regarding pumping data into Excel from .Net but haven't found anything for the reverse. Does anyone have a snippet, article ID, etc. demonstrating how to take...
3
by: aitzi | last post by:
Hi, I am doing an application and it opens an excel page. In this page I combine cells and when I execute de program it appears dialog windows that I dont want to see. How can I do this??
2
by: =?Utf-8?B?QWRpdHlhIE5hcnZla2Fy?= | last post by:
Hi, I have developed an application which downloads word and excel files from the web and then parses them to get the relevant information. However, as of now we cannot deploy the application on...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.