到目前还没有一个人能够给出一个好的方法,没有高手吗?电脑上没有安装Office,怎样用Delphi打开Office 系列(word,excel,ppt)并能预览

  • 主题发起人 主题发起人 c~c
  • 开始时间 开始时间
To hfghfghfg:
Thank you for your discuss.How can I read pdf document without Adobe Acrobat installed?
 
这个问题,我也问过,就是在没有安装那些软件的时候,怎么打开Word
后来查了一些资料,要把系统的目录下的和共享目录下的一些系统文件,安装上去,才可以
驱动OLE的一些功能。具体是哪些我也不是很清楚
等高人指点。
 
1.word:金山有一个工具可以把word转换为wps,能够转换肯定能读取了,找它买代码吧。
2.excel:axxlsrwii,花钱注册吧,好象不支持中文。
http://www.playicq.com/dispdoc.php?t=&id=1478
3.ppt好象没有办法。
4.pdf:lunix平台上有不少开放源码的阅读器,拿来研究一下吧。
先上http://www.newsoftinc.com/试一试PageManager
 
其实 安装Office的时候有安装“文本转换器”(好像是这个)
然后到以下路径找找
C:/Program Files/Common Files/Microsoft Shared/TextConv
会看到一堆文件 这里是一些文件相互转换的链接库
其中Word2000(以上)->rtf 使用MSWRD832.CNV
Excel->rtf 使用EXCEL32.CNV
Html->rtf 使用html32.cnv
其它的我还没有测试过
使用的时候 将这些文件拷贝到你的程序路径下 直接用就行了 不需要安装Word
但是我还没有找到不用安装Word 将Rtf转成Doc的方法 唉
下面是我的一个程序中使用的单元
unit Converters;

interface

uses
Registry, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, FileCtrl, OleCtrls, ComCtrls, ExtCtrls, AxCtrls,RVEdit;

// -----------------------------------------------------------------
// Functions to call when you want to convert something
// -----------------------------------------------------------------

// Function to import a file to a WideString.
function ImportAsRTF(FileName: String; Converter: String; rtbApp: TRichViewEdit;boole:Boolean): Boolean;

// Function to export RTF to a file.
//function ExportRTF(FileName: String; Converter: String; rtbApp: TRichViewEdit): Boolean;

// -----------------------------------------------------------------
// Functions to call if you want to know what can be converted
// -----------------------------------------------------------------

// Function to build a filter list, with available import and export converters.
function BuildFilterList(ForImport: Boolean): string;

// Function to build a list with available conveters.
function BuildConverterList(ForImport: Boolean; StrLst: TStringList): Boolean;

// -----------------------------------------------------------------
// Supportive functions - not to be called direct, unless you
// know what you are doing
// -----------------------------------------------------------------

// Initialize the selected converter.
function LoadConverter(Description: string; Import,boolExcel: boolean): HWND;

// Check if current file is of right format.
function IsKnownFormat(FileName: string): Boolean;

// Convert string to HGLOBAL.
function StringToHGLOBAL(const str: string): HGLOBAL;

// Procedure to free the converters.
procedure DoFreeConverters;

// Function to obtain the directory of WordPad. Not needed to be public, but maybe
// someone is looking for it.
function WordPadDir: string;

// Callback functions for reading and writing.
function Reading(CCH, nPercentComplete: integer): Integer; stdcall;
function Writing(flags, nPercentComplete: integer): Integer; stdcall;


implementation

type
// Our functions to convert the RTF-format to a foreign format, or a foreign format to the RTF-format.
// These functions are hidden in the converters.
RTF_CALLBACK = function(CCH, nPercentComplete: integer): Integer; stdcall;
TInitConverter = function(ParentWin: THandle; ParentAppName: LPCSTR): integer; stdcall;
TIsFormatCorrect = function(FileName, Desc: HGLOBAL): integer; stdcall;
TForeignToRtf = function(FileName: HGLOBAL; void: pointer{LPSTORAGE}; Buf, Desc, Subset: HGLOBAL; Callback: RTF_CALLBACK): integer; stdcall;
TRtfToForeign = function(FileName: HGLOBAL; void: pointer{LPSTORAGE}; Buf, Desc: HGLOBAL; Callback: RTF_CALLBACK): integer; stdcall;

