In Lilo Macro Starbase in Libreoffice, how to change font / add colour / bold in Table head in all cells?

So I have the below code (remove “stop” if you want to test it) , that copy paste tables and charts from LibreCalc in libre writer.

I want to change the Table head (the first row) in order to be formatted in specific font, color, bold type, and size. How I define this?

example calc file (link may expire after 4 Weeks)

A very “bad” written page with explanation for macro code for tables but useful: I will test it… table font properties

Sub LoadingLibraries
 BasicLibraries.LoadLibrary("XrayTool")
End Sub


Sub CopyChartstoWriter
'Definitions of variables

'Calc Dims
Dim oSheet    'Sheet containing the chart
Dim oDoc
'Document Dims
Dim oDocWriter  as object
Dim sUrl$ 
Dim oVCur       as object
Dim oDocument   as object
Dim oDispatcher as object


' ThisComponent.getDrawPages.getByIndex(0).getByIndex(0).Title
' ThisComponent.getDrawPages.getByIndex(0).getByIndex(0).Description
' ThisComponent.getSheets().getbyName( "Graphs_stat" ) .getDrawPage().getByIndex(0).PersistName
' oCharts   = oSheet.getCharts() | oChart = oCharts.getByName("Object 1").EmbeddedObject  
' ThisComponent.getDrawPages.getByIndex(0).getByIndex(0).Name = "aaa"
  
oDoc              = ThisComponent
oSheets           = ThisComponent.getSheets()
oSheet            = oSheets.getbyName( "Graphs_stat" ) 
oDrawPage         = oSheet.getDrawPage()

Const DataRanges  = "B4:D15,B21:F32,B37:E48"
split_DataRanges  =  Split(DataRanges,",")


  cLightBlue      = RGB(180,199,220)
  cLightPurple    = RGB(224,194,205)
  cLightGreen     = RGB(175,208,149)
  cBlue           = RGB(114,159,207)
  cElectricBlue   = RGB(86,10,216)
  cOrange         = RGB(232,162,2)
  cGreen          = RGB(63,175,70)
  cYellow         = RGB(255,255,175) 
 
  cBlack          = RGB(49,64,4 )
  cGray           = RGB(221,221,221 )
  cWhite          = RGB(255,255,255)



	sUrl="private:factory/swriter" 'new writer document
	'sUrl=ConvertToUrl("d:/documents/example.odt") 'or your writer file
	oDocWriter   = StarDesktop.LoadComponentFromUrl(sURL, "_blank", 0, array()) 'open Writer document

	oDispatcher  = createUnoService("com.sun.star.frame.DispatchHelper")
	oDocument    = ThisComponent.CurrentController.Frame
	
	for n = 0 to 100 step 1
	oDispatcher.executeDispatch(oDocument,  ".uno:InsertPara", "", 0, Array())
    next n



	For i = 0 to 2 step 1   
	
	    genNames            = "statChart_" & i
	    oChart              = oDrawPage.getByIndex(i)
	    oTableData          = oSheet.getCellRangeByName( split_DataRanges(i) )
      	DrawObject          = oChart.Title
        Component           = oChart.EmbeddedObject.Component


     	if genNames = DrawObject  then
     		
     		'very essential otherwise calc freeze on error
     		set	mCurSelection = oDoc.currentSelection                       		 	 'Record current selection   
  				on local error goto finished:    				
  				
     	
     	    Component.supportsService("com.sun.star.chart.ChartDocument") 
		    
		    'Transfer Table Data into Writer (copy and then Paste them)
			                 oDoc.CurrentController.select( oTableData )    
			oTableData     = oDoc.CurrentController.getTransferable()
			oVCur          = oDocWriter.CurrentController.getViewCursor     				 'visible cursor
		                     oDocWriter.CurrentController.Select( oVCur )    				 'select visible cursor
		                     
		    ' Optimizing in which position Table Data will be placed 
		                  	 oVCur.JumpToPage( i + 1 , False)   
		                  	 oVCur.goDown(2, False)
		                  	 
		                     oDocWriter.CurrentController.insertTransferable( oTableData )   'Libre internal Ctrl+V
		 				    	oVCur.goUp(2, False)
		
    Dim oCursor      As Object
    Dim oTable       As Object
    Dim oTableBorder As Object

     oCursor           = ThisComponent.CurrentController.ViewCursor	
  
     oStarTable        = com.sun.star.table


      If (isEmpty(oCursor.textTable)) Then
      MsgBox "Cursor is not inside a table."
        
		 Else
 
        	oTable        							    = oCursor.TextTable
       		oTableBorder   						        = oTable.TableBorder
            ' oStarTable.BorderLineStyle 			    = 0    ' Solid 
            
            oTableBorder.IsLeftLineValid 				= True
            oTableBorder.IsRightLineValid				= True
            oTableBorder.IsTopLineValid					= True
            oTableBorder.IsBottomLineValid		   	    = True
            oTableBorder.IsHorizontalLineValid     		= True
            oTableBorder.IsVerticalLineValid       		= True
            
            oTableBorder.LeftLine.Color    			 	= cBlack
            oTableBorder.LeftLine.InnerLineWidth        = 10
            oTableBorder.RightLine.Color  			 	= cBlack
            oTableBorder.RightLine.InnerLineWidth       = 10
            oTableBorder.TopLine.Color  				= cBlack
            oTableBorder.TopLine.InnerLineWidth     	= 10
            oTableBorder.BottomLine.Color  				= cBlack
            oTableBorder.BottomLine.InnerLineWidth      = 10
            oTableBorder.HorizontalLine.Color  			= cBlack
            oTableBorder.HorizontalLine.InnerLineWidth  = 0
            oTableBorder.HorizontalLine.Color  			= cBlack
            oTableBorder.HorizontalLine.InnerLineWidth  = 0
            'oTableBorder.TopLine.OutetLineWidth  		= 111
            'oTableBorder.TopLine.LineDistance  		= 1
            
   

            oTable.TableBorder          				= oTableBorder 
            oTable.HoriOrient           				= com.sun.star.text.HoriOrientation.FULL 
            oTable.CollapsingBorders   		      	    = False
  
    End If
				
		stop
		
		
		
		    'Transfer Chart into Writer (copy and then Paste them)
			    			 oDoc.CurrentController.select( oChart )                           
			 data          = oDoc.CurrentController.getTransferable()                 'Libre internal Ctrl+C
             oVCur         = oDocWriter.CurrentController.getViewCursor         	  'visible cursor
                     
                             oDoc.unlockControllers        					          'very essential on error
            
           
            ' Optimizing in which position charts will be placed 
          					 oVCur.JumpToPage( i+1 , False)       				       'cursor goes to x page
         					 oVCur.goDown(31, False)
         					 
       	    ' Placing text below the Chart
       		oText          = oVCur.text
                             oText.insertString(oVCur, "Some text", False)
                         	 oVCur.goUp(1, False)
		   					 oDocWriter.CurrentController.Select(oVCur)               'select visible cursor
							 oDocWriter.CurrentController.insertTransferable(data)    'Libre internal Ctrl+V
		
		    finished:  				
		    on error goto 0

	     else msgbox "no name found " & genNames
         endif
	  	     
	next i

