Jump to content

Batch converting of files


Recommended Posts

I converted htm file to excel with the following script. and it gone well . ( as below

Now , I want to convert a bunch of files in the script directory at once , is there a way to process n autoit or excel udf . i Am a new to autoit just one hour ......guide lines ...please ???

#include <Excel.au3>
$sFilePath1 = @ScriptDir & "\CONRADS.htm" ;This file should already exist
$oExcel = _ExcelBookOpen($sFilePath1)
;Show any errors that might occur when Opening the File
If @error = 1 Then
    MsgBox(0, "Error!", "Unable to Create the Excel Object")
    Exit
ElseIf @error = 2 Then
    MsgBox(0, "Error!", "File does not exist - Shame on you!")
    Exit
EndIf
_ExcelBookSaveAs($oExcel, @ScriptDir & "\CONRADS", "xls")
If Not @error Then MsgBox(0, "Success", "File was Saved!", 3)
_ExcelBookClose($oExcel, 1, 0) ;This method will save then Close the file, without any of the normal prompts, regardless of changes
Link to comment
Share on other sites

Something like this (not tested):

#include <Excel.au3>
#include <File.au3>
#include <Array.au3>

Local $FileList = _FileListToArray(@ScriptDir, '*.htm', 1)
If @error Then
    MsgBox(0, "", "No Filess Found.")
    Exit
EndIf

;~ _ArrayDisplay($FileList, "$FileList")

For $i = 1 To $FileList[0]
    ConsoleWrite($FileList[$i] & @CRLF)
    ProcessFile($FileList[$i])
Next

Func ProcessFile($file_name_htm)
    $file_name_htm = @ScriptDir & '' & $file_name_htm
    $file_name_xls = StringReplace($file_name_htm,'.htm','.xls')

    $oExcel = _ExcelBookOpen($file_name_htm)
    ;Show any errors that might occur when Opening the File
    If @error = 1 Then
        MsgBox(0, "Error!", "Unable to Create the Excel Object" & @CRLF & $file_name_htm)
        Exit
    ElseIf @error = 2 Then
        MsgBox(0, "Error!", "File does not exist - Shame on you!" & @CRLF & $file_name_htm)
        Exit
    EndIf
    _ExcelBookSaveAs($oExcel, $file_name_xls, "xls")
    If Not @error Then ConsoleWrite("Success - File was Saved!" & $file_name_xls & @CRLF)
    _ExcelBookClose($oExcel, 1, 0) ;This method will save then Close the file, without any of the normal prompts, regardless of changesEndFunc
EndFunc
Edited by Zedna
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...