Jump to content

Recommended Posts

Posted (edited)

This script works just fine for me for entries with multiple, single or no Client Machines. Speed can be enhanced if needed ;)

What's missing in this example is some kind of error checking. But with the code I posted so get the message faster ;)

#include <Excel.au3>

Global $oExcel = _Excel_Open()
Global $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\test.xlsx")
Global $aWorksheet = _Excel_RangeRead($oWorkbook)
_ArrayDisplay($aWorksheet)
For $i = 1 To UBound($aWorksheet, 1) - 1
    $aMaschines = StringSplit($aWorksheet[$i][2], ",")
    If @error Then ; No separator found
        If $aMaschines[1] <> "" Then ; Client machine found
            _Excel_RangeWrite($oWorkbook, Default, $aMaschines[1], "D" & $i+1)
        EndIf
    Else
        _Excel_RangeWrite($oWorkbook, Default, $aMaschines[$aMaschines[0]], "D" & $i+1)
    EndIf
Next

 

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

 

Posted (edited)

I grabbed a screenshot of your workbook that consisted of 4 columns.
This now works with your example file:

#include <Excel.au3>

Global $oExcel = _Excel_Open()
Global $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\LNtest.xlsx")
Global $aWorksheet = _Excel_RangeRead($oWorkbook)
Global $hSplashtext = SplashTextOn("Progress", "Records processed ...", -1, 50)
For $i = 1 To UBound($aWorksheet, 1) - 1
    Sleep(50)
    If Mod($i, 10) = 0 Then ControlSetText($hSplashtext, "", "Static1", "Records processed ... " & $i)
    $aMaschines = StringSplit($aWorksheet[$i][1], ",")
    If @error Then ; No separator found
        If $aMaschines[1] <> "" Then ; Client machine found
            _Excel_RangeWrite($oWorkbook, Default, $aMaschines[1], "D" & $i + 1)
        EndIf
    Else
        _Excel_RangeWrite($oWorkbook, Default, $aMaschines[$aMaschines[0]], "C" & $i + 1)
    EndIf
Next
SplashOff()

 

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

 

Posted

This one is even faster:

#include <Excel.au3>

Global $iTimer = TimerInit()
Global $oExcel = _Excel_Open()
Global $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\LNtest.xlsx")
Global $aWorksheet = _Excel_RangeRead($oWorkbook)
Global $hSplashtext = SplashTextOn("Progress", "Records processed ...", -1, 50)
Global $aTemp[UBound($aWorksheet, 1) - 1]
For $i = 1 To UBound($aWorksheet, 1) - 1
    If Mod($i, 10) = 0 Then ControlSetText($hSplashtext, "", "Static1", "Records processed ... " & $i)
    $aMaschines = StringSplit($aWorksheet[$i][1], ",")
    If @error Then ; No separator found
        If $aMaschines[1] <> "" Then ; Client machine found
            $aTemp[$i - 1] = $aMaschines[1]
        EndIf
    Else
        $aTemp[$i - 1] = $aMaschines[$aMaschines[0]]
    EndIf
Next
_Excel_RangeWrite($oWorkbook, Default, $aTemp, "C2")
SplashOff()
MsgBox(0, "Info", "Processing time: " & TimerDiff($iTimer))

Takes 4.3 seconds to process 32176 records compared to the previous version which took 460 seconds here ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

 

Posted (edited)

The slower script calls _Excel_RangeWrite for every cell, the faster stores all values in a temporary array and then writes all cells with a single call :)

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

 

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
  • Recently Browsing   0 members

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