Jump to content

excel rangewrite issue error 4


Recommended Posts

hi guys, i having an issue with excel rangewrite, @error = 4 ,@extended = -214735267

4 - Error occurred when writing a single cell. 

i am trying to write an excel from an array of a single column which contains ciphertext of hash function such as MD5(128 bits).

however, i tried arraytrim which did not work and arraytranspose which did not provided the correct hash output, instead it writes a 0.

Can any1 advise? thanks 

i also have tried write excel from other array columns which apparently are working fine. 

Edited by devilburnz
Link to comment
Share on other sites

; comment Hash text and put into a 2D array
$hashtext = _crypt_HashData($text, $CALG_MD5) 
$array[1][2] = $hashtext

local $oexcel = _Excel_Open()
local $workbook = _Excel_Booknew($oexcel)

;comment Write ciphertext from array to excel
_excel_rangewrite($workbook,$workbook.Activesheet,$array[1][2])

if @error then exit msgbox("excelerror","error writing to worksheet", & @CRLF & "error=" & @error & "extended =" & @extended)

the script is above, the output i am getting is a blank excel and an error messagebox stated in my first post 

Link to comment
Share on other sites

10 minutes ago, devilburnz said:
; comment Hash text and put into a 2D array
$text = "ABC"
$hashtext = _crypt_HashData($text, $CALG_MD5) 
$array[1][2] = $hashtext

local $oexcel = _Excel_Open()
local $workbook = _Excel_Booknew($oexcel)

;display string into 2d array
_Arraydisplay($array,"",Default,64,Default) ; able to view $hashtext 
;comment Write ciphertext from array to excel
_excel_rangewrite($workbook,$workbook.Activesheet,$array[1][2])

if @error then exit msgbox("excelerror","error writing to worksheet", & @CRLF & "error=" & @error & "extended =" & @extended)

the script is above, the output i am getting is a blank excel and an error messagebox stated in my first post 

if it just plan text it will work, i need some advise please if there is something addtional is missiing. 

Link to comment
Share on other sites

Just place the array[0][1] in String function i.e. String($array[0][1]).

Also just for future reference, please post working examples, it allows us to concentrate on looking at the error rather than fixing the script first to get it to work.

#include <Array.au3>
#include <Crypt.au3>
#include <Excel.au3>
Local $sText = "ABC"
Local $sHashText = _Crypt_HashData($sText, $CALG_MD5)
Local $aRange[1][2] = [[$sHashText]]
_Arraydisplay($aRange)

Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_Booknew($oExcel)
_Excel_RangeWrite($oWorkbook, Default, String($aRange[0][0]))
If @error Then Exit MsgBox(4096, "Excel Range Write Error","Error writing to worksheet" & @CRLF & "Error = " & @error & @CRLF & "Extended = " & @extended)

 

Link to comment
Share on other sites

Hi Subz.

Thanks for the help and i will take note of my posts for future reference, but unfortunately, the string function did not resolve the issue i facing, there is no error messagebox prompter and no problem displaying the hashdata in arraydisplay. 

 however, the string($aRange[1][2])) in excel still unable to display the hashdata, the excel cell column is still blank. Any advise? thanks!!  

Link to comment
Share on other sites

Did you just use my code as posted?  Because it works fine for me, 

"string($aRange[1][2]))" is incorrect usage, as I've shown that would result in an array error since you've gone out of the boundaries.
 

Local $aRange[1][2]
;~ You only have one row in this array, arrays start at 0
$aRange[0][0] = "Row1 Col1"
$aRange[0]1] = "Row1 Col2"

 

Link to comment
Share on other sites

 

yes the code works many thanks!  is there a specific method of placing them into exact places?  sorry i am no where have a high level in programming. 

Right now, my arraydisplay is displaying what i want but not able to write them all to excel prehaps due to hashdata which i narrow down my checking and found out that it contains error and empty display. so i am running out of options so i post here to figure out is there a way to display it so i can modify my codes later.

but what i am trying to achieve is to generate excel report which consist of hashdata and plaintext. and the rows and columns has to be specific in the exact column. 

$arange [3][0] = "title"
$arange [3][1] = "messsage"
$arange [3][2] = "messsage hash"
$arange [3][3] = "messsage2"
$arange [3][4] = "messsage2 hash"

 

so the output of the what i want to achieve in excel is something like below

A user would probably do some set of actions and these actions will store into the 2d array, next, from arraydisplay and finally to excel report. 

excel report 

title,message,messagehash,message2,message2hash

1, abc, $@#!@3, abc2, @#@#!2

2, abcd, @#@#2, abcd2, @#@#2

 

 

 

Edited by devilburnz
sorry typo, i able to write them all to arraydisplay but not for excel
Link to comment
Share on other sites

You would need to loop through the array for example:

#include <Array.au3>
#include <Excel.au3>

Local $aRange[3][5] = [["title", "messsage", "messsage hash", "messsage2", "messsage2 hash"],[1, "abc", "$@#!@3", "abc2", "@#@#!2"], [2, "abcd", "@#@#2", "abcd2", "@#@#2"]]
_Arraydisplay($aRange)

Local $oExcel = _Excel_Open()
Local $iRow = 1, $iCol = 1, $oWorkbook = _Excel_Booknew($oExcel)

For $i = 0 To UBound($aRange) - 1
    For $j = 0 To UBound($aRange, 2) - 1
        _Excel_RangeWrite($oWorkbook, Default, String($aRange[$i][$j]), _Excel_ColumnToLetter($iCol) & $iRow)
    Next
    $iRow += 1
    $iCol = 1
Next
_Excel_RangeWrite($oWorkbook, Default, $aRange)
If @error Then Exit MsgBox(4096, "Excel Range Write Error","Error writing to worksheet" & @CRLF & "Error = " & @error & @CRLF & "Extended = " & @extended)

 

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