Jump to content

Scan specific cells in Excel, error out if format is wrong


 Share

Recommended Posts

I'm just a QA guy trying to make his life easier. Any hints or links to useful sources would be much appreciated. Admittedly I haven't done much research in the forums for this problem yet. I just wanted to throw it out there and get some general feedback.

Requirement:

Our java devs currently have an application that generates an .icf file using excel and a sql db as sources. I use a 3rd party application to load another database with the data in that .icf file.

Problem:

We have two breakdowns here. Both our Java application and the 3rd party apps fail to catch certain formatting errors in the Excel spreadsheet (updated by end-user).

Possible Solution:

I would like to create a standalone exe that the end-user can use to scan the Excel document after they have updated it. I would like the exe to throw up an error message when a cell doesn't contain the correct formatting. The error message should identify the cell(s) in question.

Thanks in advance!

-MSF

Link to comment
Share on other sites

I would have a look into Excel.udf (delivered with autoit) and see how you can access Excel. The excel.udf functions are described in the autoit help -> user defined functions.

Or you search this forum for exelcom.udf. It has some advanced features.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I would have a look into Excel.udf (delivered with autoit) and see how you can access Excel. The excel.udf functions are described in the autoit help -> user defined functions.

Or you search this forum for exelcom.udf. It has some advanced features.

Thanks! I just did a search in the help for _excel and nothing popped up. Guess I was wrong.

Edit: I was doing my search in the "Search" tab. I searched in the "Index" tab for _Excel and got a bunch of results

Edited by MSF
Link to comment
Share on other sites

any reason why it has to be an .exe file.

Its much easier to write this within vbs (vbscript file).

You then first write it in an excel vba macro which you then finally translate to a vbs standalone file.

Only drawback I can think of is that people could access the VBS file.

Link to comment
Share on other sites

any reason why it has to be an .exe file.

Its much easier to write this within vbs (vbscript file).

You then first write it in an excel vba macro which you then finally translate to a vbs standalone file.

Only drawback I can think of is that people could access the VBS file.

I haven't learned vbs yet. I was hoping I could save time by using autoIT

Link to comment
Share on other sites

any solution you choose will be based on the microsoft excel object model

AutoIt has just some wrapper functions around this model

Visual basic macro

Sub scanExcelWorkbook()
    Dim xlapp As Excel.Application
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim wCell As Range
    
    Set xlapp = Application
    Set xlapp = CreateObject("excel.application")
    
    Set wb = xlapp.Workbooks.Open("map1.xls", False, True)
    
    Set ws = wb.Worksheets(1)
    
    i = 1
    While ws.Cells(i, 1) <> ""
        j = 1
        While ws.Cells(i, j) <> ""
            Set wCell = ws.Cells(i, j)
            Debug.Print wCell.Font.ColorIndex & ";" & wCell.Interior.ColorIndex
            'MsgBox wCell.Font.ColorIndex & ";" & wCell.Interior.ColorIndex
            j = j + 1
        Wend
        i = i + 1
    Wend
      
End Sub
'false=0
'true=-1

VBS script

'Sub scanExcelWorkbook()
'   Dim xlapp As Excel.Application
'   Dim wb As Workbook
'   Dim ws As Worksheet
'   Dim wCell As Range
    
'   Set xlapp = Application
    Set xlapp = CreateObject("excel.application")
    
    Set wb = xlapp.Workbooks.Open("map1.xls", False, True)
    
    Set ws = wb.Worksheets(1)
    
    i = 1
    While ws.Cells(i, 1) <> ""
        j = 1
        While ws.Cells(i, j) <> ""
            Set wCell = ws.Cells(i, j)
            Debug.Print wCell.Font.ColorIndex & ";" & wCell.Interior.ColorIndex
            'MsgBox wCell.Font.ColorIndex & ";" & wCell.Interior.ColorIndex
            j = j + 1
        Wend
        i = i + 1
    Wend
      
'End Sub
'false=0
'true=-1

Within AutoIT (not debugged)

$xlApp = ObjCreate("Excel.Application") 
$wb = $xlapp.Workbooks.Open("map1.xls", 0, -1)
$ws = $wb.Worksheets(1)
    
    $i = 1
    While $ws.Cells($i, 1) <> ""
        $j = 1
        While $ws.Cells(i, j) <> ""
            $wCell = $ws.Cells(i, j)
            consolewrite $wCell.Font.ColorIndex & ";" & $wCell.Interior.ColorIndex
            $j = $j + 1
        Wend
        $i = $i + 1
    Wend
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...