473,320 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 5815
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.