Winsoft’s Direct Office is a nice third party solution which bypasses the middle-man – namely Word – to create, open, and save DOCX documents.
DOCX is a standardized file format. It can be read using Libre Office, SoftMaker’s TextMaker and on-line Google Docs.
Installation
Steps:
- Download the trial version
- Unzip doffice.zip
- Find Winsoft.DirectOffice.dll in .\doffice\Delphi\ along with the corresponding licenses in \doffice\Licenses\
DirectOffice vs Word COM API: Less code
Using Direct Office, you can reduce the amount of steps, bloat and coding to access Word Documents. Take for example, a simple operation of opening a document:
Direct Office | Microsoft Word COM API | |
Create Document | Check if Word is Open or Not. If Word is not open, launch Word. | |
– | Check if Document is Open or Not. If Document is not Open, Open it. | |
– | Check if View is in correct mode (Print View, Draft View…) If not in correct view, change it accordingly. | |
Append Page | Insert Page |
Using the Word COM API, this is at least 35 lines of code. This includes exception checks, querying Word, if Word Document is already opened or not.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
uses ComObj, ActiveX, Word2000, ShellApi; ... var MSWord: Variant; Doc_: variant; begin try // Check if Word is already opened? MsWord := GetActiveOleObject('Word.Application'); except try MsWord := CreateOleObject('Word.Application'); MsWord.Visible := True; except Exception.Create('Error'); end; end; // Enumate... is Document already opened? var iNo, iCount: integer; var sFilename: string; var bExists: boolean; sFilename := 'yourdoc.doc'; bExists := false; iCount := MsWord.Documents.Count_; for iNo := 1 to iCount do begin begin if MsWord.Documents(iNo).Path = sFilename then begin Doc_ := MsWord.Documents(iNo); bExists := true; end; end; end; if not bExists then begin Doc_ := MsWord.Documents; Doc_.Open(sFilename); end; |
In DirectOffice, access to Word Documents is less than 4 lines of code on average.
1 2 3 4 |
var WordDocument: WordprocessingDocument; begin WordDocument := CoWordprocessingDocumentClass.Create('yourdocument.docx', WordprocessingDocumentType_Document); end; |
DirectOffice vs Word COM API: Speed
What if I told you, you could create and save Word Documents between 110% to 500% faster than using Word itself?
1 2 3 4 5 6 |
for iNo := 1 to 10000 do begin para1 := Doc_.Content.Paragraphs.Add(EmptyParam); para1.Range.Text := 'Hello World'; para1.Range.InsertParagraphAfter; end; |
The equivalent in DirectOffice:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
// create body Body := CoBody.Create; Document.AppendChild(Body as _OpenXmlElement); // create paragraph Paragraph := CoDocumentFormat_OpenXml_Wordprocessing_Paragraph.Create; Body.AppendChild(Paragraph as _OpenXmlElement); // create run for iNo := 1 to 10000 do begin Run := CoDocumentFormat_OpenXml_Wordprocessing_Run.Create; Paragraph.AppendChild(Run as _OpenXmlElement); // create text Text := CoDocumentFormat_OpenXml_Wordprocessing_Text.Create; Text.Text := 'Hello, world!'; Run.AppendChild(Text as _OpenXmlElement); end; |
The estimated time to run the above code in Word for a lenghtly document, is ~ 3 minutes. If you were doing data-processing on a large document, it could possibly take upwards between 30 minutes to days.
The estimated time to run the above code in Direct Office is in seconds.
If your customer does not have Microsoft Word installed, or using a competing Word Processor, such as Google Docs or Libre Office, your applications built using DirectOffice can still function. Prior installation of Office or Word is not necessary.
Winsoft sells the full-version at the website, which can open Word, Excel and PowerPoint documents. Your customer’s time is important. Which solution will you choose?
- Works with: Delphi, C++Builder, VCL
- Works on: Windows 32-bit, Windows 64-bit, Web
Head over and check out the full WINSOFT Direct Office library for Delphi and C++Builder
Like what you see? You can get Direct Office and over 100 other fantastic WinSoft components with our Enterprise Component Pack. For a limited time, when you purchase RAD Studio Enterprise or Architect Edition at special Upgrade Pricing, you will also get this package of third-party software worth over $13,000, including the full WinSoft Component Library, at NO EXTRA COST! Step up to RAD Studio 10.4 today!
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition