OBS/Makros und Scripting/Anwendungsbereiche/OfficeUnterstuetzung: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
KKeine Bearbeitungszusammenfassung |
KKeine Bearbeitungszusammenfassung |
||
Zeile 1: | Zeile 1: | ||
{{Makros und Scripting}} | {{Makros und Scripting}} | ||
=Office Unterstützung= | |||
Hierüber können Officedokumente angesteuert werden. | |||
{{Hinweis|Libre oder MS-Office muss auf dem PC vorhanden sein}} | {{Hinweis|Libre oder MS-Office muss auf dem PC vorhanden sein}} | ||
==Scripting== | |||
Excel | Excel | ||
Zeile 18: | Zeile 21: | ||
Office_Document_To_PDF( aMacro.cString, aMacro.cString); | Office_Document_To_PDF( aMacro.cString, aMacro.cString); | ||
Office_Document_To_Printer( aMacro.cString, aMacro.cString); | Office_Document_To_Printer( aMacro.cString, aMacro.cString); | ||
==Beispiele== | |||
===Dauermietrechnung=== | |||
{{Hinweis|Platzhalter müssen immer ganz formatiert werden, also zum Beispiel Fett, Unterstrichen, etc. (vgl. VGSUMME)}} | |||
[[Image:Scripting_Office_Beispiel1.png]] | |||
===Beispielscript=== | |||
<source lang="delphi"> | |||
//----------------------------------------------------------------------------- | |||
// Unit Name: Dokumenen Manager Verträge | |||
// Author: Jörn Böhrer | |||
// Date: 01.09.2020 | |||
// Purpose: | |||
// History: | |||
//----------------------------------------------------------------------------- | |||
Const lWholeWord = True; | |||
lClearLine = True; | |||
//------------------------------------------------------------------------------ | |||
// Procedure: RTF Replace für Internen Text | |||
// Author: jr | |||
// Date: 29-Jul-2020 | |||
// Comment: | |||
//------------------------------------------------------------------------------ | |||
function RTF_Replace(oRTF:TTextRichEdit; cVgNr:String):String; | |||
begin | |||
ReplaceRTFAll(oRTF, '1234', '67789', lWholeWord , not lClearLine); | |||
Result := oRTF.Caption; | |||
end; | |||
//------------------------------------------------------------------------------ | |||
// Procedure: RTF Replace für Internen Text | |||
// Author: jr | |||
// Date: 29-Jul-2020 | |||
// Comment: | |||
//------------------------------------------------------------------------------ | |||
procedure Kunden_Daten(oDoku:TWordDoku; cPsNr:String); | |||
var cBuffer : String; | |||
cSQL : String; | |||
qPerson : TxFQuery; | |||
begin | |||
cSQL := 'SELECT * FROM PERSSTA'+ | |||
' WHERE ps_nr = '+DB_SqlVal(cPsNr); | |||
if (DB_SOpen(oDB, cSQL, qPerson)) then begin | |||
if (not(empty(qPerson.A2C('ps_vorname')))) then begin | |||
cBuffer := qPerson.A2C('ps_vorname') + ' '; | |||
end; | |||
if (not(empty(qPerson.A2C('ps_name')))) then begin | |||
cBuffer := cBuffer + qPerson.A2C('ps_name'); | |||
end; | |||
oDoku.Replace('VKNAME', cBuffer); | |||
cBuffer := qPerson.A2C('ps_zusatz1'); | |||
AddEToken(cBuffer, qPerson.A2C('ps_zusatz2'),CRLF); | |||
oDoku.Replace('VKZUSATZ', cBuffer); | |||
if (not Empty(qPerson.A2C('ps_postf'))) then begin | |||
oDoku.Replace('VKSTRASSE', 'Postfach: ' + qPerson.A2C('ps_postf')); | |||
end else begin | |||
oDoku.Replace('VKSTRASSE', qPerson.A2C('ps_strasse')); | |||
end; | |||
oDoku.Replace('VKLK', qPerson.A2C('ps_lk')); | |||
oDoku.Replace('VKPLZ', qPerson.A2C('ps_plz')); | |||
oDoku.Replace('VKORT', qPerson.A2C('ps_ort')); | |||
end; | |||
DB_Close(qPerson); | |||
end; | |||
//------------------------------------------------------------------------------ | |||
// Procedure: Word/Libre Replace für Dokumente | |||
// Author: jr | |||
// Date: 29-Jul-2020 | |||
// Comment: | |||
//------------------------------------------------------------------------------ | |||
function Office_Replace(oDoku:TWordDoku):String; | |||
var cSQL : String; | |||
qVertrag : TxFQuery; | |||
cBuffer : String; | |||
nSatz : Double; | |||
nBetrag : Double; | |||
begin | |||
if (oDoku.cDmsTyp = DMS_TYP_VERTRAG) then begin | |||
cSQL := 'SELECT * FROM VERTRAG'+ | |||
' WHERE v_nr = '+DB_SqlVal(oDoku.cVgNr); | |||
if (DB_SOpen(oDB, cSQL, qVertrag)) then begin | |||
//Nur Notwendig bei mehreren Mandanten | |||
//oDoku.SetManNr('001'); | |||
oDoku.Replace('VNUMMER', qVertrag.A2C('v_nr')); | |||
oDoku.Replace('VNUMMER', qVertrag.A2C('v_nr')); | |||
oDoku.Replace('VKNR' , qVertrag.A2C('v_knr')); | |||
oDoku.Replace('SB' , oOBS.cSachbearbName); | |||
oDoku.Replace('DATUM' , DToC(Date())); | |||
//------------------------------------------------------------------ | |||
if (not Empty(qVertrag.A2C('v_knr'))) then begin | |||
Kunden_Daten(oDoku, qVertrag.A2C('v_knr')); | |||
end; | |||
if (qVertrag.A2I('v_zahlzeit') = 1) then begin | |||
cBuffer := 'Monatspauschale'; | |||
end else if (qVertrag.A2I('v_zahlzeit') = 2) then begin | |||
cBuffer := 'Vierteljahrespauschale'; | |||
end else if (qVertrag.A2I('v_zahlzeit') = 3) then begin | |||
cBuffer := 'Halbjahrespauschale'; | |||
end else if (qVertrag.A2I('v_zahlzeit') = 4) then begin | |||
cBuffer := 'Jahrespauschale'; | |||
end else begin | |||
cBuffer := 'Keine Angabe'; | |||
end; | |||
oDoku.Replace('VZAHLZEIT' , cBuffer); | |||
oDoku.Replace('VDATUM' , qVertrag.A2C('v_datum')); | |||
oDoku.Replace('VPAUSCH' , qVertrag.A2C('v_pauschal')); | |||
//------------------------------------------------------------------ | |||
oDoku.Replace('FELD01' , oDoku.cFeld01); | |||
oDoku.Replace('FELD02' , oDoku.cFeld02); | |||
oDoku.Replace('FELD03' , oDoku.cFeld03); | |||
StdUStSatzDB(oDB, nSatz,''); | |||
nBetrag := Roundy(qVertrag.A2F('v_pauschal') * nSatz / 100,2); | |||
oDoku.Replace('VMWST' , axStr(nSatz)); | |||
oDoku.Replace('VMWSTBET' , axStr(nBetrag)); | |||
oDoku.ReplaceRAW('VGSUMME' , axStr(nBetrag+qVertrag.A2F('v_pauschal'))); | |||
end; | |||
DB_Close(qVertrag); | |||
end; | |||
Result := 'OK'; | |||
end; | |||
//------------------------------------------------------------------------------ | |||
// Procedure: Word/Libre Replace für Dokumente | |||
// Author: jr | |||
// Date: 29-Jul-2020 | |||
// Comment: | |||
//------------------------------------------------------------------------------ | |||
function IsAllowed(cVgNr:String; cPsNr:String; cDMSTyp:String):Boolean; | |||
begin | |||
Result := True; | |||
end; | |||
//------------------------------------------------------------------------------ | |||
</source> |
Aktuelle Version vom 18. September 2020, 10:32 Uhr
Office Unterstützung
Hierüber können Officedokumente angesteuert werden.
HINWEIS: Libre oder MS-Office muss auf dem PC vorhanden sein
Scripting
Excel
EXCEL_XLSX_Replace( aMacro.cString, TWordDoku(aMacro.oObj)); StartLibreExcel(aMacro.cString,TWordDoku(aMacro.oObj)); StartMicrosoftExcel(aMacro.cString,TWordDoku(aMacro.oObj));
Word
Office_DOCX_Replace(aMacro.oObj, aMacro.cString, aMacro.cString); Office_XLSX_Replace(aMacro.oObj, aMacro.cString, aMacro.cString); Office_CreateDocument(TWordDoku(aMacro.oObj), aMacro.cString, aMacro.cString, aMacro.lBoolean); Office_CreateDocument(TWordDoku(aMacro.oObj), aMacro.cString, aMacro.cString, aMacro.lBoolean);
Office_OpenDocument(aTmp, aMacro.cString, aMacro.cString, aMacro.lBoolean); Office_Document_To_PDF( aMacro.cString, aMacro.cString); Office_Document_To_Printer( aMacro.cString, aMacro.cString);
Beispiele
Dauermietrechnung
HINWEIS: Platzhalter müssen immer ganz formatiert werden, also zum Beispiel Fett, Unterstrichen, etc. (vgl. VGSUMME)
Beispielscript
//-----------------------------------------------------------------------------
// Unit Name: Dokumenen Manager Verträge
// Author: Jörn Böhrer
// Date: 01.09.2020
// Purpose:
// History:
//-----------------------------------------------------------------------------
Const lWholeWord = True;
lClearLine = True;
//------------------------------------------------------------------------------
// Procedure: RTF Replace für Internen Text
// Author: jr
// Date: 29-Jul-2020
// Comment:
//------------------------------------------------------------------------------
function RTF_Replace(oRTF:TTextRichEdit; cVgNr:String):String;
begin
ReplaceRTFAll(oRTF, '1234', '67789', lWholeWord , not lClearLine);
Result := oRTF.Caption;
end;
//------------------------------------------------------------------------------
// Procedure: RTF Replace für Internen Text
// Author: jr
// Date: 29-Jul-2020
// Comment:
//------------------------------------------------------------------------------
procedure Kunden_Daten(oDoku:TWordDoku; cPsNr:String);
var cBuffer : String;
cSQL : String;
qPerson : TxFQuery;
begin
cSQL := 'SELECT * FROM PERSSTA'+
' WHERE ps_nr = '+DB_SqlVal(cPsNr);
if (DB_SOpen(oDB, cSQL, qPerson)) then begin
if (not(empty(qPerson.A2C('ps_vorname')))) then begin
cBuffer := qPerson.A2C('ps_vorname') + ' ';
end;
if (not(empty(qPerson.A2C('ps_name')))) then begin
cBuffer := cBuffer + qPerson.A2C('ps_name');
end;
oDoku.Replace('VKNAME', cBuffer);
cBuffer := qPerson.A2C('ps_zusatz1');
AddEToken(cBuffer, qPerson.A2C('ps_zusatz2'),CRLF);
oDoku.Replace('VKZUSATZ', cBuffer);
if (not Empty(qPerson.A2C('ps_postf'))) then begin
oDoku.Replace('VKSTRASSE', 'Postfach: ' + qPerson.A2C('ps_postf'));
end else begin
oDoku.Replace('VKSTRASSE', qPerson.A2C('ps_strasse'));
end;
oDoku.Replace('VKLK', qPerson.A2C('ps_lk'));
oDoku.Replace('VKPLZ', qPerson.A2C('ps_plz'));
oDoku.Replace('VKORT', qPerson.A2C('ps_ort'));
end;
DB_Close(qPerson);
end;
//------------------------------------------------------------------------------
// Procedure: Word/Libre Replace für Dokumente
// Author: jr
// Date: 29-Jul-2020
// Comment:
//------------------------------------------------------------------------------
function Office_Replace(oDoku:TWordDoku):String;
var cSQL : String;
qVertrag : TxFQuery;
cBuffer : String;
nSatz : Double;
nBetrag : Double;
begin
if (oDoku.cDmsTyp = DMS_TYP_VERTRAG) then begin
cSQL := 'SELECT * FROM VERTRAG'+
' WHERE v_nr = '+DB_SqlVal(oDoku.cVgNr);
if (DB_SOpen(oDB, cSQL, qVertrag)) then begin
//Nur Notwendig bei mehreren Mandanten
//oDoku.SetManNr('001');
oDoku.Replace('VNUMMER', qVertrag.A2C('v_nr'));
oDoku.Replace('VNUMMER', qVertrag.A2C('v_nr'));
oDoku.Replace('VKNR' , qVertrag.A2C('v_knr'));
oDoku.Replace('SB' , oOBS.cSachbearbName);
oDoku.Replace('DATUM' , DToC(Date()));
//------------------------------------------------------------------
if (not Empty(qVertrag.A2C('v_knr'))) then begin
Kunden_Daten(oDoku, qVertrag.A2C('v_knr'));
end;
if (qVertrag.A2I('v_zahlzeit') = 1) then begin
cBuffer := 'Monatspauschale';
end else if (qVertrag.A2I('v_zahlzeit') = 2) then begin
cBuffer := 'Vierteljahrespauschale';
end else if (qVertrag.A2I('v_zahlzeit') = 3) then begin
cBuffer := 'Halbjahrespauschale';
end else if (qVertrag.A2I('v_zahlzeit') = 4) then begin
cBuffer := 'Jahrespauschale';
end else begin
cBuffer := 'Keine Angabe';
end;
oDoku.Replace('VZAHLZEIT' , cBuffer);
oDoku.Replace('VDATUM' , qVertrag.A2C('v_datum'));
oDoku.Replace('VPAUSCH' , qVertrag.A2C('v_pauschal'));
//------------------------------------------------------------------
oDoku.Replace('FELD01' , oDoku.cFeld01);
oDoku.Replace('FELD02' , oDoku.cFeld02);
oDoku.Replace('FELD03' , oDoku.cFeld03);
StdUStSatzDB(oDB, nSatz,'');
nBetrag := Roundy(qVertrag.A2F('v_pauschal') * nSatz / 100,2);
oDoku.Replace('VMWST' , axStr(nSatz));
oDoku.Replace('VMWSTBET' , axStr(nBetrag));
oDoku.ReplaceRAW('VGSUMME' , axStr(nBetrag+qVertrag.A2F('v_pauschal')));
end;
DB_Close(qVertrag);
end;
Result := 'OK';
end;
//------------------------------------------------------------------------------
// Procedure: Word/Libre Replace für Dokumente
// Author: jr
// Date: 29-Jul-2020
// Comment:
//------------------------------------------------------------------------------
function IsAllowed(cVgNr:String; cPsNr:String; cDMSTyp:String):Boolean;
begin
Result := True;
end;
//------------------------------------------------------------------------------