Jump to content

Export database?


Recommended Posts

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'); }

Link to comment
Share on other sites

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'); }

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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...