var
CurrentConverter: HWND;
InitConverter: TInitConverter = nil;
IsFormatCorrect: TIsFormatCorrect = nil;
ForeignToRtf: TForeignToRtf = nil;
RtfToForeign: TRtfToForeign = nil;
hBuf: HGLOBAL;
bytesRead: integer = 0;
WritePos: integer = 0; // in Char, not WChar
WriteMax: integer = 0; // in Char, not WChar
RTFToWrite: string;
mstream: TMemorystream = nil;

const
nBufSize: integer = 4096;
MSTextConvKey = 'SOFTWARE/Microsoft/Shared Tools/Text Converters/';


function ImportAsRTF(FileName: String; Converter: String; rtbApp: TRichViewEdit;boole:Boolean): Boolean;
var
// Variables used for the actual conversion.
hSubset,
hFileName,
hDesc: HGLOBAL;
res: integer;
begin
Result := False; // We are very pessimistic.
try
if LoadConverter(Converter, True,boole) <> 0 then
begin
// Check selected file format.
if IsKnownFormat(FileName) then
begin
// prepare parameters
hSubset := StringToHGLOBAL('');
hDesc := StringToHGLOBAL('');

hFileName := StringToHGLOBAL(FileName);

hBuf := GlobalAlloc(GHND, nBufSize + 1);

try
Screen.Cursor := crHourGlass;

mstream := TMemoryStream.Create;
mstream.SetSize(512 * 1024); // initial: 512 kB, seems reasonable.

if Assigned(ForeignToRtf) then
res := ForeignToRtf(hFileName, nil, hBuf, hDesc, hSubset, Reading)
else
res := -1; // no valid entry point for DLL

if res = 0 then // Don't know any other states. Might be boolean.
begin
mstream.SetSize(mstream.Position); // shrink to right size
mstream.Position := 0;

//rtbApp.Lines.LoadFromStream(mStream);
//rtbApp.Clear;
//rtbApp.Format;
rtbApp.LoadRTFFromStream(mStream);
rtbApp.Format;
//rtbApp.WideLines.LoadFromStream(mStream);
mStream.Free;

Result := True;
end
else
Result := False;
finally
GlobalFree(hBuf);
GlobalFree(hFileName);
GlobalFree(hDesc);
GlobalFree(hSubset);
Screen.Cursor := crDefault;
end;
end
else
begin
ShowMessage('Not the correct file format');
Result := False;
end;
end;
except
Result := False;
end;
end;


{function ExportRTF(FileName: String; Converter: String; rtbApp: TRichViewEdit): Boolean;
var
hSubset,
hFileName,
hDesc: HGLOBAL;
res: integer;
iSelStart, iSelLength: Integer;
begin
if LoadConverter(Converter, False) <> 0 then
begin
if not (Assigned(InitConverter)
and LongBool(InitConverter(Application.Handle, PChar(Uppercase(Application.ExeName))))) then
begin
ShowMessage('Please report: InitConverter failed');
Result := False;
Exit;
end;

hSubset := StringToHGLOBAL('');
hDesc := StringToHGLOBAL('');
hFileName := StringToHGLOBAL(FileName);
hBuf := GlobalAlloc(GHND, nBufSize + 1);

try
Screen.Cursor := crHourGlass;
WritePos := 0;

if Assigned(RtfToForeign) then
begin
iSelStart := rtbApp.SelStart;
iSelLength := rtbApp.SelLength;

rtbApp.SelectAll; // This is done quick-and-dirty, but at the moment it works.

RTFToWrite := rtbApp.SelText;

rtbApp.SelStart := iSelStart;
rtbApp.SelLength := iSelLength;

WriteMax := length(RTFToWrite);

res := RtfToForeign(hFileName, nil, hBuf, hDesc, Writing);

RTFToWrite := '';

if res = 0 then
Result := True
else
Result := False;
end
else
begin
ShowMessage('Coult not export document');
Result := False;
end;

finally
GlobalFree(hBuf);
GlobalFree(hFileName);
GlobalFree(hDesc);
GlobalFree(hSubset);
Screen.Cursor := crDefault;
end;
end
else
Result := False;
end; }


// Try to obtain the WordPad directory.
function WordPadDir: string;
var
reg: TRegistry;
begin
reg := TRegistry.Create;

with reg do
try
RootKey := HKEY_LOCAL_MACHINE;

Result := '';

