Seite 1 von 1

LibXL und Zellen umranden

Verfasst: Mo, 27. Nov 2017 16:28
von Rudolf
Hallo,
wie kann ich einer Zelle ein bestimmtes Format zuordenen ? Ich möchte eine Zelle dick unterstreichen, also setBorderBottom(BORDERSTYLE_THICK). Aber wie addressiere ich die Zelle ?
Grüße
Rudolf

Re: LibXL und Zellen umranden

Verfasst: Mo, 27. Nov 2017 17:07
von brandelh
schau dir mal meine Klasse an ... ansonsten 0,0 ist A1 ... wenn ich mich richtig erinnere

Re: LibXL und Zellen umranden

Verfasst: Mo, 27. Nov 2017 17:20
von Rudolf
Hallo Hubert,
in der Klasse sehe ich auch nicht wo die Position angegeben wird.
Grüße
Rudolf


METHOD xlFormat:FormatSetBorderBottom( nStyle )
LOCAL uRet := nil
DEFAULT nStyle TO 0
uRet := FpQCall( {'LibXL','xlFormatSetBorderBottomA'},'__vo__sl__sl',::hHandle,nStyle)
RETURN uRet

Re: LibXL und Zellen umranden

Verfasst: Mo, 27. Nov 2017 17:33
von Rudolf
Hallo,
wenn ich das Format vorher mit

oFormatLine := oBook:BookaddFormat()
oFormatLine:FormatsetBorderBottom(BORDERSTYLE_THICK)

defniere und dann z.B.

for zz := 1 to 27
oSheet:SheetsetCol(nLine,zz-1,,oFormatLine)
next zz

