Page 1 of 1
Load DIRECTLY WinWord Document to rvEditor?
Posted: Tue Mar 06, 2012 2:40 pm
by j&b
Is there a way to load DIRECTLY WinWord Documents to rvEditor[br][br]
Background:[br]
The rvf files are very much smaller than Word files. This property I would like to use to archive Word files[br][br]
I do not want[br]
to load a DOC-file with Winword[br]
save it by Winword as RTF file and[br]
load it with rvEditor.
PS: What ist wrong using [br] for next line
Posted: Tue Mar 06, 2012 7:02 pm
by Sergey Tkachenko
Note that when converting MS Word document to RVF you looses all features that are not supported by TRichView.
There are no methods for loading doc or docx files directly, sorry.
You can use converters to import them (using TRVOfficeConverter component), however the result will be worse comparing to importing RTF saved/copied by MS Word.
Probably, you can use OLE automation (TWordApplication, TWordDocument) to save a document to a temporal RTF file (or the Clipboard) and then import it in TRichView. But I do not have an example, sorry.
Posted: Wed Mar 07, 2012 6:20 am
by j&b
Sergey Tkachenko wrote:Probably, you can use OLE automation (TWordApplication, TWordDocument) to save a document to a temporal RTF file (or the Clipboard) and then import it in TRichView. But I do not have an example, sorry.
Thank you for your answere.
If you do not know what time you should: Would that no be a further round out?
Posted: Wed Mar 07, 2012 7:22 am
by Sergey Tkachenko
Sorry, I do not understand the question
Posted: Wed Mar 07, 2012 9:25 am
by j&b
Sergey Tkachenko wrote:Sorry, I do not understand the question
A joke (Scherz)
'Falls du mal nicht weißt was du machen sollst ...'
oder 'Solltest du mal "Saure Gurkenzeit haben"...' (
http://de.wikipedia.org/wiki/Sauregurkenzeit)
... dann würde die Erweiterung (.doc to .rvf) dein Programm weiter abrunden.
Posted: Wed Mar 28, 2012 7:32 am
by j&b
I have found that many users do not publish the solution of their question. That's a shame, because I think that the last article should be the solution of a question.. Therefore, I present MY solution for my question to all those who are interested.
In the meantime, I have had a "Saure Gurkenzeit" and I found Sergey's "Office Converter" (in folder "... \ Richview \ Demos \ Delphi \ Office Converter"). I ingrated the few lines (to solve my problem) in his program "REditor.exe" (... \ Richview \ Demos \ Delphi \ Editors \ Editor 2 integrated) for training.
procedure TForm1.btnOpenClick(Sender: TObject);
begin Open; end;
procedure TForm1.Open;
var fEinfuegen: boolean; i: integer; filename: string;
begin
//if query1.state in [dsEdit, dsInsert] then query1.post; //if memo is a TDBRichViewEdit
//memo.Modified := False; //if SaveIfNeeded
i:= MessageDlg('JA: Es soll das Memo vorher geleert werden.'+#10#10+
'NEIN: Inhalt der Datei soll an eine bestimmten Zeile im Memo eingefügt werden.'+#10+
' - Die Schreibmarke muss daher in der gew. Zeile stehen'+#10#10, mtConfirmation, [mbYes,mbNo,mbCancel],0);
fEinfuegen:= false; //Memo NICHT vorher leeren
if i= 2 then exit //mbChancel
else if i= 7 then fEinfuegen:= true;
od.filter:= 'RichViewEDIT (RVF)|*.rvf|RichView (RTF)|*.rtf|Ini-Dateien (INI)|*.ini|'+
'Text-Dateien (TXT)|*.txt|Doc (1997-2003)|*.DOC|DOCx (2007)|*.DOCx|HTML (o. Grafik), HTM|*.htm|'+
'Alles (*.*)|*.*|'; //+rvc.GetImportFilter nach OfficeLaden verlegt
od.filterIndex:= 99; //wenn index>letzten tats. Index, dann wird der letzte tats. Index genommen
if od.Execute then begin
FileName := ansiLowerCase(od.fileName);
if fEinfuegen= false then memo.clear;
if pos('rvf', filename)>0 then begin
if memo.InsertRVFFromFileEd(filename)= false then
if MessageDlg(filename+#10#10+'Fehler beim Laden der RVF-Datei !'+#10#10+
'Laden insgesamt abbrechen ? '+#10, mtConfirmation, [mbYes,mbNo],0) = mrYes then exit;
od.filterIndex:= 1;
end else if pos('rtf', filename)>0 then begin
if memo.InsertRTFFromFileEd(filename)= false then
if MessageDlg(filename+#10#10+'Fehler beim Laden der RVF-Datei !'+#10#10+
'Laden insgesamt abbrechen ? '+#10, mtConfirmation, [mbYes,mbNo],0) = mrYes then exit;
od.filterIndex:= 2;
end else if pos('doc', FileName)>0 then begin officeLaden(6); exit;
end else if pos('docx', FileName)>0 then begin officeLaden(5); exit;
end else if pos('htm', FileName)>0 then begin officeLaden(0); exit;
end else if memo.LoadText(filename,0,0,false)= false then begin
if MessageDlg(filename+#10#10+'Fehler beim Laden der Text-Datei !'+#10#10+
'Laden insgesamt abbrechen ? '+#10, mtConfirmation, [mbYes,mbNo],0) = mrYes then exit;
od.filterIndex:= 99;
end;
//if query1.state in [dsEdit, dsInsert] then query1.post;
form1.Caption := 'RichView-Editor * '+FileName;
end;
end;
procedure TForm1.rvcConverting(Sender: TObject; Percent: Integer);
begin pb.Position := Percent; end; //TProgressBar
procedure TForm1.officeLaden(wahl: integer);
var r: Boolean; //rvc: uses RVOfficeCnv
begin
od.filter:= rvc.GetImportFilter; //hier angesiedelt, weil sonst von vornherein im od.filter
pb.Visible := True; //die Office-Endungen enthalten sind
r:= rvc.ImportRV(od.FileName, memo, wahl); //wahl ist sehr wichtig - s. TForm1.Open
if not r then Application.MessageBox('Error','Error',0);
pb.Visible := False;
memo.Format;
form1.Caption:= 'Konvertierte Office-Datei * '+od.FileName; //jb
memo.SetFocus;
end;
procedure TForm1.officeSpeichern(wahl: integer);
var r: Boolean;
begin
sd.filter:= rvc.GetExportFilter; //hier angesiedelt, weil sonst von vornherein im od.filter
pb.Visible := True; //die Office-Endungen enthalten sind
//memo.canChange; //nur wenn mit TDBRichViewEdit
r:= rvc.ExportRV(sd.FileName, memo, wahl); //wahl bezieht sich auf "rvc.GetExportFilter.ItemIndex"
if not r then Application.MessageBox('Error','Error',0);
pb.Visible := False; //nur wenn mit TDBRichViewEdit, ansonsten
//memo.change; //s. wichtig
memo.Format; //TRichViewEdit <--> TDBRichViewEdit
//if query1.state in [dsEdit, dsInsert] then query1.post; //nur bei TDBRichViewEdit
form1.Caption:= 'Konvertierte Office-Datei * '+sd.FileName;
memo.SetFocus;
end;
function TForm1.SaveAs: Boolean;
var fEinfuegen: boolean;
i: integer;
s,filename: string;
begin
//if query1.state in [dsEdit, dsInsert] then query1.post;
i:= MessageDlg('JA: Es soll der Inhalt des ganzen Memos gespeichert werden.'+#10#10#10+
'NEIN: Es soll nur das Markierte gespeichert werden.'+#10+
' - Die Schreibmarke muss daher in der gew. Zeile stehen'+#10+
' - Dieses Memo wird dann allen anderen Memos zugewiesen'+#10#10, mtConfirmation, [mbYes,mbNo,mbCancel],0);
fEinfuegen:= false;
if i= 2 then exit
else if i= 7 then fEinfuegen:= true;
s:= form1.Caption+' (Endung bitte mit angeben)';
sd.title:=s;
sd.filter:= 'RichViewEDIT (RVF)|*.rvf|RichView (RTF)|*.rtf|Ini-Dateien (INI)|*.ini|'+
'Text-Dateien (TXT)|*.txt|Doc (1997-2003)|*.DOC|DOCx (2007)|*.DOCx|HTML (o. Grafik), HTM|*.htm|'+
'Alles (*.*)|*.*|'; //+rvc.GetImportFilter nach OfficeLaden verlegt
sd.filterIndex:= 99; //wenn index>letzten tats. Index, dann wird der letzte tats. Index genommen
if sd.Execute then begin
FileName := ansilowerCase(sd.FileName);
if pos('rvf', FileName)>0 then begin memo.SaveRVF(FileName, fEinfuegen); sd.filterIndex:= 1; //false: gesamtes Dokument, true: Markiertes
end else if pos('rtf', FileName)>0 then begin memo.SaveRTF(FileName, fEinfuegen); sd.filterIndex:= 2;
end else if pos('doc', FileName)>0 then begin officeSpeichern(6); exit;
end else if pos('docx', FileName)>0 then begin officeSpeichern(5); exit;
end else if pos('htm', FileName)>0 then begin officeSpeichern(0); exit;
end else begin memo.saveText(FileName,0,0); sd.filterIndex:= 99; end;
end;
end;
Posted: Wed Mar 28, 2012 8:08 am
by Sergey Tkachenko
As far as I can see, you use hard-coded indices of converters (like 6, 5, 0).
This is wrong, because different computers may have different sets of converters: the same converter may have different index on different computers, or it may be not installed at all.
So, to find a converter for the required format, you need to search in ImportConverters or ExportConverters to find the index of the converter to use. And you cannot search for the Name property of converters, because they may be different on different computers (localized).
For example, the HTML converter, both import and export, is implemented in HTML32.CNV. You can search for inclusion of 'HTML32.CNV' in Path property of the converter.
Posted: Wed Mar 28, 2012 11:14 am
by j&b
I hope that's what you mean.
Perhaps someone find a better way as "unit uDatTyp" on a new Form
procedure TForm1.btnOpenClick(Sender: TObject);
begin Open; end;
procedure TForm1.Open;
var fEinfuegen: boolean;
i,wahl: integer;
dateityp, filename: string;
begin
//if query1.state in [dsEdit, dsInsert] then query1.post;
//memo.Modified := False; //s. SaveIfNeeded
//----------------------------------------------------------------------------
Application.CreateForm(TfDateityp, fDateityp);
try
with fDateityp do begin
rg2.Items.delete(1); rg2.Items.delete(0);
rg2.items.ADD('Vorher leeren'); rg2.items.ADD('An Position');
rg2.itemIndex:= 0;
ShowModal;
if pClose.tag= 0 then exit
else begin
if rg1.ItemIndex=1 then dateityp:= 'office' else dateityp:= 'rve';
if rg2.ItemIndex=0 then fEinfuegen:= false else fEinfuegen:= true;
end;
end;
finally
fDateityp.release;
end;
if dateityp= 'office' then begin
od.title:= form1.Caption+' (Dateityp bitte wählen)';
<font color=red>od.Filter := 'RTF (Built-In RichView Export)|*.rtf|'+rvc.GetImportFilter;</font>
od.fileName:= '*.*';
if od.Execute then begin
officeLaden(od.filterIndex);
exit;
end else exit;
end;
//----------------------------------------------------------------------------
od.filter:= 'RichViewEDIT (RVF)|*.rvf|RichView (RTF)|*.rtf|Ini-Dateien (INI)|*.ini|'+
'Text-Dateien (TXT)|*.txt|Alles (*.*)|*.*|';
od.filterIndex:= 99; //wenn index>letzten tats. Index, dann wird der letzte tats. Index genommen
if od.Execute then begin
FileName := ansiLowerCase(od.fileName);
if fEinfuegen= false then memo.clear;
if pos('rvf', filename)>0 then begin
if memo.InsertRVFFromFileEd(filename)= false then
if MessageDlg(filename+#10#10+'Fehler beim Laden der RVF-Datei !'+#10#10+
'Laden insgesamt abbrechen ? '+#10, mtConfirmation, [mbYes,mbNo],0) = mrYes then exit;
end else if pos('rtf', filename)>0 then begin
if memo.InsertRTFFromFileEd(filename)= false then
if MessageDlg(filename+#10#10+'Fehler beim Laden der RVF-Datei !'+#10#10+
'Laden insgesamt abbrechen ? '+#10, mtConfirmation, [mbYes,mbNo],0) = mrYes then exit;
end else if memo.LoadText(filename,0,0,false)= false then begin
if MessageDlg(filename+#10#10+'Fehler beim Laden der Text-Datei !'+#10#10+
'Laden insgesamt abbrechen ? '+#10, mtConfirmation, [mbYes,mbNo],0) = mrYes then exit;
end;
//if query1.state in [dsEdit, dsInsert] then query1.post;
form1.Caption := 'RichView-Editor * '+FileName;
end;
end;
procedure TForm1.rvcConverting(Sender: TObject; Percent: Integer);
begin pb.Position := Percent; end; //TProgressBar
procedure TForm1.officeLaden(wahl: integer);
var r: Boolean;
begin
pb.Visible := True;
r:= rvc.ImportRV(od.FileName, memo, wahl-2 ; //wahl bezieht sich auf "rvc.GetExportFilter.ItemIndex"
if not r then Application.MessageBox('Error','Error',0);
pb.Visible := False;
memo.Format;
form1.Caption:= 'Konvertierte Office-Datei * '+od.FileName;
memo.SetFocus;
end;
procedure TForm1.officeSpeichern(wahl: integer);
var r: Boolean;
begin
pb.Visible := True;
//memo.canChange; //nur wenn mit TDBRichViewEdit
r:= rvc.ExportRV(sd.FileName, memo, wahl-2 ); //wahl bezieht sich auf "rvc.GetExportFilter.ItemIndex"
if not r then Application.MessageBox('Error','Error',0);
pb.Visible := False;
//memo.change; //nur wenn mit TDBRichViewEdit
memo.Format; //nur bei TRichViewEdit
//if query1.state in [dsEdit, dsInsert] then query1.post; //nur bei TDBRichViewEdit
form1.Caption:= 'Konvertierte Office-Datei * '+sd.FileName;
memo.SetFocus;
end;
function TForm1.SaveAs: Boolean;
var fEinfuegen: boolean;
filename, dateityp: string;
begin
//if query1.state in [dsEdit, dsInsert] then query1.post;
//----------------------------------------------------------------------------
Application.CreateForm(TfDateityp, fDateityp);
try
with fDateityp do begin
ShowModal;
if pClose.tag= 0 then exit
else begin
if rg1.ItemIndex=1 then dateityp:= 'office' else dateityp:= 'rve';
if rg2.ItemIndex=0 then fEinfuegen:= false else fEinfuegen:= true;
end;
end;
finally
fDateityp.release;
end;
if dateityp= 'office' then begin
sd.title:= form1.Caption+' (Dateityp bitte wählen)';
sd.Filter := 'RTF (Built-In RichView Export)|*.rtf|'+rvc.GetExportFilter;
sd.fileName:= '*.*';
if sd.Execute then begin
officeSpeichern(sd.filterIndex);
exit;
end else exit;
end;
//----------------------------------------------------------------------------
sd.title:= form1.Caption+' (Dateityp bitte wählen)';
sd_office.filter:= rvc.GetExportFilter;
sd.filter:= 'RichViewEDIT (RVF)|*.rvf|RichView (RTF)|*.rtf|Ini-Dateien (INI)|*.ini|'+
'Text-Dateien (TXT)|*.txt|Alles (*.*)|*.*|';
sd.filterIndex:= 99;
if sd.Execute then begin
FileName := ansilowerCase(sd.FileName);
if pos('rvf', FileName)>0 then memo.SaveRVF(FileName, fEinfuegen) //false: gesamtes Dokument, true: Markiertes
else if pos('rtf', FileName)>0 then memo.SaveRTF(FileName, fEinfuegen)
else memo.saveText(FileName,0,0);
end;
end;
//--------------------------------------------------------------------------------------------------------------
{ Create a new form (fDateityp) and set in mainprogram: uses uDatTyp
unit uDatTyp;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls;
type
TfDateityp = class(TForm)
rg1: TRadioGroup;
rg2: TRadioGroup;
pClose: TPanel;
pCancel: TPanel;
//Panel3: TPanel;
procedure pCloseClick(Sender: TObject);
procedure pCancelClick(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
fDateityp: TfDateityp;
implementation
{$R *.dfm}
procedure TfDateityp.pCloseClick(Sender: TObject);
begin pClose.tag:= 1; close; end;
procedure TfDateityp.pCancelClick(Sender: TObject);
begin pClose.tag:= 0; close; end;
end.
}
Posted: Wed Mar 28, 2012 1:58 pm
by j&b
Oddly enough are "memo.canChange and memo.Change" (for working with "TDBRichViewEdit") are written to "officeSpeichern" instead to "officeLaden".
Sorry.
Here are the corrected procedures.
procedure TForm1.officeLaden(wahl: integer);
var r: Boolean;
begin
pb.Visible := True;
//memo.canChange; //nur wenn mit TDBRichViewEdit
r:= rvc.ImportRV(od.FileName, memo, wahl-2 ; //wahl bezieht sich auf "rvc.GetExportFilter.ItemIndex"
if not r then Application.MessageBox('Error','Error',0);
pb.Visible := False;
//memo.change; //nur wenn mit TDBRichViewEdit
memo.Format; //nur wenn TRichViewEdit
//if query1.state in [dsEdit, dsInsert] then query1.post; //nur bei TDBRichViewEdit
form1.Caption:= 'Konvertierte Office-Datei * '+od.FileName;
memo.SetFocus;
end;
procedure TForm1.officeSpeichern(wahl: integer);
var r: Boolean;
begin
pb.Visible := True;
r:= rvc.ExportRV(sd.FileName, memo, wahl-2 ); //wahl bezieht sich auf "rvc.GetExportFilter.ItemIndex"
if not r then Application.MessageBox('Error','Error',0);
pb.Visible := False;
form1.Caption:= 'Konvertierte Office-Datei * '+sd.FileName;
memo.SetFocus;
end;