if OpenKey('/SOFTWARE/Microsoft/Windows/CurrentVersion/App Paths/WORDPAD.EXE', False) then
Result := ReadString('');

Result := ExtractFilePath(Result); // leaves the trailing backslash intact
finally
Free;
end;
end;


// The function "BuildFilterList" creates a string, that we can use as a filterlist
// in the dialog.
function BuildFilterList(ForImport: Boolean): string;
const
saImEx: array[False..True] of string = ('Export', 'Import');
var
regTxtConv: TRegistry;
regConvEntry: TRegistry;
slEntries: TStringList;
x,
i: integer;
extensions: string;
begin
regTxtConv := TRegistry.Create;
regConvEntry := TRegistry.Create;
slEntries := TStringList.Create;
Result := '';

with regTxtConv do
try
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey(MSTextConvKey + saImEx[ForImport], False) then
GetKeyNames(slEntries);
finally
CloseKey;
Free;
end;

regConvEntry.RootKey := HKEY_LOCAL_MACHINE;
try
for i := 0 to slEntries.Count-1 do
begin
if regConvEntry.OpenKey(MSTextConvKey + saImEx[ForImport] + '/' + slEntries, false) then
try
extensions := '*.' + regConvEntry.ReadString('Extensions');
x := pos(' ', extensions);
while x > 0 do
begin
delete(extensions, x, 1);
insert(';*.', extensions, x);
x := pos(' ', extensions);
end;
Result := Result + regConvEntry.ReadString('Name') + '|' + extensions + '|';
except
// catch a faulty key mismatch
end;
regConvEntry.CloseKey;
end;
finally
regConvEntry.Free;
slEntries.Free;
end;

// We can always im/export RTF, but there is no (trivial) converter for,
// but we do want to show it...
Result := 'Rich Text Format|*.rtf|' + Result;

// Since the WordPad converters are identically to the Office converters,
// we test if WordPad is installed and if so, if we did find Word and/or
// Write format. If not, add them.
// NB: these are valid for both im- and export.
if WordPadDir <> '' then
begin
if (pos('Windows Write', Result) = 0) and
(FileExists(WordPadDir + 'write32.wpc')) then
Result := 'Windows Write|*.wri|' + Result;
if FileExists(WordPadDir + 'mswd6_32.wpc') then // do we have W6 converter?
if (pos('Word 6.0/95', Result) = 0) then
// no office converter for W6, add Wordpad as default converter
Result := 'Word 6.0/95|*.doc|' + Result
else
// Since Office converter seems buggy, add Wordpad converter as default
Result := 'Word 95 via WordPad|*.doc|' + Result;
end;

if (Result <> '') and (Result[Length(Result)] = '|') then
Delete(Result, Length(Result), 1); // strip trailing |
end;


// The function "BuildConverterList" creates a stringlist, in which all available
// converters are stored.
function BuildConverterList(ForImport: Boolean; StrLst: TStringList): Boolean;
const
saImEx: array[False..True] of string = ('Export', 'Import');
var
regTxtConv: TRegistry;
regConvEntry: TRegistry;
slEntries: TStringList;
i: integer;
begin
if not Assigned(StrLst) then
begin
Result := False;
Exit; // StrLst must be initialized.
end;

regTxtConv := TRegistry.Create;
regConvEntry := TRegistry.Create;
slEntries := TStringList.Create;

try
with regTxtConv do
try
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey(MSTextConvKey + saImEx[ForImport], False) then
GetKeyNames(slEntries);
finally
CloseKey;
Free;
end;

regConvEntry.RootKey := HKEY_LOCAL_MACHINE;

try
for i := 0 to slEntries.Count-1 do
begin
if regConvEntry.OpenKey(MSTextConvKey + saImEx[ForImport] + '/' + slEntries, False) then
try
StrLst.Add(regConvEntry.ReadString('Name'));
except
// catch a faulty key mismatch
end;
regConvEntry.CloseKey;
end;
finally
regConvEntry.Free;
slEntries.Free;
end;

// We can always im/export RTF, but there is no (trivial) converter for,
// but we do want to show it...
StrLst.Insert(0, 'Rich Text Format');

