Opendocument (libreoffice) lazarus / 21-General ---------------------------------------------------------------------- cpalx · 2022-08-29 16:44 Hello Is it posble to open a libreoffice document ( odt file ), and modified? i was playing with fpODT, but it does not have open file feature ---------------------------------------------------------------------- beria · 2022-08-29 22:16 Quote from: cpalx on August 29, 2022, 06:44:33 pmHello Is it posble to open a libreoffice document ( odt file ), and modified? i was playing with fpODT, but it does not have open file feature 1. Cross-platform - there is a standard library fpvectorial. There are examples on the wiki. But the functionality is very limited. Particularly it has no ability to work with images in text... 2. OLE. VERY slow and glitchy. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  ServiceManager, Desktop : Variant;  CoreReflection, PropertyValue, VA: Variant;  Document: Variant;  Table, TableCell : Variant;  obj, objText, objCursor : Variant;  w,n : integer;  Cols,range : Variant;  str,fname1,faddresse1,finn,ffullname:widestring;  i,j:integer;  sum,s,sql_str:string;  sumzatr:currency;begin  if VarIsEmpty(ServiceManager) then    try      ServiceManager := CreateOleObject('com.sun.star.ServiceManager');    except      Raise Exception.Create('Couldn''t get ServiceManager');      Exit;    end;  sql_firm.Close;  sql_firm.sql.Text:='select * from tfirm where fshortname='''+ed_firm.Text+'''';  sql_firm.open;  fname1:=ed_firm.Text;  faddresse1:=trim(sql_firmfaddress.Value);  finn:='ИНН '+trim(sql_firmfinn.Value);  ffullname:= trim(sql_firmffullname.Value);  sql_firm.Close;  CoreReflection := Ser viceManager.createInstance('com.sun.star.reflection.CoreReflection');  CoreReflection.forName('com.sun.star.beans.PropertyValue').createObjec t(PropertyValue);  VA := VarArrayCreate([0, 0], varVariant);  VA[0] := PropertyValue;   Desktop := ServiceManager.createInstance('com.sun.star.frame.Desktop');  Document := Desktop.LoadComponentFromURL( 'private:factory/swriter','_blank', 0,  VA);  if (VarIsNull(Document) or VarIsEmpty(Document)) then     begin       Raise Exception.Create('Couldn''t create document');     Exit;     end;    //доступ к тексту документа  objText := Document.getText;// доступ к курсору документаobjCursor := objText.createTextCursor;//для курсора задаем шрифт  objCursor.setPropertyValue('CharHeight',12); //size  objCursor.setPropertyValue('CharWeight',150);//bold  //для курсора задаем положение текста на странице  objCursor.setPropertyValue('ParaAdjust',2);  //left  //переводим кодировку utf8 в текущую на ПК  str:=utf8decode(fname1+', '+ffullname);  //выводим текст    objText.insertString(objCursor, str, false);    //вносим разделитель - перенос строки не привязанный к размеру шрифта   objText.insertControlCharacter(objCursor, 0, false );  str:=utf8decode(faddresse1);objText.insertString(objCursor, str, false);objText.insertControlCharacter(objCursor, 0, false ); str:=utf8decode(finn);objText.insertString(objCursor, str, false);objText.insertControlCharacter(objCursor, 0, false );//разделитель     //Заголовок документа  objCursor.setPropertyValue('CharHeight',22); //size  objCursor.setPropertyValue('CharWeight',150);//bold  objCursor.setPropertyValue('ParaAdjust',3);  //center  str:=utf8decode('Калькуляция на изделие : ');  objText.insertString(objCursor, str, false);  objText.insertControlCharacter(objCursor, 0, false );//разделитель  objCursor.setPropertyValue('CharHeight',16); //size  str:=utf8decode(trim(sql_nomFDESCR.Value));  objText.insertString(objCursor, str, false);  objText.insertControlCharacter(objCursor, 0, false );//разделитель  objText.insertControlCharacter(objCursor, 0, false );//разделитель  str:=utf8decode('Комплектация (изделия и материалы)');  objText.insertString(objCursor, str, false);  objText.insertControlCharacter(objCursor, 0, false ); //PARA_BREAK   //создаем таблицу   Table := Document.createInstance( 'com.sun.star.text.TextTable' );  sql_str:='select * from tcalc where fdescr='''+'material'+''' and fud<>1 and ftovar='+sql_nomfid.asstring;  sql_calc1.close;  sql_calc1.SQL.Text:=sql_str;  sql_calc1.open;  sql_calc1.last;    n:=sql_calc1.RecordCount;    //задаем количество ячеек  Table.initialize(n+1, 3);  //row, column  //горизонтальная ореинтация  Table.HoriOrient := 0;//  поле слева  Table.LeftMargin := 20; // 2* 1/100 mm;  //  поле справа  Table.RightMargin := 20;  //доступ к тексту таблицы  Document.getText.insertTextContent( objCursor, Table, false );  //доступ к массиву вертикальных линий внутри таблицы  obj := Table.TableColumnSeparators;   //ширина первой колонки (поз. от начала таблы верт. разд. линии)    obj[0].Position :=8000;//zatr   // ширина второй колонки  obj[1].Position := obj[0].Position+900;//kol//передаем данные массива вертикальных линий в таблицу  Table.TableColumnSeparators := obj;  //заголовоки колонок таблицы (доступ возможен по имени или по индексу, по имени с 1, по индексу с 0)   str:=utf8decode('Наименование затрат');  TableCell := Table.getCellByName('A1');  TableCell.setString(str);   str:=utf8decode('Кол-во');  TableCell := Table.getCellByname('B1');   TableCell.setString(str);    str:=utf8decode('Сумма');  TableCell := Table.getCellByname('C1');   TableCell.setString(str);  //конец шапки     //выделяем участок таблицы центруем текст в ячейках по горизонтали  str:='B1:C'+inttostr(n+1);   range := table.getCellRangeByname(str);  range.setPropertyValue('ParaAdjust',3);  //center     sumzatr:=0;     sql_calc1.First;       //заполняем материалы  for i:=1 to sql_calc1.RecordCount do begin    for j:=0 to 2 do begin    //доступ к ячейке по индексу (i=0 - шапка)  TableCell := Table.getCellByPosition(j, i);if j=0 then beginstr:=utf8decode(trim(sql_calc1Fzatr.Value));  TableCell.setString(str);end;if j=1 then beginstr:=utf8decode(trim(sql_calc1Fkolvo.AsString)); TableCell.setString(str);end;if j=2 then beginstr:=utf8decode(sql_calc1Fsumzatr.AsString); TableCell.setString(str);end;      end;    sumzatr:=sumzatr+ sql_calc1Fsumzatr.value;  sql_calc1.Next;end;   //конец таблицы  1   //отделяем заголовок второй таблицы(ниже) от первой таблицы  objText.insertControlCharacter(objCursor, 0, false );//разделитель  objCursor.setPropertyValue('CharHeight',16); //size  objCursor.setPropertyValue('CharWeight',150);//bold  objCursor.setPropertyValue('ParaAdjust',3);  //center  //заголовок второй таблицы  str:=utf8decode('Прочие затраты (зарплата и т.п.)');  objText.insertString(objCursor, str, false);  objText.insertControlCharacter(objCursor, 0, false ); //PARA_BREAK   objCursor.setPropertyValue('CharHeight',12); //size  objCursor.setPropertyValue('CharWeight',150);//bold  objCursor.setPropertyValue('ParaAdjust',2);  //center  Table := Document.createInstance( 'com.sun.star.text.TextTable' );  sql_str:='select * from tcalc where fdescr='''+'rabota'+''' and fud<>1 and ftovar='+sql_nomfid.asstring;  sql_calc1.close;  sql_calc1.SQL.Text:=sql_str;  sql_calc1.open;  sql_calc1.last;    n:=sql_calc1.RecordCount;  Table.initialize(n+1, 2);  //row, column  Table.HoriOrient := 0;  Table.LeftMargin := 20; // 2* 1/100 mm;  Table.RightMargin := 20;   Document.getText.insertTextContent( objCursor, Table, false );   obj := Table.TableColumnSeparators;   obj[0].Position :=8000;//zatr   Table.TableColumnSeparators := obj;   str:=utf8decode('Наименование затрат');  TableCell := Table.getCellByName('A1');  TableCell.setString(str);   str:=utf8decode('Сумма');  TableCell := Table.getCellByname('B1');   TableCell.setString(str);   //конец шапки  //центрируем текст в ячейках второго столбца     str:='B1:B'+inttostr(n+1);   range := table.getCellRangeByname(str);  range.setPropertyValue('ParaAdjust',3);  //center       sql_calc1.First;       //заполняем  for i:=1 to sql_calc1.RecordCount do begin    for j:=0 to 1 do begin  TableCell := Table.getCellByPosition(j, i);if j=0 then begin  str:=utf8decode(trim( sql_calc1Fzatr.Value));TableCell.setString(str);end;if j=1 then begin  str:=utf8decode(sql_calc1Fsumzatr.AsString);; TableCell.setString(str);end;      end;    sumzatr:=sumzatr+ sql_calc1Fsumzatr.value;  sql_calc1.Next;end;   //конец таблицы  //отделяем текст (ниже) от таблиц   objText.insertControlCharacter(objCursor, 0, false ); //PARA_BREAK  objText.insertControlCharacter(objCursor, 1, false ); //LINE_BREAK  objText.insertControlCharacter(objCursor, 0, false ); //PARA_BREAK  //Параметры текста   objCursor.setPropertyValue('CharHeight',12); //size   objCursor.setPropertyValue('CharWeight',150);//bold   objCursor.setPropertyValue('ParaAdjust',2);  //left    s:= currtostr(sql_nomfcenar.value);    f_sborka.Sum_Propisyu(s,Sum) ;  sum:=trim(sum);  str:= utf8decode('Итого затрат : '+ currtostr(sumzatr)+' руб.'+#13#10);   objText.insertString(objCursor, str, false);   str:= utf8decode('С учетом накладных расходов: '+ sql_nomfcenar.AsString+' руб. /'+sum+'/'+#13#10+'Менеджер  ');    objText.insertString(objCursor, str, false);  end; 3. Very fast, cross platform. It takes a file, unpacks it, and parses it like xlm... I've seen examples of this. ---------------------------------------------------------------------- egsuh · 2022-08-30 02:29 There is an internal language called OpenOffice.org Basic. You may modify the contents calling the Basic commands within pascal.