Word Hacks [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Word Hacks [Electronic resources] - نسخه متنی

Andrew Savikas

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید







Hack 91 Create a Word Document in Notepad

This hack demonstrates how you can use simple
XML files to create Word documents.

If you save one of your Word
documentseven a very simple one with just a line or two of
textin XML format, then open it in a standard text editor such
as Notepad, you'll see that the file contains much
more than just the text you typed.

Fortunately, Word can fill in most of that information if
it's missing, so you don't need to
be quite so verbose when creating XML documents meant to be opened in
Word.

For example, open Notepad or another standard text editor and type
the following:

<?xml version="1.0"?>
<?mso-application prog?>
<w:wordDocument
xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">
<w:body>
<w:p>
<w:r>
<w:t>Hello, World!</w:t>
</w:r>
</w:p>
</w:body>
</w:wordDocument>

The w:body element contains the body of the
document; the w:p element stands for
"paragraph," the
w:r element stands for
"run," and the
w:t element contains text in the document.

Now save the file as Hello.xml. If you look at
the file in Windows Explorer (or from Notepad's Save
As dialog box), you'll see that it has a special
icona combination of the icon used for XML files and the icon
used for Word documents, as shown in Figure 10-3.


Figure 10-3. Windows recognizes the file as an XML file meant for Word

If you then double-click the file in Windows Explorer, Word launches
rather than your default XML viewer (usually Internet Explorer).
Figure 10-4 shows the Hello.xml
document after Word has opened it. If you save the file from within
Word, then open it in Notepad, you'll see that Word
has added quite a bit of additional information (check out Figure 10-6 in [Hack #92] to
see the information Word inserts).


Figure 10-4. Your XML document opens in Word

The reason the file opened in Word, and not in Internet Explorer (or
whatever program usually opens XML files on your system), is the
following line included in the file:

<?mso-application prog?>

This processing instruction (PI)
associates the XML
document with Word. It is also used for other applications in
Microsoft Office: the progid pseudoattribute can
have Excel.Sheet and
InfoPath.Document as values, for example.

As you can see, there's nothing fancy here; Word
used the Normal paragraph style to provide all the formatting
information. However, this simple example shows how you can use plain
text to create fully functional Word documents. See [Hack #94]
for a more detailed example of using XML to create Word documents.

Evan Lenz


/ 162