// Since the WordPad converters are identically to the Office converters,
// we test if WordPad is installed and if so, if we did find Word and/or
// Write format. If not, add them.
// NB: these are valid for both im- and export.
if WordPadDir <> '' then
begin
if (pos('Windows Write', StrLst.Text) = 0) and
(FileExists(WordPadDir + 'write32.wpc')) then
StrLst.Insert(0, 'Windows Write');
if FileExists(WordPadDir + 'mswd6_32.wpc') then // do we have W6 converter?
if (pos('Word 6.0/95', StrLst.Text) = 0) then
// no office converter for W6, add Wordpad as default converter
StrLst.Insert(0, 'Word 6.0/95')
else
// Since Office converter seems buggy, add Wordpad converter as default
StrLst.Insert(0, 'Word 95 via WordPad');
end;

Result := True;
except
Result := False;
end;
end;


// The function "LoadConverter" loads a specific converter.
// We set the converter-functions as well.
function LoadConverter(Description: string; Import,boolExcel: boolean): HWND;
const
saImEx: array[false..true] of string = ('Export', 'Import');
var
regTxtConv: TRegistry;
regConvEntry: TRegistry;
slEntries: TStringList;
i: integer;
ConverterDLL: string;
begin
//regTxtConv := TRegistry.Create;
//regConvEntry := TRegistry.Create;

//slEntries := TStringList.Create;

Result := 0;
ConverterDLL := '';

{with regTxtConv do
try
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey(MSTextConvKey + saImEx[Import], false) then
GetKeyNames(slEntries);
finally
CloseKey;
Free;
end;

regConvEntry.RootKey := HKEY_LOCAL_MACHINE;

try
for i := 0 to slEntries.Count - 1 do
begin
regConvEntry.OpenKey(MSTextConvKey + saImEx[Import] + '/' + slEntries, False);
try
if regConvEntry.ReadString('Name') = Description then // we've found our dll
ConverterDLL := regConvEntry.ReadString('Path'); // get dll-location & name
except
// catch a faulty key mismatch to be able to continue
end;
regConvEntry.CloseKey;
end;
finally
regConvEntry.Free;
slEntries.Free;
end; }

{if ConverterDLL = '' then // It could be a Wordpad provided converter
begin
if pos('Word 6.0/95', Description) > 0 then
ConverterDLL := WordPadDir + 'mswd6_32.wpc'
else if pos('Windows Write', Description) > 0 then
ConverterDLL := WordPadDir + 'write32.wpc'
else if pos('WordPad', Description) > 0 then
ConverterDLL := WordPadDir + 'mswd6_32.wpc';
end;}

if Import then begin
if not boolExcel then
ConverterDLL := ExtractFilePath(Application.ExeName)+'textconv/Mswrd832.cnv'
else
ConverterDLL := ExtractFilePath(Application.ExeName)+'textconv/Excel32.cnv';
end;
//else
// ConverterDLL := ExtractFilePath(Application.ExeName)+'textconv/WNWRD232.CNV'
if ConverterDLL <> '' then
begin
if CurrentConverter <> 0 then // Unload the current loaded converter.
FreeLibrary(CurrentConverter);

Result := LoadLibrary(PChar(ConverterDLL)); // Load the new converter.

if Result <> 0 then
begin
CurrentConverter := Result; // Try to initialize our functions.
@InitConverter := GetProcAddress(Result, 'InitConverter32');
@IsFormatCorrect := GetProcAddress(Result, 'IsFormatCorrect32');
@ForeignToRtf := GetProcAddress(Result, 'ForeignToRtf32');
@RtfToForeign := GetProcAddress(Result, 'RtfToForeign32');
end;
end;

if Result = 0 then
begin // On failure, reset...
@InitConverter := nil;
@IsFormatCorrect := nil;
@ForeignToRtf := nil;
@RtfToForeign := nil;
end;
end;


// The function "StringToHGlobal" converts a string in HGLOBAL.
function StringToHGLOBAL(const str: string): HGLOBAL;
var
new: PChar;
begin
Result := GlobalAlloc(GHND, Length(str) * 2 + 1);

new := GlobalLock(Result);

if new <> nil then
strcopy(new, PChar(str));

GlobalUnlock(Result);
end;


// The function "IsKnownFormat" is used to check if a selected file
// matches a converter-type.
function IsKnownFormat(FileName: string): Boolean;
var
hFileName,
hDesc: HGLOBAL;
begin
Result := False;

