- XML Reference Guide
- Overview
- What Is XML?
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Table of Contents
- The Document Object Model
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- DOM and Java
- Informit Articles and Sample Chapters
- Books and e-Books
- Implementations
- DOM and JavaScript
- Using a Repeater
- Repeaters and XML
- Repeater Resources
- DOM and .NET
- Informit Articles and Sample Chapters
- Books and e-Books
- Documentation and Downloads
- DOM and C++
- DOM and C++ Resources
- DOM and Perl
- DOM and Perl Resources
- DOM and PHP
- DOM and PHP Resources
- DOM Level 3
- DOM Level 3 Core
- DOM Level 3 Load and Save
- DOM Level 3 XPath
- DOM Level 3 Validation
- Informit Articles and Sample Chapters
- Books and e-Books
- Documentation and Implementations
- The Simple API for XML (SAX)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- SAX and Java
- Informit Articles and Sample Chapters
- Books and e-Books
- SAX and .NET
- Informit Articles and Sample Chapters
- SAX and Perl
- SAX and Perl Resources
- SAX and PHP
- SAX and PHP Resources
- Validation
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Document Type Definitions (DTDs)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XML Schemas
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- RELAX NG
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Schematron
- Official Documentation and Implementations
- Validation in Applications
- Informit Articles and Sample Chapters
- Books and e-Books
- XSL Transformations (XSLT)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XSLT in Java
- Java in XSLT Resources
- XSLT and RSS in .NET
- XSLT and RSS in .NET Resources
- XSL-FO
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XPath
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XML Base
- Informit Articles and Sample Chapters
- Official Documentation
- XHTML
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XHTML 2.0
- Documentation
- Cascading Style Sheets
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XUL
- XUL References
- XML Events
- XML Events Resources
- XML Data Binding
- Informit Articles and Sample Chapters
- Books and e-Books
- Specifications
- Implementations
- XML and Databases
- Informit Articles and Sample Chapters
- Books and e-Books
- Online Resources
- Official Documentation
- SQL Server and FOR XML
- Informit Articles and Sample Chapters
- Books and e-Books
- Documentation and Implementations
- Service Oriented Architecture
- Web Services
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Creating a Perl Web Service Client
- SOAP::Lite
- Amazon Web Services
- Creating the Movable Type Plug-in
- Perl, Amazon, and Movable Type Resources
- Apache Axis2
- REST
- REST Resources
- SOAP
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- SOAP and Java
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- WSDL
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- UDDI
- UDDI Resources
- XML-RPC
- XML-RPC in PHP
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Ajax
- Asynchronous Javascript
- Client-side XSLT
- SAJAX and PHP
- Ajax Resources
- JSON
- Ruby on Rails
- Creating Objects
- Ruby Basics: Arrays and Other Sundry Bits
- Ruby Basics: Iterators and Persistence
- Starting on the Rails
- Rails and Databases
- Rails: Ajax and Partials
- Rails Resources
- Web Services Security
- Web Services Security Resources
- SAML
- Informit Articles and Sample Chapters
- Books and e-Books
- Specification and Implementation
- XML Digital Signatures
- XML Digital Signatures Resources
- XML Key Management Services
- Resources for XML Key Management Services
- Internationalization
- Resources
- Grid Computing
- Grid Resources
- Web Services Resource Framework
- Web Services Resource Framework Resources
- WS-Addressing
- WS-Addressing Resources
- WS-Notifications
- New Languages: XML in Use
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Google Web Toolkit
- GWT Basic Interactivity
- Google Sitemaps
- Google Sitemaps Resources
- Accessibility
- Web Accessibility
- XML Accessibility
- Accessibility Resources
- The Semantic Web
- Defining a New Ontology
- OWL: Web Ontology Language
- Semantic Web Resources
- Google Base
- Microformats
- StructuredBlogging
- Live Clipboard
- WML
- XHTML-MP
- WML Resources
- Google Web Services
- Google Web Services API
- Google Web Services Resources
- The Yahoo! Web Services Interface
- Yahoo! Web Services and PHP
- Yahoo! Web Services Resources
- eBay REST API
- WordML
- WordML Part 2: Lists
- WordML Part 3: Tables
- WordML Resources
- DocBook
- Articles
- Books and e-Books
- Official Documentation and Implementations
- XML Query
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XForms
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Resource Description Framework (RDF)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Topic Maps
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation, Implementations, and Other Resources
- Rich Site Summary (RSS)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Simple Sharing Extensions (SSE)
- Atom
- Podcasting
- Podcasting Resources
- Scalable Vector Graphics (SVG)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- OPML
- OPML Resources
- Summary
- Projects
- JavaScript TimeTracker: JSON and PHP
- The Javascript Timetracker
- Refactoring to Javascript Objects
- Creating the Yahoo! Widget
- Web Mashup
- Google Maps
- Indeed Mashup
- Mashup Part 3: Putting It All Together
- Additional Resources
- Frequently Asked Questions About XML
- What's XML, and why should I use it?
- What's a well-formed document?
- What's the difference between XML and HTML?
- What's the difference between HTML and XHTML?
- Can I use XML in a browser?
- Should I use elements or attributes for my document?
- What's a namespace?
- Where can I get an XML parser?
- What's the difference between a well-formed document and a valid document?
- What's a validating parser?
- Should I use DOM or SAX for my application?
- How can I stop a SAX parser before it has parsed the entire document?
- 2005 Predictions
- 2006 Predictions
- Nick's Book Picks
At this point I've talked about general WordProcessingML documents, as well as styling and creating lists, so I'm going to give you one more bit of formatting text using WordML before we move on to something else. We're going to talk about tables.
In WordML, as in HTML, a table is just a collection of rows, each of which has one or more "cells". Viewed as a whole, the cells make up columns. As a developer (or an author, I suppose) you have the option to combine (or as we call it in HTML, "span") cells. In Word, this is called merging.
But before we get that far, let's look at the basic table itself. We can go ahead and add a table to the document we've been using:
... <w:tbl> <w:tr> <w:tc> <w:p></w:p> </w:tc> <w:tc> <w:p> <w:r> <w:t>WordML</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:p> <w:r> <w:t>HTML</w:t> </w:r> </w:p> </w:tc> </w:tr> <w:tr> <w:tc> <w:p> <w:r> <w:t>Table Caption</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:p> <w:r> <w:t></w:t> </w:r> </w:p> </w:tc> <w:tc> <w:p> <w:r> <w:t>X</w:t> </w:r> </w:p> </w:tc> </w:tr> ... </w:tbl> </w:body> </w:wordDocument>
Notice the structure. We have a tbl
element to denote the actual table. A tr
element represents each table row, with each table cell represented by a tc
element. Within each
table cell, content looks just like it does elsewhere in the document; a p
aragraph contains a
r
un of t
ext. You can see the results in Figure 1:
You can style the actual text the same way you'd style it outside the document:
... <w:tr> <w:tc> <w:p></w:p> </w:tc> <w:tc> <w:p> <w:pPr> <w:jc w:val="center"/> </w:pPr> <w:r> <w:rPr> <w:b/> </w:rPr> <w:t>WordML</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:p> <w:pPr> <w:jc w:val="center"/> </w:pPr> <w:r> <w:rPr> <w:b/> </w:rPr> <w:t>HTML</w:t> </w:r> </w:p> </w:tc> </w:tr> <w:tr> ...
As you can see in Figure 2, you can't quite tell that the text is centered, because the table's too small.
To remedy that problem, we can set the width of the table using the tblW
element:
... <w:tbl> <w:tblPr> <w:tblW w:w="7200" w:type="dxa"/> <w:jc w:val="center"/> </w:tblPr> <w:tr> <w:tc> <w:p></w:p> </w:tc> ...
In this case, we're setting a property for the table itself, so we set it in the tblPr
element.
We're setting the value in "twips", or twentieths of a point. In other words, 1/1440th of an inch.
The type
, in this case, represents the units, and dxa
represents twips. You
can see the results in Figure 3:
We can also set properties on individual rows or cells. For example, we can set the height of the first row:
... <w:tbl> <w:tblPr> <w:tblW w:w="7200" w:type="dxa"/> <w:jc w:val="center"/> </w:tblPr> <w:tr> <w:trPr> <w:trHeight w:val="620"/> </w:trPr> <w:tc> <w:p></w:p> </w:tc> ...
You can see the results in Figure 4:
As in HTML, we can also combine tables vertically or horizontally, but unlike in HTML, the affected cells are not actually moved, but rather hidden. Consider, for example, this basic table:
<w:tbl> <w:tblPr> <w:tblW w:w="3600" w:type="dxa"/> </w:tblPr> <w:tr> <w:tc> <w:p> <w:r> <w:t>1</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:p> <w:r> <w:t>2</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:p> <w:r> <w:t>3</w:t> </w:r> </w:p> </w:tc> </w:tr> <w:tr> <w:tc> <w:p> <w:r> <w:t>4</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:p> <w:r> <w:t>5</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:p> <w:r> <w:t>6</w:t> </w:r> </w:p> </w:tc> </w:tr> <w:tr> <w:tc> <w:p> <w:r> <w:t>7</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:p> <w:r> <w:t>8</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:p> <w:r> <w:t>9</w:t> </w:r> </w:p> </w:tc> </w:tr> </w:tbl>
It's a simple grid of numbers, as you can see in Figure 5:
In order to "merge" cells, we can do a horizontal merge, or a vertical merge. Let's start with a horizontal merge:
<w:tbl> <w:tblPr> <w:tblW w:w="3600" w:type="dxa"/> </w:tblPr> <w:tr> <w:tc> <w:p> <w:r> <w:t>1</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:tcPr> <w:hmerge w:val="restart"/> </w:tcPr> <w:p> <w:r> <w:t>2</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:tcPr> <w:hmerge/> </w:tcPr> <w:p> <w:r> <w:t>3</w:t> </w:r> </w:p> </w:tc> </w:tr> ...
In this case, we're starting the merge in cell number 2, as indicated by the
val="restart"
attribute. Each cell that's part of this merge (in this case, cell number 3)
includes the hmerge
element. When Word displays the table, the cells are merged,
but you'll notice that the content of cell number 3 is missing from the display, as you can see in Figure 6:
The same thing happens with a vertical merge:
<w:tbl> <w:tblPr> <w:tblW w:w="3600" w:type="dxa"/> </w:tblPr> <w:tr> <w:tc> <w:tcPr> <w:vmerge w:val="restart"/> </w:tcPr> <w:p> <w:r> <w:t>1</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:tcPr> <w:hmerge w:val="restart"/> </w:tcPr> <w:p> <w:r> <w:t>2</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:tcPr> <w:hmerge/> </w:tcPr> <w:p> <w:r> <w:t>3</w:t> </w:r> </w:p> </w:tc> </w:tr> <w:tr> <w:tc> <w:tcPr> <w:vmerge/> </w:tcPr> <w:p> <w:r> <w:t>4</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:p> <w:r> <w:t>5</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:p> <w:r> <w:t>6</w:t> </w:r> </w:p> </w:tc> </w:tr> <w:tr> <w:tc> <w:tcPr> <w:vmerge/> </w:tcPr> <w:p> <w:r> <w:t>7</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:p> <w:r> <w:t>8</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:p> <w:r> <w:t>9</w:t> </w:r> </w:p> </w:tc> </w:tr> </w:tbl> ...
You can see the result in Figure 7:
Of course, there's a lot more to displaying tables in Word, but this should be enough to get you started. Check out the Resources for links to more information.