Sign in to follow this  
Followers 0
SorryButImaNewbie

[SOLVED]_Excel_RangeWrite How to Bold?

2 posts in this topic

#1 ·  Posted (edited)

Hello

First, I thank you for all the help I received here with Excel UDFs and COM objects in the last few days/week.

I would like to "pimp" my output excel a bit, and for that I would like to write some results Bold.

How do I do that?

I tried a few things but most return errors, or doesn't do a thing seemingly.

My code right now, this does run, but doesn't make the inserted results bold. (by inserted I mean what I write with _Excel_RangeWrite)

_Excel_RangeWrite($ExcelObject, $ExcelObject.Activesheet, "=" & $OSSZEGoszlop & $CellaOlvasoSzamlalo & "*" & String($ArfolyamArray[$DateArrayTimeIndex]) & "", String($sHUFBeszurOszlop) & $CellaOlvasoSzamlalo)
    $ExcelObject.Activesheet.Range(String($sHUFBeszurOszlop) & $CellaOlvasoSzamlalo).Bold = True

Thank you for the help!

Edit: I leave this here, added the bold tag, maybe someone find it usefull

Edited by SorryButImaNewbie

Share this post


Link to post
Share on other sites



#2 ·  Posted

Okey, thanks to Murphy again...

Around 10 minutes after I decided to humiliate myself again, with posting pretty easy questions, I found the solution.

https://www.autoitscript.com/wiki/Excel_UDF#Bold_etc.

$ExcelObject.Activesheet.Range(String($sHUFBeszurOszlop) & $CellaOlvasoSzamlalo).Font.Bold = True