if not (Assigned(InitConverter)
and LongBool(InitConverter(Application.Handle, PChar(Uppercase(Application.ExeName))))) then
ShowMessage('Please report: InitConverter failed') // Question only is: report to who?
else
begin
hFileName := StringToHGLOBAL(FileName);
hDesc := StringToHGLOBAL('');
try
if Assigned(IsFormatCorrect) then
Result := LongBool(IsFormatCorrect(hFileName, hDesc)); // hDesc gets like 'MSWord6'
finally
GlobalFree(hDesc);
GlobalFree(hFileName);
end;
end;
end;


// The function "Reading" is used by the converter-DLL's.
// It is used to import a foreign format to the RTF-format.
function Reading(CCH, nPercentComplete: integer): Integer; stdcall;
var
tempBuf: PChar;
begin
tempBuf := GlobalLock(hBuf);

if CCH > 0 then
begin
if mstream.Position + CCH >= mstream.Size then // enlarge stream
mstream.SetSize(mstream.size + (mstream.size div 4)); // by .25
mstream.Write(tempBuf^, CCH);
end;

GlobalUnlock(hBuf);

inc(BytesRead, CCH);

Result := 0; // everything OK
end;


// The function "Writing" is used by the converter-DLL's.
// It is used to export the RTF-format to a foreign format.
function Writing(flags, nPercentComplete: integer): Integer; stdcall;
var
tempBuf: PChar;
begin
tempBuf := GlobalLock(hBuf);

if tempBuf = nil then
begin
Result := -8; // out of memory?
Exit;
end;

if writePos < writeMax then
begin
if (writeMax - writePos) < nBufSize then
bytesRead := writeMax - writePos
else
bytesRead := nBufSize;

move(RTFToWrite[WritePos+1], tempBuf^, bytesRead);

inc(writePos, bytesRead);
end
else
bytesRead := 0;

GlobalUnlock(hBuf);
Result := bytesRead;
end;


procedure DoFreeConverters;
begin
if CurrentConverter <> 0 then
begin
FreeLibrary(CurrentConverter);
CurrentConverter := 0;
end;
end;

initialization

finalization
DoFreeConverters;

end.
其中 导出的函数不好使 我给屏蔽了 我只使用了Word和Excel两个
 
to jlutt-sadan:
非常感谢!!即使没有能够正确回答我的问题,但是你的参与已经让我很感动了。
现在我是想做个在电脑上不安装office,而能够阅读word,excel,powerpoint等Office系列
文件和pdf文件。目前我已经实现了能够不安装Adobe Acrobat而能够阅读pdf文件。
希望我们能够交流与讨论。
 
好像不行哦,pdf有个activex控件,所以可以
office系列估计不行,估计要用第三方控件
可以问问杀毒公司,这些公司都有分析office文件格式
 
>>目前我已经实现了能够不安装Adobe Acrobat而能够阅读pdf文件。
老大,把你的方法也公开行吗?
 
to donkey:
正与秋风萧萧所说的,pdf有个activex控件,只要注册这个控件,就可以在没有安装
Adobe Acrobat上阅读pdf文件了。
 
这样使用别人的文件合法吗?可能会引起法律纠纷哟.我记得有个控件是直接读写的,厉害.
但是不记得名字了
 
To donkey:
Adobe Acrobat阅读器就是免费的,它所带的控件当然也是免费的了。
就是微软什么东西都是收费的。
 
to c~c 上面的转换单元 不需要安装Office就可以转换的
你也可以直接把Office光盘上的TextConv目录的文件拷贝下来就可以使用
我已经测试过了的
 
To jlutt-sadan:
我已经试过了,是可以,不过如果word文档里有图片就不行的,你有什么方法吗?
 
有图片的时候 我没有在delphi自带的Richedit中测试过 只用过了
Richedit98,Rx,还有InfoPower的Richedit都是支持Ole的
但是它们对中文的处理不够,我最近使用的是RichView1.7带的RichViewEdit 不错
支持表格,图片,背景什么的,看源代码好像是画上去的 插入图片比上面的要快

 
To jlutt-sadan:
我是用RxRichEdit控件的,请问哪里有RichViewEdit控件下?
 
ftp://202.117.213.5/file/richview.rar
richview的官方网站有一个Actions控件包也Down下来装上
能省很多代码
 
可以用ADO访问Excel
 
To jlutt-sadan:
下载不了!
 
啊,留下你的邮箱 我给你发吧
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部