formatiere habe ich keinen dicken Strich unten und die Zelle hat die Breite 0 bekommen :-(
Grüße
Rudolf

Re: LibXL und Zellen umranden

Verfasst: Mo, 27. Nov 2017 18:33
von Werner_Bayern

Code: Alles auswählen

Excel_SheetWriteNum(nSheet, i + nIndex, i2, val(substr(aDaten[i, i2 + 1], 7)), Excel_SetNumFormat(nFormatHandleDate, NUMFORMAT_DATE))
Einfach aus meinem Code rausgenommen. Du musst das Format beim Schreiben mitgeben.

Re: LibXL und Zellen umranden

Verfasst: Mo, 27. Nov 2017 18:41
von Rudolf
Hallo Werner,
ich muss in eine Vorlage schreiben und daher das Format nachträglich ändern. Es muss doch einen Möglichkeit geben Zellen zu formatieren ohne dass man was reinschreibt.
Grüße
Rudolf

Re: LibXL und Zellen umranden

Verfasst: Mo, 27. Nov 2017 20:52
von Werner_Bayern
Servus Rudolf,

m. W. n. nicht. Auch die Beispiele schreiben immer gleichzeitig den Wert.

Lies halt den Wert aus und schreib ihn mit dem neuen Format rein.

Re: LibXL und Zellen umranden

Verfasst: Di, 28. Nov 2017 7:38
von Rudolf
Hallo Werner,
das geht nur bei einfachen Formatierungen z.B. fürs Zahlenformat, aber nicht wenn verschiedene Dinge wie Farbe oder Font anders sind. Ich verliere auch Formatierungen wenn ich in eine Zelle schreibe. Mal schauen ob ich vom Support Infos bekomme.
Grüße
Rudolf

Re: LibXL und Zellen umranden

Verfasst: Di, 28. Nov 2017 8:04
von brandelh
Rudolf hat geschrieben: Mo, 27. Nov 2017 17:33 Hallo,
wenn ich das Format vorher mit

oFormatLine := oBook:BookaddFormat()
oFormatLine:FormatsetBorderBottom(BORDERSTYLE_THICK)

defniere und dann z.B.

for zz := 1 to 27
oSheet:SheetsetCol(nLine,zz-1,,oFormatLine)
next zz

formatiere habe ich keinen dicken Strich unten und die Zelle hat die Breite 0 bekommen :-(
Grüße
Rudolf
du darfst in deinem Beispiel den 3. Parameter (Spaltenbreite) nicht einfach leer lassen, leer ist soviel wie 0
Richtig ist, dass man entweder ein neues Format anlegt oder das der Zelle abfragt, ändert und wieder setzt.

Re: LibXL und Zellen umranden

Verfasst: Di, 28. Nov 2017 8:45
von Rudolf
Hallo Hubert,
das habe ich schon korrigiert, muss also vorher die Breite auslesen und dann wieder angeben. Aber die Zelle wird trotzdem nicht unten dick dargestellt. Irgend etwas fehlt noch.
Grüße
Rudolf

Re: LibXL und Zellen umranden

Verfasst: Di, 28. Nov 2017 9:47
von brandelh
So wie ich das sehe scheint es keinen Befehl zu geben, der einen normalen Bereich (Excel Range) formatiert.
Die Spalte kann nach unten ja sehr lange sein !
Vermutlich muss man Zelle für Zelle auslesen und links oben, links, links unten, unten, rechts unten, rechts, rechts oben und oben einzeln setzen.

Am Besten mal den support mit dem gewünschten Beispiel fragen, wie man das hin bekommt.

Re: LibXL und Zellen umranden

Verfasst: Di, 28. Nov 2017 9:53
von brandelh
so sähe das wohl in Excel Macro Sprache aus:

Code: Alles auswählen

Sub Makro1()
'
' Makro1 Makro
'

'
    Range("B2").Select
    ActiveCell.FormulaR1C1 = "Test"
    Range("C2").Select
    ActiveCell.FormulaR1C1 = "or"
    Range("B5").Select
    ActiveCell.FormulaR1C1 = "lu"
    Range("C5").Select
    ActiveCell.FormulaR1C1 = "ru"
    Range("B2:C5").Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone
    Selection.Borders(xlEdgeTop).LineStyle = xlNone
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    Selection.Borders(xlEdgeRight).LineStyle = xlNone
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
    Range("H12").Select
End Sub

Re: LibXL und Zellen umranden

Verfasst: Di, 28. Nov 2017 9:58
von Rudolf
Hallo Hubert,
danke für die Infos, wäre eigenartig wenn das nicht funktionieren würde, mal schauen was der Support sagt.
Grüße
Rudolf

LibXL LIBRARY - commands

Verfasst: Di, 28. Nov 2017 21:16
von engindenizoglu
I started new working with this library.
LIBXL is great library for preparing EXCEL sheets but the samples/documantation for xbase are too much insufficient.

See below a sample:
How can i change the color a certain cell ?
How can i format a cell like 999,999.99 for numbers ?
Does anyone have sample prgs related LIBXL for XBASE++ ?

---------------------------------------------------------------------------------------------------------------------------------------------------------

Code: Alles auswählen

   cFile := "PERSON"                //   EXCEL DOSYA ADI 
   oBook := xlCreateBook(cName,cKey)
    oSheet := oBook:BookAddSheet("SAYFA-1" )            
    now := 1        
    oSheet:SheetWriteStr(now,1,"VORNAME" )           
    oSheet:SheetWriteStr(now,2,"GEHALT " )       ----->   [b]how can i change the cell color[/b]
    oSheet:SheetWriteStr(now,3,"Fiili Çalışma Saat    " )               
     now=now+1
     SAYI=456366.88
     oSheet:SheetWriteNum( now, 8, SAYI)                        ---------->   [b]HOW CAN WE FORMAT THE nr  like 999,999.99  [/b]
---------------------------------------------------------------------------------------------

Re: LibXL und Zellen umranden

Verfasst: Mi, 29. Nov 2017 8:37
von brandelh
Hi,

I wrote the Xbase++ Class HBLibXL, and I think this ist the code from my example:

Code: Alles auswählen

oSheet:SheetWriteStr(now,2,"GEHALT " )       ----->   [b]how can i change the cell color[/b]
oSheet:SheetWriteNum( now, 8, SAYI)     ---------->   [b]HOW CAN WE FORMAT THE nr  like 999,999.99  [/b]
In the example PRGs are examples for color and numeric or date formates.
First you should get the newest version of my class, and look here for more examples:

:arrow: viewtopic.php?f=16&t=7610&p=107692

The first step is to get a format object, with one of 2 ways:
1. oAlign := oBook:BookAddFormat() to add a new format to the book, you can set and access through oAline in this example, or
2. oFormat := oSheet:SheetCellFormat(2,0) to read the active format of a cell, change it an use it !

In Test3.PRG I do use formats directly to write the right format per data type

Code: Alles auswählen

      for k := 1 to nDataCols
         oAlign  := oBook:BookAddFormat()
         oHeader := oBook:BookAddFormat()
         oHeader:FormatSetNumFormat( NUMFORMAT_TEXT )
         oHeader:FormatSetFont( oFont )
         oHeader:FormatSetFillPattern( FILLPATTERN_SOLID )
         oHeader:FormatSetPatternForegroundColor( COLOR_LIGHTGREEN )

         xValue := aData[1,k]
         do case
         case ValType( xValue ) == "C"
            oAlign:FormatSetAlignH( ALIGNH_LEFT )
            oHeader:FormatSetAlignH( ALIGNH_LEFT )
         case ValType( xValue ) == "N"
            oAlign:FormatSetAlignH( ALIGNH_RIGHT )
//          oAlign:FormatSetNumFormat( NUMFORMAT_NUMBER_SEP_D2 )
            oAlign:FormatSetNumFormat( oBook:BookAddCustomNumFormat( "###,###,###.000" ) )
            oHeader:FormatSetAlignH( ALIGNH_RIGHT )
         case ValType( xValue ) == "D"
            oAlign:FormatSetAlignH( ALIGNH_CENTER )
            oAlign:FormatSetNumFormat( NUMFORMAT_DATE )
            oHeader:FormatSetAlignH( ALIGNH_CENTER )
         endcase
         oSheet:SheetSetCol( k-1, k-1, aWidth[k], oAlign )
         oSheet:SheetWriteStr( nRow, k-1, aHeader[k], oHeader )
         oAlign  := NIL
         oHeader := NIL
      next

Re: LibXL und Zellen umranden

Verfasst: Do, 30. Nov 2017 8:09
von Rudolf
Hallo,
habe die Antwort vom Support, so müsste es klappen:

You should copy existing formats and add new properties, for example:

Format* oldFormat = sheet->cellFormat(row, col); // get existing format
Format* newFormat = book->addFormat(oldFormat); // copy of oldFormat
newFormat->setBorderBottom(BORDERSTYLE_THICK); // add a new property
sheet->setCellFormat(row, col, newFormat); // set a new format

Grüße
Rudolf

Re: LibXL und Zellen umranden

Verfasst: Do, 30. Nov 2017 8:24
von brandelh
Aber eben nur je Zelle, damit braucht man für einen Bereich eine Schleife ...

Re: LibXL und Zellen umranden

Verfasst: Do, 30. Nov 2017 8:25
von Rudolf
Hallo,
so löse ich jetzt mein Problem:

Grüße
Rudolf

Code: Alles auswählen

for zz := 1 to 28
       oOld := oSheet:SheetCellFormat(nStart+nLine,zz-1)
      oNew := oBook:BookaddFormat(oOld)
       oNew:FormatsetBorderBottom(BORDERSTYLE_THICK)
        oSheet:SheetSetCellFormat(nStart+nLine,zz-1,oNew)
  next zz

Re: LibXL - SELECTING FONT

Verfasst: Fr, 01. Dez 2017 20:52
von engindenizoglu
How is it possible to switch to BOLD font ?

-------------------------------------------------------------------------------

Code: Alles auswählen

oFont1:=oBook:BookAddFont() // reuse object is OK.
oFont1:FontSetName("Tahoma")
oFont1:FontSetSize(11)
-------------------------------------------------------------------------------

Here below it saves the excel file , but with which function can i open the same excel file ?

-----------------------------------------------------------------------------

Code: Alles auswählen

 oBook:BookSave( cFile )         /*    rec.     */  
 oBook:destroy()
-----------------------------------------------------------------------------

Re: LibXL - SELECTING FONT

Verfasst: Sa, 02. Dez 2017 3:14
von AUGE_OHR
engindenizoglu hat geschrieben: Fr, 01. Dez 2017 20:52 Here below it saves the excel file , but with which function can i open the same excel file ?
-----------------------------------------------------------------------------

Code: Alles auswählen

 oBook:BookSave( cFile )         /*    rec.     */  
 oBook:destroy()
-----------------------------------------------------------------------------
this is for Excel activeX but here we talk about LibXL which work without Excel.

about BOLD : you have to find out how your OS() Version name it. in German Version it is called "Fett"

Re: LibXL und Zellen umranden

Verfasst: Sa, 02. Dez 2017 15:01
von brandelh
Hi,

to get a Idea what it can do you should read the documentation from here:

http://www.libxl.com/font.html

or look through the methods of the HBLibXL Class ...

there is a function to set bold:

Code: Alles auswählen

bool bold() const
Returns whether the font is bold.
void setBold(bool bold = true)
Turns on/off the bold font.
so add this line to your examle:

oFont1:FontSetBold(.t.)

Re: LibXL - SELECTING FONT

Verfasst: Sa, 02. Dez 2017 15:04
von brandelh
AUGE_OHR hat geschrieben: Sa, 02. Dez 2017 3:14
engindenizoglu hat geschrieben: Fr, 01. Dez 2017 20:52 Here below it saves the excel file , but with which function can i open the same excel file ?
-----------------------------------------------------------------------------

Code: Alles auswählen

 oBook:BookSave( cFile )         /*    rec.     */  
 oBook:destroy()
-----------------------------------------------------------------------------
this is for Excel activeX but here we talk about LibXL which work without Excel.
about BOLD : you have to find out how your OS() Version name it. in German Version it is called "Fett"
The code abouve looks like my HBLibXL Class and not ActiveX, so no OS() bold needed ;-)

Re: LibXL und Zellen umranden

Verfasst: Sa, 02. Dez 2017 21:01
von engindenizoglu
Bold worked ; Thank u :)


So how can i open an excel file ?

With Activex or LIBXL.

Re: LibXL und Zellen umranden

Verfasst: Mo, 04. Dez 2017 8:19
von brandelh
With ActiveX, there is an example to open a DBF and save it as as XLS in the samples folder of xbase++

:arrow: ..\XPPW32\source\samples\activex\msexcel

in LibXL use the method:

Code: Alles auswählen

Book class reference
public void load(string filename)
Loads an entire file into memory.
:arrow: xlBook:BookLoad( cFilename )