end sub

I found that there is Autoformat property that can be set.
autoformat

I am trying to apply it.

What is the meaning of " Lilo Macro Starbase?" Perhaps you meant “LibO Macro StarBasic.”

My assumption is here :wink:

Maybe it is the boot loader for the Enterprise’s main computer systems?

Finally, i found that it is given an autoformat property for table objects in Lilo Macro starbase.
So, I deleted a lot of code. You need to create an Autoformat style in librewriter, and then you call this by its name from Macro.

Warning: Dont worry if your autoformatted style is not applied in the table. Save the document, and open it. It may appear then, especially, when the table is copied from calc. I filed a bug for that.

Example given:

    Dim oCursor      As Object
    Dim oTable       As Object

' you must have created a table in librewriter and cursor must be inside the table. 
     oCursor           = ThisComponent.CurrentController.ViewCursor	

      If (isEmpty(oCursor.textTable)) Then
      MsgBox "Cursor is not inside a table."
        
    		 Else
     
        	oTable        							    = oCursor.TextTable
            oTable.autoFormat("APA_BLUE")

      End If

Before hacking the star base of this office suite (or any other office suite) you should learn how to work with office suites in general. Office suites are made for people without knowing anything about star base. Simply use stlyes and templates. Styles and templates are the core functionality of any office suite I’ve seen in the past 30 years. Styles and templates. No macros.

I meant Libo, sorry for my typo. I am transfering a lot of tables from calc to writer. And then I would like to format through macro these tables cause it takes time to do that by hand either using autoformat style menu. Thankfully, Libo starbase has an option to call by its names the autoformat custom styles that you have created in Libre Writer.

Great, you fixed “Lilo” after a lot of hints from different people. Now possibly it will take not that much time to also fix “starbase” to be properly spelled as “StarBasic” (where Basic is the name of the macro language) :wink: . “Base” is one of the components of LibreOffice, which is for databases, and is unrelated to Writer that you tagged your question with.

1 Like

This is about formatting in database tables? Weird. I drop this topic.