Jump to content

Recommended Posts

Posted (edited)

Hi,

I have about 205 lines  in Array.
I want to write this data to Excel. But it writes random amount rows each time. usually 90rows.
At same time I use also FileWriteLine and this works perfect, all 205 lines will be there.
Here's my code for excel 
 

Func _ExportData($aArray)
    
   Sleep(100)
    Global $oExcel = _Excel_Open(False, False, True, True, True)
    Global $oWorkBook
    If Not FileExists($sDataFilePath) Then
        $oWorkBook = _Excel_BookNew($oExcel)
    Else
        $oWorkBook = _Excel_BookOpen($oExcel, $sDataFilePath)

EndIf
Local $sRange = "A1:F600"
_Excel_RangeDelete($oWorkbook.Activesheet, $sRange)
Sleep(1000)
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aArray)
Sleep(1000)
   _Excel_BookSaveAs($oWorkBook, $sDataFilePath)
   _Excel_Close($oExcel, Default, True)
   killEXCEL()
      
EndFunc   ;==>_ExportData

 

Edited by dersiniar
Posted

Can you try setting $bForceFunc to True within _Excel_RangeWrite?  Recall had to do this for a script I wrote a few years back, forget the reason why.

Posted

Why $bForceFunc is needed in some cases is described in the Wiki.

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted
  On 6/8/2022 at 10:56 AM, Subz said:

Can you try setting $bForceFunc to True within _Excel_RangeWrite?  Recall had to do this for a script I wrote a few years back, forget the reason why.

Expand  

Umm, can you help me with it? im not sure how to add this

Posted

Please post the values of @error and @extended after calling _Excel_RangeWrite.
$forceFunc does not solve all problems described in the Wiki (see my link above). Add your array to the example script and post the result.

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted
  On 6/9/2022 at 6:52 AM, water said:

Please post the values of @error and @extended after calling _Excel_RangeWrite.
$forceFunc does not solve all problems described in the Wiki (see my link above). Add your array to the example script and post the result.

Expand  

I do not have "@error and @extended" 

Array

Global $aArray[1][5] = [["A","B","C","D","E"]]

ArrayAdd
 

_ArrayAdd($aArray, $First & "|" & $Second & "|" & $Third & "|" & $Forth& "|" & $Fifth)

And Write to excel

Func _ExportData($aArray)
    
   Sleep(100)
    Global $oExcel = _Excel_Open(False, False, True, True, True)
    Global $oWorkBook
    If Not FileExists($sDataFilePath) Then
        $oWorkBook = _Excel_BookNew($oExcel)
    Else
        $oWorkBook = _Excel_BookOpen($oExcel, $sDataFilePath)

EndIf
Local $sRange = "A1:F600"
_Excel_RangeDelete($oWorkbook.Activesheet, $sRange)
Sleep(1000)
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aArray, "A1", True, True)
Sleep(1000)
   _Excel_BookSaveAs($oWorkBook, $sDataFilePath)
   _Excel_Close($oExcel, Default, True)
   killEXCEL()
      
EndFunc   ;==>_ExportData

All cells have max value 30caracters
and there must be 205 lines and 5 columns.
Array works good, cos i have same outbut in txt file, but i need csv not txt.
 

FileWriteLine($file1, $First & "|" & $Second & "|" & $Third & "|" & $Forth& "|" & $Fifth)

Sample from csv
A B C D E F 
€10  Artur    5h €9.99    June 16
€10 Juhan    5h Not Found    Not Found
€12 Artur     1.2h Not Found    Not Found
€12 Enn        1.2h Not Found    Not Found
 

Posted

One solution can be like this, instead using array,

Maybe I can write lines directly to excel using same system as i write to txt file?
FileWriteLine($file1, $First & "|" & $Second & "|" & $Third & "|" & $Forth& "|" & $Fifth)

Posted (edited)
  On 6/9/2022 at 7:07 AM, dersiniar said:

I do not have "@error and @extended" 

Expand  

This are AutoIt macros.
Add

ConsoleWrite("@error=" & @error & ", @extended=" & @extended & @CRLF)

after _Excel_RangeWrite and post the result.

Edited by water

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted
  On 6/9/2022 at 6:52 AM, water said:

Add your array to the example script and post the result.

Expand  

Run the example script from the wiki with your data and post the result.

My UDFs and Tutorials:

  Reveal hidden contents

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...