How to add doc and docx support in ActionTest ribbon demo?
-
- Posts: 2
- Joined: Sun Dec 09, 2012 3:36 pm
How to add doc and docx support in ActionTest ribbon demo?
How to add doc and docx support in ActionTest ribbon demo?How can i spread the filter?
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
The instructions are below. I tested it on the normal ActionTest demo, but the same code must work for the Ribbon version. The only difference: actions are located on the form, not on rvActionsResource.
Options for opening DOC and/or DOCX files appears in the open and save dialogs only if the corresponding converters are installed on the computer.
1) Place rvc: TRVOfficeConverter on the form.
2) Add to the form declaration:
3) Add the form method InitDocFilters:
4) Call this InitDocFilters in FormCreate.
5) Process RVAControlPanel1.OnCustomFileOperation:
Options for opening DOC and/or DOCX files appears in the open and save dialogs only if the corresponding converters are installed on the computer.
1) Place rvc: TRVOfficeConverter on the form.
2) Add to the form declaration:
Code: Select all
DocConverters, DocXConverters: Boolean;
Code: Select all
function FindConverter(Converters: TRVOfficeCnvList; const Filter, DLL: String): Integer;
var i: Integer;
begin
Result := -1;
for i := 0 to Converters.Count-1 do
if (Filter = AnsiLowerCase(Converters[i].Filter)) and
(AnsiPos(DLL, AnsiLowerCase(Converters[i].Path))>0) then begin
Result := i;
exit;
end;
end;
const CNVDLL = 'wordcnvpxy.cnv';
procedure TForm3.InitDocFilters;
begin
DocConverters :=
(FindConverter(rvc.ImportConverters, '*.doc', CNVDLL)>=0) and
(FindConverter(rvc.ExportConverters, '*.doc', CNVDLL)>=0);
DocXConverters :=
(FindConverter(rvc.ImportConverters, '*.docx', CNVDLL)>=0) and
(FindConverter(rvc.ExportConverters, '*.docx', CNVDLL)>=0);
if DocConverters then
rvActionsResource.rvActionOpen1.CustomFilter := 'Microsoft Word 97-2003 Document|*.doc';
if DocXConverters then begin
if DocConverters then
rvActionsResource.rvActionOpen1.CustomFilter :=
rvActionsResource.rvActionOpen1.CustomFilter+'|';
rvActionsResource.rvActionOpen1.CustomFilter :=
rvActionsResource.rvActionOpen1.CustomFilter+'Microsoft Word 2007+ Document|*.docx';
end;
rvActionsResource.rvActionSaveAs1.CustomFilter := rvActionsResource.rvActionOpen1.CustomFilter;
end;
5) Process RVAControlPanel1.OnCustomFileOperation:
Code: Select all
procedure TForm3.RVAControlPanel1CustomFileOperation(Sender: TrvAction;
Edit: TCustomRichViewEdit; const FileName: string;
Operation: TRVAFileOperation; var SaveFormat: TrvFileSaveFilter;
var CustomFilterIndex: Integer; var Success: Boolean);
var Ext: String;
Index: Integer;
begin
Success := False;
Ext := '';
case CustomFilterIndex of
1:
if DocConverters then
Ext := '*.doc'
else if DocXConverters then
Ext := '*.docx';
2:
if DocConverters and DocXConverters then
Ext := '*.docx';
end;
if Ext='' then
exit;
case Operation of
rvafoOpen:
Success := rvc.ImportRV(FileName, Edit, FindConverter(rvc.ImportConverters, Ext, CNVDLL));
rvafoSave:
Success := rvc.ExportRV(FileName, Edit, FindConverter(rvc.ExportConverters, Ext, CNVDLL));
end;
end;
Last edited by Sergey Tkachenko on Mon Dec 10, 2012 8:02 pm, edited 2 times in total.
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Notes:
1) I tested on a computer with MS Word 2007 installed. Probably, if doc-converters are installed with older versions of MS Word, the converter DLL has a different name, not wordcnvpxy.cnv.
2) The quality of importing doc/docx is worse than if you save a file in MS Word as rtf and then open this rtf. The same for exporting. Unfortunately, converters do their work not as good as MS Word itself.
3) Converters can open/save files with names that can be converted to DOS (OEM) charset. They fail opening files having Unicode characters. To solve this problem, you can either use GetShortPathName, or create a temporal copy of the file to open/save with a simple name.
4) If MS Office is not installed, DOCX converter can be downloaded here: http://www.microsoft.com/en-us/download ... .aspx?id=3
1) I tested on a computer with MS Word 2007 installed. Probably, if doc-converters are installed with older versions of MS Word, the converter DLL has a different name, not wordcnvpxy.cnv.
2) The quality of importing doc/docx is worse than if you save a file in MS Word as rtf and then open this rtf. The same for exporting. Unfortunately, converters do their work not as good as MS Word itself.
3) Converters can open/save files with names that can be converted to DOS (OEM) charset. They fail opening files having Unicode characters. To solve this problem, you can either use GetShortPathName, or create a temporal copy of the file to open/save with a simple name.
4) If MS Office is not installed, DOCX converter can be downloaded here: http://www.microsoft.com/en-us/download ... .aspx?id=3