Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/31/2017 in all areas

  1. nice example @funkey it makes easy to print tables in full & multi page mode. Here another example on how to put tables on the page by passing data in an 1D or 2D array, with the possibility to positioning it where you want and with a desired dimension using the _InsertArrayTable() function. I've also inserted a "graph paper" as background" so to be facilitated to position "stuff" on the page (as you can see the origin of the axis is on the bottom-left). To remove the "graph paper" from the background, just comment out all lines between _StartObject and _EndObject. this demo uses as data an array generated by the _GenerateMonth function that returns an 7x7 array containing a month af an year. Of course you can pass any array of your choice. p.s. if you get this error: ERROR: _Iif() already defined then just remove or rename the _Iif() function from the bottom of the script. this occurs with older AutoIt versions have fun. #include "MPDF_UDF.au3" ; get it here https://www.autoitscript.com/forum/topic/118827-create-pdf-from-your-application/ #include <Date.au3> #include <array.au3> ; ----- set the properties for the pdf ----- _SetTitle("Demo Table PDF in AutoIt") _SetSubject("Demo Table PDF in AutoIt") _SetKeywords("pdf, demo, table, AutoIt") _OpenAfter(True);open after generation _SetUnit($PDF_UNIT_CM) _SetPaperSize("A4"); A4 vertical _SetZoomMode($PDF_ZOOM_FULLPAGE) _SetOrientation($PDF_ORIENTATION_PORTRAIT) ; set page vertical _SetLayoutMode($PDF_LAYOUT_CONTINOUS) ;initialize the pdf (create the pdf file on disk) _InitPDF(@ScriptDir & "\Example_Table.pdf") ; === load used font(s) === _LoadFontTT("_CalibriB", $PDF_FONT_CALIBRI, $PDF_FONT_BOLD) _LoadFontTT("_CalibriI", $PDF_FONT_CALIBRI, $PDF_FONT_ITALIC) _LoadFontTT("_Calibri", $PDF_FONT_CALIBRI) ; ----- draw graph paper on all pages ------------------------------------ ; this "object" will be automatically inserted on each new page ; _StartObject("GraphPaper", $PDF_OBJECT_ALLPAGES) ; $PDF_OBJECT_NOTFIRSTPAGE For $i = 0 To 21 Step 0.1 ; vertical steps every 1 mm on the bottom border _DrawLine($i, 0, $i, 0.75, 2, 10, 0.03, 0xD0D0D0, 0, 0) Next For $i = 0 To 29.7 Step 0.1 ; horizontal steps every 1 mm on the left border _DrawLine(0, $i, 0.75, $i, 2, 10, 0.03, 0xD0D0D0, 0, 0) Next For $i = 0 To 21 ; vertical lines _DrawLine($i, 0, $i, 29.7, 2, 10, 0.03, 0xD0D0D0, 0, 0) ; vertical line every 1 cm along the page _DrawLine($i, 0, $i, 1, 2, 10, 0.03, 0x909090, 0, 0) ; mark steps every 1 cm on the bottom (a little darker) _DrawLine($i - 0.50, 0, $i - 0.50, 29.7, 2, 10, 0.02, 0xD0D0D0, 0, 0) ; vertical line every 1/2 cm _DrawLine($i - 0.25, 0, $i - 0.25, 29.7, 2, 10, 0.01, 0xF0F0F0, 0, 0) ; vertical line every 1/4 cm _DrawLine($i + 0.50, 0, $i + 0.50, 29.7, 2, 10, 0.02, 0xD0D0D0, 0, 0) ; vertical line every 1/2 cm _DrawLine($i + 0.25, 0, $i + 0.25, 29.7, 2, 10, 0.01, 0xF0F0F0, 0, 0) ; vertical line every 1/4 cm ; following code line writes the nr. of this cm _DrawText($i + 0.02, 1, $i, "_TimesT", 9, $PDF_ALIGN_LEFT, 0) Next For $i = 0 To 29.7 ; horizontal lines _DrawLine(0, $i, 21, $i, 2, 10, 0.03, 0xD0D0D0, 0, 0) ; horizontal line every 1 cm along the page _DrawLine(0, $i, 1, $i, 2, 10, 0.03, 0x909090, 0, 0) ; mark steps every 1 cm on the left (a little darker) _DrawLine(0, $i - 0.50, 21, $i - 0.50, 2, 10, 0.02, 0xD0D0D0, 0, 0) ; horizontal line every 1/2 cm _DrawLine(0, $i - 0.25, 21, $i - 0.25, 2, 10, 0.01, 0xF0F0F0, 0, 0) ; horizontal line every 1/4 cm _DrawLine(0, $i + 0.50, 21, $i + 0.50, 2, 10, 0.02, 0xD0D0D0, 0, 0) ; horizontal line every 1/2 cm _DrawLine(0, $i + 0.25, 21, $i + 0.25, 2, 10, 0.01, 0xF0F0F0, 0, 0) ; horizontal line every 1/4 cm ; following code line writes the nr. of this cm _DrawText(1, $i + 0.02, $i, "_TimesT", 9, $PDF_ALIGN_LEFT, 0) Next _EndObject() ; ------------------------------------------------------------------------ _BeginPage(); begin new page (above object is inserted automatically) ; ; insert the table on the pdf page (see header of function for parameters) ; Local $iYear = 1962, $iMonth = 5 ; just for example Local $aMyTable = _GenerateMonth($iYear, $iMonth) ; create an array containing wanted month Local $fXpos = 3 Local $fYpos = 23 Local $fWidth = 8 Local $fHeight = 4 Local $dTxtColor = 0x00ff00 Local $dFillColor = 0xF0F0F0 Local $dBorderColor = 0xff0000 ; _InsertArrayTable($fXpos, $fYpos, $fWidth, $fHeight, $aMyTable, $dTxtColor, $dFillColor, $dBorderColor) ; ; draw a rectangle above the table _SetColourStroke($dBorderColor) _Draw_Rectangle($fXpos, $fYpos + $fHeight, $fWidth, .7, $PDF_STYLE_STROKED, 0, $dFillColor, 0.01) ; 0.01 is the thickness of the edge pane frame ; draw a string on the page (we put this screen in the rectangle above the table) Local $sMyString = _DateToMonth($iMonth, $DMW_LOCALE_LONGNAME) & " " & $iYear _InsertRenderedText($fXpos + .2, $fYpos + $fHeight + .25, $sMyString, "_CalibriI", 14, 100, $PDF_ALIGN_LEFT, $dTxtColor, $dBorderColor) _EndPage() _ClosePDFFile(); write the buffer to disk ; #FUNCTION# ==================================================================================================================== ; Name ..........: _InsertArrayTable ; Description ...: ; Syntax ........: _InsertArrayTable($fX, $fY[, $fW = 0[, $fH = 0[, $aData = ""[, $dTxtColor = 0x000000[, $dFillColor = 0xF0F0F0[, ; $dBorderColor = 0xdddddd]]]]]]) ; Parameters ....: $fX - X position (cm from the left side of the paper) ; $fY - y position (cm from the bottom side of the paper) ; $fW - wanted table total width in cm ; $fH - wanted table total height in cm ; $aData - An 1D or 2D array containing data to be inserted in the table (a simple variable as well) ; $dTxtColor - [optional] Text Color. Default is 0x000000. ; $dFillColor - [optional] Background Color. Default is 0xF0F0F0. ; $dBorderColor - [optional] Border Color. Default is 0xdddddd. ; Return values .: None ; Author ........: Chimp ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _InsertArrayTable($fX, $fY, $fW = 0, $fH = 0, $aData = "", $dTxtColor = 0x000000, $dFillColor = 0xF0F0F0, $dBorderColor = 0xdddddd) Local $aTemp[1][1] If Not IsArray($aData) Then $aTemp[0][0] = $aData ElseIf UBound($aData, 0) > 2 Then Return SetError(1) ; max 2 dimensions ElseIf UBound($aData, 0) = 1 Then; 1d array becomes a 2d array ReDim $aTemp[1][UBound($aData)] For $i = 0 To UBound($aData) - 1 $aTemp[0][$i] = $aData[$i] Next ElseIf UBound($aData, 0) = 2 Then $aTemp = $aData EndIf $iCols = UBound($aTemp, 2) ; number of columns in the table $iRows = UBound($aTemp, 1) ; number of rows in the table Local $fPgW = Round(_GetPageWidth() / _GetUnit(), 1) Local $fPgH = Round(_GetPageHeight() / _GetUnit(), 1) If $fW = 0 Then $fW = $fPgW - $fX - 2 If $fH = 0 Then $fH = $fPgH - $fY - 2 Local $iColW = $fW / $iCols ; width of each single column Local $iRowH = $fH / $iRows ; heigth of each single row Local $sText ; _Draw_Rectangle($fX, $fY, $fW, $fH, $PDF_STYLE_STROKED, 0, $dFillColor, 0.01) For $i = 0 To $iRows - 1 For $j = 0 To $iCols - 1 _SetColourStroke($dBorderColor) _Draw_Rectangle($fX + $j * $iColW, $fY + $fH - ($i + 1) * $iRowH, $iColW, $iRowH, $PDF_STYLE_STROKED, 0, $dFillColor, 0.01) ; 0.01 is the thickness of the edge pane frame $sText = $aTemp[$i][$j] _InsertRenderedText($fX + $j * $iColW + $iColW / 10, $fY + $fH - ($i + 1) * $iRowH + ($iRowH - 10 / _GetUnit()) / 2, $sText, "_Calibri", 10, 100, $PDF_ALIGN_LEFT, $dTxtColor) Next Next EndFunc ;==>_InsertArrayTable Func _GenerateMonth($iYear = @YEAR, $iMonth = @MON, $ISO = True) ; this function creates a month calendar into an 7x7 array Local $aMonth[7][7], $iDOW Local $iFirstDOW = $ISO ? _DateToDayOfWeekISO($iYear, $iMonth, 1) : _DateToDayOfWeek($iYear, $iMonth, 1) For $iDay = 1 To 7 $aMonth[0][$iDay - 1] = $ISO ? _DateDayOfWeek(Mod($iDay, 7) + $ISO, $DMW_LOCALE_SHORTNAME) : _DateDayOfWeek($iDay, $DMW_LOCALE_SHORTNAME) Next For $iDay = 1 To _DateDaysInMonth($iYear, $iMonth) $iDOW = $ISO ? _DateToDayOfWeekISO($iYear, $iMonth, $iDay) : _DateToDayOfWeek($iYear, $iMonth, $iDay) $aMonth[Int(($iFirstDOW + $iDay - 2) / 7) + 1][$iDOW - 1] = $iDay Next Return $aMonth EndFunc ;==>_GenerateMonth Func _Iif($fTest, $vTrueVal, $vFalseVal) If $fTest Then Return $vTrueVal Else Return $vFalseVal EndIf EndFunc ;==>_Iifx
    2 points
  2. Looks like 128 characters is a limit in Windows. You'd probably want TraySetOnEvent($TRAY_EVENT_MOUSEOVER, "functionname")
    1 point
  3. Could it be an x86/x64 issue since it works with the batchfile from the CMD prompt? Have you tried running the script in x64? Have you tried running the batch file from AutoIt3? Jos
    1 point
  4. #include <WinAPIShellEx.au3> $s_Path_Downloads = _WinAPI_ShellGetKnownFolderPath($FOLDERID_Downloads) MsgBox(0,"", $s_Path_Downloads)
    1 point
  5. Not sure why you need an object to read a plain text file (even if the extension is .xml) #include <String.au3> #include <Array.au3> Global $sXml = @TAB & "<name>SOME TEXT</name>" & @CRLF & @CRLF & @TAB & "<name>SOME more TEXT</name>" & @CRLF & @CRLF & @TAB & "<name>hello world</name>" Global $sLog = "" ; Option 1 Global $aStringBetween = _StringBetween($sXml, "<name>", "</name>") _ArrayDisplay($aStringBetween, "_StringBetween") ; Option 2, bypassing _StringBetween (which just uses StringRegExp anyway) Global $aRegExp = StringRegExp($sXml, "<name>(.*)</name>", 3) _ArrayDisplay($aRegExp, "StringRegExp") For $iName = 0 To UBound($aRegExp) - 1 $sLog &= $aRegExp[$iName] & @CRLF Next FileWrite(@ScriptDir & "\Log File.log", StringTrimRight($sLog, 2)) Maybe I'm just weird...
    1 point
  6. Here is another options similar to @You suggestion although haven't tested this, you will need to uncomment the RunWait to test. Global $sPSScript = @TempDir & "\PSScript.ps1" Global $aUserInfo[2][2] $aUserInfo[0][0] = 'First.User@google.com' $aUserInfo[0][1] = @TempDir & '\First.User-Sig' $aUserInfo[1][0] = 'Second.User@google.com' $aUserInfo[1][1] = @TempDir & '\Second.User-Sig.htm' For $i = 0 To UBound($aUserInfo) - 1 _PSScript($aUserInfo[$i][0], $aUserInfo[$i][1]) Next Func _PSscript($sEmail, $sFile) Local $hPSScript, $sPSWrite = "" $sPSWrite &= "#Add Exchange 2010/2013 snapin if not already loaded in the PowerShell session" & @CRLF $sPSWrite &= 'if (!(Get-PSSnapin | where {$_.Name -eq "'&'Microsoft.Exchange.Management.PowerShell.E2010"}))' & @CRLF $sPSWrite &= "{" & @CRLF $sPSWrite &= " try" & @CRLF $sPSWrite &= " {" & @CRLF $sPSWrite &= " Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction STOP" & @CRLF $sPSWrite &= " }" & @CRLF $sPSWrite &= " catch" & @CRLF $sPSWrite &= " {" & @CRLF $sPSWrite &= " #Snapin was not loaded" & @CRLF $sPSWrite &= " Write-Warning $_.Exception.Message" & @CRLF $sPSWrite &= " EXIT" & @CRLF $sPSWrite &= " }" & @CRLF $sPSWrite &= " . $env:ExchangeInstallPath\bin\RemoteExchange.ps1" & @CRLF $sPSWrite &= " Connect-ExchangeServer -auto -AllowClobber" & @CRLF $sPSWrite &= "}" & @CRLF $sPSWrite &= "" & @CRLF $sPSWrite &= "$mailboxes = Get-Mailbox -Identity " & $sEmail & @CRLF $sPSWrite &= '$mailboxes| foreach {$file= "' & $sFile & '"; Set-MailboxMessageConfiguration -identity $_.alias -SignatureHtml ' & '"$(Get-Content -Path $file -ReadCount 0)' & '"}' & @CRLF $hPSScript = FileOpen($sPSScript, 10) If @error Then Return FileWrite($sPSScript, $sPSWrite) FileClose($hPSScript) ;~ RunWait(@ComSpec & ' /k PowerShell.exe -ExecutionPolicy Bypass -File "' & $sPSScript & '"') EndFunc
    1 point
  7. I used something like this some time ago, but then I ported it to C because of speed. Hope this helps. #include "..\MPDF_UDF.au3" #include <Array.au3> ;set the properties for the pdf _SetTitle("Demo Table PDF in AutoIt") _SetSubject("Demo Table PDF in AutoIt, with formating") _SetKeywords("pdf, demo, table, AutoIt") _OpenAfter(True);open after generation _SetUnit($PDF_UNIT_CM) _SetPaperSize("CUSTOM", 841.890, 595.276); A4 landscape _SetZoomMode($PDF_ZOOM_FULLPAGE) _SetOrientation($PDF_ORIENTATION_PORTRAIT) _SetLayoutMode($PDF_LAYOUT_CONTINOUS) Global $aCSV = _CSVReadToArray("Test.csv", ',') ;~ Global $aCSV = _CSVReadToArray("Table.txt", ';') ReDim $aCSV[UBound($aCSV, 1)][UBound($aCSV, 2) - 1] _Array2DTransposeAU3($aCSV) ;initialize the pdf _InitPDF(@ScriptDir & "\Example_Table.pdf") ;=== load used font(s) === ;fonts: Garamond _LoadFontTT("_CalibriB", $PDF_FONT_CALIBRI, $PDF_FONT_BOLD) _LoadFontTT("_CalibriI", $PDF_FONT_CALIBRI, $PDF_FONT_ITALIC) _LoadFontTT("_Calibri", $PDF_FONT_CALIBRI) Global $MaxRowsPerPage = 30 _InsertTable($aCSV, 1.5, 1.5, 0, 0, $MaxRowsPerPage, 0x000000, 0x00000) ;~ $sTit = "Sample pdf table generated with AutoIt" ;~ _SetTextRenderingMode(1) ;~ _InsertRenderedText((_GetPageWidth()/_GetUnit())/2, _GetPageHeight()/_GetUnit()-1.5, $sTit, "_CalibriI", 32, 100, $PDF_ALIGN_CENTER, 0xbbbbbb, 0x202020) ;~ _SetTextRenderingMode(0) _ClosePDFFile() Func _InsertTable($aCSV, $iX, $iY, $iW = 0, $iH = 0, $iRowsPerPage = 30, $lTxtColor = 0x000000, $lBorderColor = 0xdddddd) Local $iCols = UBound($aCSV, 1) Local $iPages = Ceiling(UBound($aCSV, 2) / $iRowsPerPage) Local $iRest = Mod(UBound($aCSV, 2), $iRowsPerPage), $iSub = 1 Local $iPgW = Round(_GetPageWidth() / _GetUnit(), 1) Local $iPgH = Round(_GetPageHeight() / _GetUnit(), 1) If $iW = 0 Then $iW = $iPgW - 2 * $iX If $iH = 0 Then $iH = $iPgH - 2 * $iY Local $iColW = $iW / $iCols Local $iRowH = $iH / $iRowsPerPage Local $lRGB For $k = 0 To $iPages - 1 _BeginPage() _SetColourStroke($lBorderColor) ;~ _Draw_Rectangle($iX, $iY, $iW, $iH, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.01) _SetColourStroke(0) If $k = $iPages - 1 Then $iSub = $iRowsPerPage - $iRest + 1 For $i = $k * $iRowsPerPage To ($k + 1) * $iRowsPerPage - $iSub For $j = 0 To $iCols - 1 If $k = 0 Then If $i = 0 Then $lRGB = 0xbbbbbb Else $lRGB = 0xfefefe EndIf Else $lRGB = 0xfefefe EndIf _SetColourStroke($lBorderColor) _Draw_Rectangle($iX + $j * $iColW, $iY + $iH - ($i - $k * $iRowsPerPage + 1) * $iRowH, $iColW, $iRowH, $PDF_STYLE_STROKED, 0, $lRGB, 0.01) _SetColourStroke(0) Local $sText = $aCSV[$j][$i] Local $sLength = Round(_GetTextLength($sText, "_Calibri", 10), 1) $lScale = Ceiling(0.75 * $iColW * 100 / $sLength) _SetColourFill($lTxtColor) ;~ _SetTextHorizontalScaling(80) _DrawText($iX + $j * $iColW + $iColW / 10, $iY + $iH - ($i - $k * $iRowsPerPage + 1) * $iRowH + ($iRowH - 10 / _GetUnit()) / 2, $sText, "_Calibri", 10, $PDF_ALIGN_LEFT, 0) ;~ _SetTextHorizontalScaling(50) _SetColourFill(0) Next Next _EndPage() Next EndFunc ;==>_InsertTable Func _CSVReadToArray($sFile, $sSeparator, $sQuote = '"') Local $hFile = FileOpen($sFile, 0) Local $sText = FileRead($hFile) FileClose($hFile) ;~ $sText = StringReplace($sText, "Intern", "Raumtemp") $sText = StringReplace($sText, "." & @YEAR, "." & "12") Local $aArray If StringRight($sText, 1) = @LF Then $sText = StringTrimRight($sText, 1) If StringRight($sText, 1) = @CR Then $sText = StringTrimRight($sText, 1) If StringInStr($sText, @LF) Then $aArray = StringSplit(StringStripCR($sText), @LF, 2) ElseIf StringInStr($sText, @CR) Then ;; @LF does not exist so split on the @CR $aArray = StringSplit($sText, @CR, 2) Else ;; unable to split the file If StringLen($sText) Then Dim $aArray[1] = [$sText] Else Return SetError(2, 0, 0) EndIf EndIf $aArray = _Array1DTo2D($aArray, $sSeparator) ReDim $aArray[UBound($aArray, 1)][UBound($aArray, 2) - 1] Return $aArray EndFunc ;==>_CSVReadToArray Func _Array1DTo2D($a1D, $sDelim = ";", $iSeveral = 0) ;funkey 17.02.2010 Local $iUbound = UBound($a1D) - 1 Local $iTemp = 0, $iColumn = 0 For $i = 0 To $iUbound If $iSeveral Then $iTemp = UBound(StringRegExp($a1D[$i], $sDelim & "+", 3)) Else $iTemp = UBound(StringSplit($a1D[$i], $sDelim, 3)) EndIf If $iTemp > $iColumn Then $iColumn = $iTemp Next Local $a2D[UBound($a1D)][$iColumn + 1] Local $aTemp For $i = 0 To $iUbound If $iSeveral Then $aTemp = StringSplit(StringRegExpReplace($a1D[$i], $sDelim & "+", $sDelim), $sDelim, 3) Else $aTemp = StringSplit($a1D[$i], $sDelim, 3) EndIf For $j = 0 To UBound($aTemp) - 1 $a2D[$i][$j] = $aTemp[$j] Next Next Return SetExtended($iColumn, $a2D) EndFunc ;==>_Array1DTo2D Func _Array2DTransposeAU3(ByRef $ar_Array) If IsArray($ar_Array) Then Local $ar_ExcelValueTrans[UBound($ar_Array, 2)][UBound($ar_Array, 1)] ;ubound($s_i_ExcelValue,2)-1, ubound($s_i_ExcelValue,1)-1) For $j = 0 To UBound($ar_Array, 2) - 1 For $numb = 0 To UBound($ar_Array, 1) - 1 $ar_ExcelValueTrans[$j][$numb] = $ar_Array[$numb][$j] Next Next $ar_Array = $ar_ExcelValueTrans Else ;MsgBox(0, "", "No Array to transpose") EndIf EndFunc ;==>_Array2DTransposeAU3
    1 point
  8. Should be $aItems = _OL_ItemFind($oO, "*\Sent", $olMail, "[SenderName]='Test' And [Subject]='Testt'", "", "", "Subject", "", 1)
    1 point
×
×
  • Create New...