Jump to content
Sign in to follow this  
nht3004

Export database?

Recommended Posts

nht3004

I want to export an INI file to an Excel file, what should I do?

I have an INIFile:

[Student number 1]
ID=1;
Score=9;
[Student number 2]
ID=2;
Score=10;

And an excel page should be:

Name                                        ID                                      Score
Student Number 1                            1                                          9
Student Number 2                            2                                          10

Thanks ^_^

Edited by nht3004

for(loop=0; loop<infinity; loop++) { alert('I love you'); }

Share this post


Link to post
Share on other sites
MrMitchell

Read from INI, write to Excel. Take it a step at a time.

Why don't you post what code you have so far? Might want to #include <Excel.au3> too.

Share this post


Link to post
Share on other sites
nht3004

Read from INI, write to Excel. Take it a step at a time.

Why don't you post what code you have so far? Might want to #include <Excel.au3> too.

I thought of it but I dont know how to write to an Excel, do you mean open an excel an use SEND(KEY)?

for(loop=0; loop<infinity; loop++) { alert('I love you'); }

Share this post


Link to post
Share on other sites
Quual

Do you know how to use VBA in excel ?

If so, accessing the .ini files and filling cells with the data via VBA would be a lot easier than doing it with AutoIt.

Here are some simple VBA functions to read/write .ini files.

Paste the following code into its own module.

Private Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" _
(ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, _
ByVal nSize As Long, ByVal lpFileName As String) As Long

Private Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" _
(ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long

Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" _
(ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
'-------------------

'reads ini string
Public Function ReadIni(filename As String, section As String, key As String) As String
Dim RetVal As String * 255, v As Long
v = GetPrivateProfileString(section, key, "", RetVal, 255, filename)
ReadIni = Left(RetVal, v)
End Function

'reads ini section
Public Function ReadIniSection(filename As String, section As String) As String
Dim RetVal As String * 255, v As Long
v = GetPrivateProfileSection(section, RetVal, 255, filename)
ReadIniSection = Left(RetVal, v - 1)
End Function

'writes ini
Public Sub WriteIni(filename As String, section As String, key As String, value As String)
WritePrivateProfileString section, key, value, filename
End Sub

'writes ini section
Public Sub WriteIniSection(filename As String, section As String, value As String)
WritePrivateProfileSection section, value, filename
End Sub

If you have no experience with VBA I suggest using Autoit to read the .ini files and export the data as a csv (comma seperated values] file.

Name,ID ,Score

Student Number 1,1,9

Student Number 2,2,10

Excel can import a cvs file directly into a worksheet. (file - open - change files of type dropdown to Txt (*.cvs) and select the file.

Share this post


Link to post
Share on other sites
MrMitchell

If you have no experience with VBA I suggest using Autoit to read the .ini files and export the data as a csv (comma seperated values] file.

Name,ID ,Score

Student Number 1,1,9

Student Number 2,2,10

Excel can import a cvs file directly into a worksheet. (file - open - change files of type dropdown to Txt (*.cvs) and select the file.

I like this approach, it would be very easy and you don't have to touch Excel UDF.

You could use IniReadSectionNames then for each element of that you can use IniReadSection and write to a CSV.

Share this post


Link to post
Share on other sites
nht3004

Thanks alot, I'll try all the way you tell me ^^!


for(loop=0; loop<infinity; loop++) { alert('I love you'); }

Share this post


Link to post
Share on other sites
MrMitchell

Any luck?

Edited by MrMitchell

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.