472,983 Members | 2,558 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,983 software developers and data experts.

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 5777
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...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.