Have to specify that I talk about Font first (.Font) to the COM, in my leman terms.

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  
Followers 0

  • Similar Content

    • SorryButImaNewbie
      [SOLVED] Excel_RangeWrite, no error and MsgBox returns string, yet nothing happens
      By SorryButImaNewbie
      Hello dear forum user!
      I try to make an algorithm that reads values from 2 predefined columns until it founds 2 empty cells in that column, if that happens, It should write a SUM function in to the cell after the last read value. It should do this until it founds 3 empty cells. (I order my excel before this part, so these criteriums should work, and they do while I'm testing).
      Now, I just found a little logical bump on the $SUMsor variable, but I corrected it. Since MsgBox shows me that the readings are good, and the string it should write are also good, and no error flags are detected, I'm not sure what to do next.
      I'm pretty sure it is attached to the right excel, since every other things works, and it also reads in from the excel It should.
      Here is my code snippet:
      ;CONSTRUCTION----------------------------------- ;TO DO: ;Range insert to SULY and HUF, put it in Bold $CellaOlvasoSzamlalo = $CellNumb + 1 Do Local $SUMSor = $CellNumb + 1 ;will be used to determine the "top of the area which it should SUM, CellNumb is the row where the headers/titels were found Local $SULYolvaso1 = _Excel_RangeRead($ExcelObject, Default, $SULYoszlop & $CellaOlvasoSzamlalo) ;Read MsgBox($MB_SYSTEMMODAL, "Értesítés", "$SULYolvaso1:" & $SULYolvaso1 & "") ;Check what is read Local $SULYolvaso2 = _Excel_RangeRead($ExcelObject, Default, $SULYoszlop & $CellaOlvasoSzamlalo + 1) MsgBox($MB_SYSTEMMODAL, "Értesítés", "$SULYolvaso2:" & $SULYolvaso2 & "") Local $SULYolvaso3 = _Excel_RangeRead($ExcelObject, Default, $SULYoszlop & $CellaOlvasoSzamlalo + 2) MsgBox($MB_SYSTEMMODAL, "Értesítés", "$SULYolvaso3:" & $SULYolvaso3 & "") Select Case $SULYolvaso2 = "" and $SULYolvaso3 = "" _Excel_RangeWrite($ExcelObject, $ExcelObject.Activesheet, "=SUM(" & $SULYoszlop & $SUMSor & ":" & $SULYoszlop & $CellaOlvasoSzamlalo & ")") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 1", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Értesítés", "Suly oszlop: " & "=SUM(" & $SULYoszlop & $SUMSor & ":" & $SULYoszlop & $CellaOlvasoSzamlalo & ")") _Excel_RangeWrite($ExcelObject, $ExcelObject.Activesheet, "=SUM(" & $sHUFBeszurOszlop & $SUMSor & ":" & $sHUFBeszurOszlop & $CellaOlvasoSzamlalo & ")") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 1", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Értesítés", "Suly oszlop: " & "=SUM(" & $sHUFBeszurOszlop & $SUMSor & ":" & $sHUFBeszurOszlop & $CellaOlvasoSzamlalo & ")") $SUMSor = $CellaOlvasoSzamlalo + 3 EndSelect $CellaOlvasoSzamlalo = $CellaOlvasoSzamlalo + 1 Until $SULYolvaso1 = "" and $SULYolvaso2 = "" and $SULYolvaso3 = "" ;$ExcelObject.Activesheet.Range(String($sHUFBeszurOszlop) & $CellaOlvasoSzamlalo).Font.Bold = True ;----------------------------------------------- Also I would like to write it in bold, I have en example commented out at the end, but is there a way with range insert to insert in Bold?
      Thank you for your help and insight! and have a nice day
    • AndyS01
      How to set Menu text items to bold, colored
      By AndyS01
      I want to create a menu item and set the text to bold and the color to red, but I cannot find a UDF to do this.
      I want to make calls something like this:
      _GUICtrlMenu_SetItemFont($hMenu, $iIndex, $oFont) _GUICtrlMenu_SetItemColor($hMenu, $iIndex, $iColor) I want to make them UDFs so I don't have to add lots of code to the script that calls them.  I've seen some on-line content, but what I found needed add too much code to support it.
      Here is my test code:
      #include <GuiMenu.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <FontConstants.au3> Opt('MustDeclareVars', 1) Opt("GUICloseOnESC", 1) ; 1 = ESC closes GUI Opt("GUIOnEventMode", 1) ; 1 = OnEvent mode OnAutoItExitRegister("ExitStageLeft") ; The $aMenuItems[] array holds information about each menu item. ; Each element holds items that are separated by a '|'. When each item is split ; into an array, the resulting array has this info: ; [0] = The item's Menu ID (from the '_GUICtrlMenu_AddMenuItem' function call ; [1] = The item's Font Number (0 = no special font; 1 = font #1, etc.)) ; [2] = The Item's Text Color value (0 = no special color, else: $COLOR_RED, $COLOR_BLUE, etc.) ; [3] = The item's menu index value ; [4] = The Item's Handler name Global Enum $__MI_ID, $__MI_FONTNUM, $__MI_COLOR, $__MI_NDX, $__MI_HANDLER, $__MI_CNT Global $aMenuItems Global $iMemo, $aFonts[2] Example() exit Func Example() Local $hGUI, $hFile, $hMain createFonts() $hGUI = GUICreate("Menu", 400, 300); Create the main GUI $aMenuItems = StringSplit("", "") ; Initialize the $aMenuItems[] array $hFile = _GUICtrlMenu_CreateMenu(); Create the File menu _myGUICtrlMenu_AddMenuItem($hFile, "&New", "handle_munuitem_New") _myGUICtrlMenu_AddMenuItem($hFile, "&Open", "handle_munuitem_Open") _myGUICtrlMenu_AddMenuItem($hFile, "") _myGUICtrlMenu_AddMenuItem($hFile, "I want this to be bold 12pt Red text", "handle_MenuItem_test", 0xFF0000, 1) _myGUICtrlMenu_AddMenuItem($hFile, "") _myGUICtrlMenu_AddMenuItem($hFile, "E&xit", "handle_munuitem_Exit") $hMain = _GUICtrlMenu_CreateMenu(); Create the Main menu _GUICtrlMenu_InsertMenuItem($hMain, 0, "&File", 0, $hFile) _GUICtrlMenu_SetMenu($hGUI, $hMain); Set the window menu ; Display the 'menu items' info array For $ndx = 0 To UBound($aMenuItems) - 1 ConsoleWrite("+++: [" & $ndx & "] = " & $aMenuItems[$ndx] & @CRLF) Next $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 276, 0); Create the memo control GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE, "ExitStageLeft") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") MemoWrite("Click on the File menu and " & @crlf & "select one of the menu items.") ; Loop until the user exits. while(1) sleep(100) WEnd EndFunc ;==>Example ; Add a menu item, then add its info to the $aMenuItems[] array Func _myGUICtrlMenu_AddMenuItem($hMenu, $sTitle = "", $sHandler = "", $iColor = 0, $iFontnum = 0) Local $iIndex, $iCmdID, $ar[1], $fontnum, $str, $color $iIndex = _GUICtrlMenu_GetItemCount($hMenu) If ($sTitle <> "") Then $iCmdID = 1000 + $iIndex $iIndex = _GUICtrlMenu_AddMenuItem($hMenu, $sTitle, $iCmdID) If ($sHandler <> "") Then ; Create then populate a MenuItem info array ReDim $ar[$__MI_CNT] $ar[$__MI_ID] = $iCmdID $ar[$__MI_FONTNUM] = $iFontnum $ar[$__MI_COLOR] = $iColor $ar[$__MI_NDX] = $iIndex $ar[$__MI_HANDLER] = $sHandler $str = _ArrayToString($ar, "|", 0) _ArrayAdd($aMenuItems, $str) $aMenuItems[0] = UBound($aMenuItems) - 1 If ($iFontnum > 0) And ($iFontnum <= UBound($aFonts)) Then _GUICtrlMenu_SetItemFont($hMenu, $iIndex, $aFonts[$iFontnum-1]) EndIf If ($iColor <> 0) Then _GUICtrlMenu_SetItemColor($hMenu, $iIndex, $iColor) EndIf GUICtrlSetOnEvent($iCmdID, $sHandler) EndIf Else _GUICtrlMenu_AddMenuItem($hMenu, "") ; Add just a horizontal bar EndIf EndFunc ;==>_myGUICtrlMenu_AddMenuItem ; Handle menu commands Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $ilParam Local $id, $parts, $handler $id = _WinAPI_LoWord($iwParam) ; See if this ID is in the list of items in the $aMenuItems[] array For $ndx = 1 To UBound($aMenuItems) - 1 $parts = StringSplit($aMenuItems[$ndx], "|", 2) If ($id = $parts[$__MI_ID]) Then MemoWrite("$id = " & $id) ; It is, so call the handler associated with it $handler = $parts[$__MI_HANDLER] Call($handler) ; Call the handler ExitLoop EndIf Next Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func handle_munuitem_New() MemoWrite("handle_munuitem_New") EndFunc ;==>handle_munuitem_New Func handle_munuitem_Open() MemoWrite("handle_munuitem_Open") EndFunc ;==>handle_munuitem_Open Func handle_MenuItem_test() MemoWrite("handle_MenuItem_test") EndFunc ;==>handle_MenuItem_test Func handle_munuitem_Exit() MemoWrite("handle_munuitem_Exit") EndFunc ;==>handle_munuitem_Exit Func ExitStageLeft() Exit (1) EndFunc ;==>ExitStageLeft ; Write message to memo Func MemoWrite($sMessage) Local Static $cnt = 0 $cnt += 1 GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) ConsoleWrite("+++: " & StringFormat("%2d: %s", $cnt, $sMessage) & @CRLF) EndFunc ;==>MemoWrite Func createFonts() $aFonts[0] = _WinAPI_CreateFont(14, 0, 0, 0, $FW_NORMAL, _ False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, _ $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, "MS Sans Serif") $aFonts[1] = _WinAPI_CreateFont(14, 0, 0, 0, $FW_BOLD) EndFunc ;==>createFonts Here is a skeleton of the UDF functions:
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; _GUICtrlMenu_SetItemColor() - Set the color for the text in a menu item. ; ; PARAMS: $hMenu - The Handle of the menu the item's attached to ; $iIndex - The menu item number ; $iColor - The text color ; ; RETURNS: <nothing> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func _GUICtrlMenu_SetItemColor($hMenu, $iIndex, $iColor) #forceref $hMenu, $iIndex, $iColor ConsoleWrite("+++: _GUICtrlMenu_SetItemColor(" & $hMenu & ", " & $iIndex & ", " & Hex($iColor) & ") entered" & @CRLF) ; TBD ... TBD ... TBD ... EndFunc ;==>_GUICtrlMenu_SetItemColor ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; _GUICtrlMenu_SetItemFont() - Set the font for the text in a menu item. ; ; PARAMS: $hMenu - The Handle of the menu the item's attached to ; $iIndex - The menu item number ; $iColor - The font object (as created by the _WinAPI_CreateFont() function). ; ; RETURNS: <nothing> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func _GUICtrlMenu_SetItemFont($hMenu, $iIndex, $oFont) #forceref $hMenu, $iIndex, $fFont ConsoleWrite("+++: _GUICtrlMenu_SetItemFont(" & $hMenu & ", " & $iIndex & ", $oFont) entered" & @CRLF) ; TBD ... TBD ... TBD ... EndFunc ;==>_GUICtrlMenu_SetItemFont  
    • arts
      Using _GUICtrlMonthCal_SetDayState
      By arts
      I'm trying to make bold some days of a calendar. I get those days from a SQLite database. Using the _GUICtrlMonthCal_SetDayState function I almost got it working. Please look at the following ugly code and help me to understand why when the variable $finalX is calculated by the script it doesn't work (no bolding days) but, if I declare the value of the same variable manually, it works... I'm sure I'm doing something stupid but can't see it.
       
      [...] ;---- BUSY DAYS if _SQLite_GetTable2d(-1,'select A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, ID from mydatabase where DEADLINE like "%' & "-" & $tTeste & "-" & '%" ORDER BY 1 D, C;', $arows, $irows, $icols) = $SQLITE_OK Then _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($lvList)) Local $final[ubound($arows)] Local $finalX = "" Local $tempDay = "" Local $val_hex[ubound($arows)] Local $val_pre = "" for $1 = 1 to ubound($arows) - 1 _GUICtrlListView_AddItem($lvList, $arows[$1][0]) for $2 = 1 to ubound($arows,2) - 1 _GUICtrlListView_AddsubItem($lvList,$1-1, $arows[$1][$2], $2) next $tempDay = StringLeft(($arows[$1][3]), 2) $val_pre = Number($tempDay); + 0 ConsoleWrite("val_pre: " & $val_pre & @CRLF) $val_hex[$1] = "BitShift(0x0001,-" & "(" & $val_pre & "-1)" & ")" ConsoleWrite("val_hex[$1]: " & $val_hex[$1] & @CRLF) next ConsoleWrite("===========================" & @CRLF) $final = _ArrayUnique($val_hex) $finalX = _ArrayToString($final, " + ", 1) $finalX = StringTrimLeft($finalX, 3); <<------ COMPUTED $finalX doesn't work ConsoleWrite("FinalX:"&$finalX & @CRLF) ;------>> When I declare the same value as the computed above, it WORKS.. --->> $finalX = BitShift(0x0001,-(28-1)) + BitShift(0x0001,-(29-1)) + BitShift(0x0001,-(30-1)) + BitShift(0x0001,-(15-1)) + BitShift(0x0001,-(7-1)) + BitShift(0x0001,-(24-1)) + BitShift(0x0001,-(1-1)) + BitShift(0x0001,-(11-1)) + BitShift(0x0001,-(2-1)) EndIf ;--------------- Local $aMasks[_GUICtrlMonthCal_GetMonthRangeSpan($idMonthCal, True)] $aMasks[1] = $finalX; <<<-------- bold days _GUICtrlMonthCal_SetDayState($idMonthCal, $aMasks) GUICtrlSetState($tabCalendar, $GUI_SHOW) EndFunc ;==>BusyDays  
    • lucamad
      SciTE Editor problem
      By lucamad
      Hi guys

      A little but very annoying problem with the new version (2.28) of SciTE editor included in last AutoIT installation...

      I have a problem with syntax language check and view in the editor. See the attch pic...
      No blue-bolded text for some autoit words and no _* functions in the help context menu.

      I have win xp sp3. What's wrong??
      THX