Jump to content
Sign in to follow this  
autow

Write in a excel file

Recommended Posts

Hi buddies i need write some data in a excel file (1 edit and 1 input) the input contains day,month and year,the edit contains the data :)

my code dont have any error but he doesnt write data:(I dont know how to use Excel Functions and i had try read help file)

#include <GUIConstants.au3>
#include <Excel.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 431, 277, 836, 156)
$Label1 = GUICtrlCreateLabel("Data:", 8, 40, 30, 17)
$Input1 = GUICtrlCreateInput("00/00/00", 56, 40, 57, 21)
$Edit1 = GUICtrlCreateEdit("", 0, 131, 430, 145)
$Input2 = GUICtrlCreateInput("0", 56, 72, 41, 21)
$Label2 = GUICtrlCreateLabel("Linha:", 8, 72, 33, 17)
$Label3 = GUICtrlCreateLabel("Coluna", 8, 104, 37, 17)
$Input3 = GUICtrlCreateInput("0", 56, 104, 41, 21)
$Button1 = GUICtrlCreateButton("Entrar Dados", 192, 8, 75, 25, 0)
$Label4 = GUICtrlCreateLabel("Arquivo:", 8, 8, 43, 17)
$Exemplo = GUICtrlCreateInput("Exemplo.csv", 56, 8, 121, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Func Entra()
    $File = GUICtrlRead($Exemplo)
    $Handle = _ExcelBookOpen ($File,0)
        If @error Then
        MsgBox (0,"Error","ERR")
    EndIf
    $Cell = $Input3 & $Input2
    _ExcelWriteCell ($Handle,$Edit1,$cell)
    If @error Then
        MsgBox (0,"Error","ERR")
    EndIf
        _ExcelBookClose($Handle)
            If @error Then
        MsgBox (0,"Error","ERR")
    EndIf
    MsgBox (0,"Salvo","Seus Dados foram salvos")
    EndFunc
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Entra ()
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

One thing I spotted was this, which isn't going to do what you want:

$Cell = $Input3 & $Input2
    _ExcelWriteCell ($Handle,$Edit1,$cell)

It should be something like this:

_ExcelWriteCell ($Handle,GUICtrlRead($Edit1),GUICtrlRead($Input3) & GUICtrlRead($Input2))

Use the $Cell variable if you like, the important part is using GUICtrlRead.

Share this post


Link to post
Share on other sites

need write some data in a excel file

Need to change Cel and Column also to numbers:

#include <GUIConstants.au3>
#include <Excel.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 431, 277, 836, 156)
$Exemplo = GUICtrlCreateInput("Exemplo.csv", 56, 8, 121, 21)
$Label1 = GUICtrlCreateLabel("Data:", 8, 40, 30, 17)
$Input1 = GUICtrlCreateInput("00/00/00", 56, 40, 57, 21)
$Input2 = GUICtrlCreateInput("0", 56, 72, 41, 21)
$Label2 = GUICtrlCreateLabel("Linha:", 8, 72, 33, 17)
$Label3 = GUICtrlCreateLabel("Coluna", 8, 104, 37, 17)
$Input3 = GUICtrlCreateInput("0", 56, 104, 41, 21)
$Label4 = GUICtrlCreateLabel("Arquivo:", 8, 8, 43, 17)
$Edit1 = GUICtrlCreateEdit("", 0, 131, 430, 145)
$Button1 = GUICtrlCreateButton("Entrar Dados", 192, 8, 75, 25, 0)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
Func Entra()
    $File = GUICtrlRead($Exemplo)
    MsgBox(0, '', $File)
    $Handle = _ExcelBookOpen(@ScriptDir & "\" & $File, 0)
    If @error Then
        MsgBox(0, "Error", "ERR")
    EndIf
    $Cell = $Input3 & $Input2
    _ExcelWriteCell($Handle, GUICtrlRead($Edit1), Number(GUICtrlRead($Input2)), Number(GUICtrlRead($Input3)))
    If @error Then
        MsgBox(0, "Error", "ERR")
    EndIf
    _ExcelBookClose($Handle)
    If @error Then
        MsgBox(0, "Error", "ERR")
    EndIf
    MsgBox(0, "Salvo", "Seus Dados foram salvos")
EndFunc   ;==>Entra
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Entra()
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

i need change the code,now he save in a txt file but have some bugs...he save crazy stuff

#include <GUIConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Usuário\Desktop\Form1.kxf
$Form1 = GUICreate("Form1", 487, 261, 474, 137)
$Data = GUICtrlCreateInput("", 64, 8, 65, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER))
$Label1 = GUICtrlCreateLabel("Data:", 16, 8, 30, 17)
$Label2 = GUICtrlCreateLabel("Cliente:", 16, 80, 39, 17)
$Label3 = GUICtrlCreateLabel("Usuário:", 16, 40, 43, 17)
$Label4 = GUICtrlCreateLabel("Problema", 24, 120, 48, 17)
$Label5 = GUICtrlCreateLabel("Inicio:", 184, 8, 32, 17)
$Label6 = GUICtrlCreateLabel("Fim", 184, 40, 20, 17)
$Hora1 = GUICtrlCreateInput("00", 224, 8, 25, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER))
$pts = GUICtrlCreateLabel(":", 256, 8, 7, 17)
$Min1 = GUICtrlCreateInput("00", 264, 8, 25, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER))
$Hora2 = GUICtrlCreateInput("00", 224, 40, 25, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER))
$Label7 = GUICtrlCreateLabel(":", 256, 40, 7, 17)
$Min2 = GUICtrlCreateInput("00", 264, 40, 25, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER))
$Label8 = GUICtrlCreateLabel("Soluçao", 248, 120, 43, 17)
$User = GUICtrlCreateInput("User", 64, 40, 97, 21)
$Pobrema = GUICtrlCreateEdit("", 0, 137, 213, 121)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKBOTTOM)
$Solucao = GUICtrlCreateEdit("", 240, 138, 246, 121)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT+$GUI_DOCKBOTTOM)
$Cliente = GUICtrlCreateInput("Cliente", 64, 80, 97, 21)
$Button1 = GUICtrlCreateButton("Salvar", 328, 8, 83, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Func Save()
    $LOG = $Data & ";" & $Cliente & ";" & $User & ";" & $Pobrema & ";" & $Solucao & ";" & $Hora1 & ":" & $Min1 & ";" & $Hora2 & ":" & $Min2
    $file = FileSaveDialog("Salve File", "", "All files (*.txt;)")
    _FileWriteToLine ($file,InputBox("Linha","Insira a linha para salvar"),$LOG,1)
EndFunc
While 1
$nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Save()
EndSwitch
WEnd

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  

×
×
  • Create New...