Sign in to follow this  
Followers 0
r3dbull

From .ini to Excel file

3 posts in this topic

#1 ·  Posted (edited)

Problem has been solved, topic can be closed.

For your info, the source code to the solution of my problem:

#include <Excel.au3>
#include <Array.au3>
$oExcel=ObjCreate("Excel.Application")
$oExcel.Visible=1
$oExcel.WorkBooks.Open("D:\Trash\AutoIT Scripts\Database_S8.xls")
If @error=1 Then
    ConsoleWrite("Error! - Unable to Create the Excel Object!"& @CRLF)
ElseIf @error=2 Then
    ConsoleWrite("Error! - File does not exist!" & @CRLF)
EndIf

Global $avData = _ExcelReadArray($oExcel,1,1,1000,1,1)
Global $iLastUsed =0, $iNextRow=0, $i=0, $var[10000]
$var=IniReadSectionNames("Database.ini")

For $i=1 To $var[0]
    _ExcelWriteCell($oExcel,$var[$i],$i,1)
    $var2=IniReadSection("Database.ini",$var[$i])

    For $x=1 to $var2[0][0]
        _ExcelWriteCell($oExcel,$var2[$x][0],$i,$x+2)    
    Next
$avData = _ExcelReadArray($oExcel,1,1,1000,1,1)
Next
_ExcelBookSave($oExcel)
_ExcelBookClose($oExcel)
Hi guys,

I have a .ini file that is "Updated" by a function every minute or so and what I need to do (With a separate function) is to read the entire .ini file and export it's content to an Excel for a better looking style and data managing, without overwriting cell format.

(For example, if A1 cell is formatted with green background, the function should not change that colour)

So that I can leave the .ini updating like it is doing at the moment, and every so often generate an Excel report of what's inside it.

The composition of my .ini file is like in the following:

[(ValueA|ValueA)]

xx/xx=httplink -> All these values are different from each other

xx/xx=httplink

xx/xx=httplink

[(ValueB|ValueB)]

yy/yy=httplink

yy/yy=httplink

yy/yy=httplink

And so on...

I need to have my Excel file indicized by the Main Valour, so that it will come out in something similar to this:

1          |    2    |    3    |    4   -> ... 12347
A (ValueA|ValueA)  |  xx/xx  |  xx/xx  |  xx/xx -> ... xx/xx
B (ValueB|ValueB)  |  yy/yy  |  yy/yy  |  yy/yy -> ... yy/yy

EDIT:// I have, after some research and tries, finally come to a solution , working exactly as I meant.

I'll post here the source, if anyone in future will look for something like this =)

Edited by r3dbull

Share this post


Link to post
Share on other sites



Yup its possible, look in the help file for IniRead and _ExcelWriteCell

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks for the reply :)

EDIT:// After some debugging of the code, I've got the following piece of code, I am on the way to the solution :P

As of now it writes down correctly the Sector Names, now I have to learn a bit how to iniread all the values/keys inside sectors :)

#include <Excel.au3>
#include <Array.au3>
$oExcel=ObjCreate("Excel.Application")
$oExcel.Visible=0
$oExcel.WorkBooks.Open("D:\Trash\AutoIT Scripts\Database_S8.xls")
If @error=1 Then
    ConsoleWrite("Error! - Unable to Create the Excel Object!"& @CRLF)
ElseIf @error=2 Then
    ConsoleWrite("Error! - File does not exist!" & @CRLF)
EndIf

Global $avData = _ExcelReadArray($oExcel,1,1,1000,1,1)
ConsoleWrite("Read Array"&@CRLF)
Global $iLastUsed =0, $iNextRow=0, $i=0, $var[10000]
$var=IniReadSectionNames("Database.ini")
_ArrayDisplay($var)
For $i=1 To Ubound($var) -1
    For $n = Ubound($avData) -1 to 1 Step -1
        If StringStripWS($avData[$n],8) <> "" Then
            $iLastUsed = $n
            ExitLoop
        EndIf
        Next
    If $iLastUsed Then
        $iNextRow = $iLastUsed+1
    Else
        $iNextRow=1
    EndIf
_ExcelWriteCell($oExcel,$var[$i],$iNextRow,1)
ConsoleWrite("Trovato ultima riga:"& $iNextRow&@CRLF)
$avData = _ExcelReadArray($oExcel,1,1,1000,1,1)
Next
_ExcelBookSave($oExcel)
_ExcelBookClose($oExcel)
Edited by r3dbull

Share this post


Link to post
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
Sign in to follow this  
Followers 0