incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From devin...@apache.org
Subject svn commit: r795290 - in /websites/production/odftoolkit: ./ content/odftoolkit/simple/demo/demo4.html
Date Mon, 05 Sep 2011 03:01:16 GMT
Author: devinhan
Date: Mon Sep  5 03:01:15 2011
New Revision: 795290

Log:
Publishing merge to odftoolkit site by devinhan

Modified:
    websites/production/odftoolkit/   (props changed)
    websites/production/odftoolkit/content/odftoolkit/simple/demo/demo4.html

Propchange: websites/production/odftoolkit/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Sep  5 03:01:15 2011
@@ -1 +1 @@
-/websites/staging/odftoolkit/trunk:794771-795175
+/websites/staging/odftoolkit/trunk:794771-795289

Modified: websites/production/odftoolkit/content/odftoolkit/simple/demo/demo4.html
==============================================================================
--- websites/production/odftoolkit/content/odftoolkit/simple/demo/demo4.html (original)
+++ websites/production/odftoolkit/content/odftoolkit/simple/demo/demo4.html Mon Sep  5 03:01:15
2011
@@ -78,426 +78,129 @@
   <div id="contenta">
   
     
-    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<link rel="stylesheet" href="../images/style.css" type="text/css" />
-
-<link type="text/css" rel="stylesheet" href="styles/shCoreEclipse.css"/>
-
-<title>Demos - SimpleODF</title>
-<style type="text/css">
-<!--
-.STYLE1 {
-    color: #FFFFFF;
-    font-size: 24px;
-}
-.STYLE2 {font-size: 32px}
-.STYLE3 {font-size: 16px}
-.STYLE4 {font-size: 36px}
--->
-    </style>
-    <script type="text/javascript">
-
-var _gaq = _gaq || [];
-  _gaq.push(['_setAccount', 'UA-22366020-1']);
-  _gaq.push(['_trackPageview']);
-
-(function() {
-    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
-    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
-    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
-  })();
-
-</script>
-</head>
-<body>
-<div id="page" align="center">
-  <div id="content" style="width:920px" class="contentpanel">
-    <div id="topheader">
-      <div class="topright"> </div>
-    </div>
-    <div id="menu">
-      <div align="left" class="smallwhitetext"> <a href="../index.html" class="home">
</a> <a href="../downloads.html" class="download"></a> <a href="../documents.html"
class="document"></a> <a href="../demo/index.html" class="sample"> </a>
</div>
-    </div>
-    <div id="subcontent" align ="left">
-        <div align="left" class="titletext"> <span >
-        <a href="index.html">Simple Demos<a> > 
-        <a href="demo4.html">Demo 3: List and Table Conversion<a>
-        </span> 
-        </div>
-
-<!---------------------------------------------------------------------------------------------------->

-<div class="contenttitle">
-
-<a name="overview">Overview</a>
-
-</div>
-
-<div class="bodytext">
-
-<p> Starting in version 0.4, we have added methods to support bullet, numbered and
-
-image lists to the Simple API. This includes frequently used features
-
-for processing lists and list item. This demo is designed to show the power
-
-of List API and help you learn how to use it. <br/> <br/> This demo shows
-
-how to convert between a nested List and Table. As you can see in the
-
-following two pictures, on the left we have a simple outline of a corporate
-
-hierarchy. There are four departments in this company.  Each department has
-
-several managers and each manager has several reporting staff.  Now we want
-
-to change this list to a table, just like the picture on the right
-
-shows.<br/> <br/> &nbsp;&nbsp;&nbsp;<img
-
-src="image/demo4_organization_list.png"><br/> <br/> However,
-
-sometimes we want to convert in the opposite direction, from a table to a
-
-list. Take the following two pictures as example.  The left one is table of
-
-country calling codes, which includes the codes of countries from different
-
-continents. Suppose you want to convert this table representation into a
-
-nested list.  The picture on the right shows the conversion result. The
-
-first level list show the continent names and the second level list show
-
-the countries and their calling codes.<br/> <br/> <img
-
-src="image/demo4_code_list.png" ><br/> <br/> You can see similar
-
-functionality in office software, such as selective copy and paste. In the
-
-next section, I will show how easy to do these kinds of conversions using
-
-the Simple API.
-
-</p>
-
-</div>
-
-<hr/>
-
-<div class="contenttitle">
-
-<a name="codeintroduction">Code Introduction</a>
-
-</div>
-
-<div class="bodytext">
-
-<p>
-
-Let's have a look at the main method. It will help us get an overview of
-
-this demo. First, the list data text document, "ListTable.odt" and table
-
-data spreadsheet document "TableList.ods" are loaded. Secondly, we use the
-
-list iteration function to get all of the lists in the text document and
-
-invoke the method <code>convertFromListToTable</code> to convert each of them
to a table.
-
-Finally, we get the data table from "TableList.ods" and invoke the method
-
-<code>convertFromTableToList</code> to convert this table to a list. All of the
updated
-
-documents are saved as new files. You can open them and see the
-
-conversion results.
-
-</p>
-
-<!--java code-->
-
-<pre class="brush:java;">
-
-public static void main(String[] args) {
-
-try {
-
-TextDocument textDoc = TextDocument.loadDocument("ListTable.odt");
-
-SpreadsheetDocument spreadsheetDoc = SpreadsheetDocument.loadDocument("TableList.ods");
-
-// covert list in text document to spreadsheet table
-
-Iterator<list> listIterator = textDoc.getListIterator();
-
-int i = 1;
-
-String[] tableLabel = { "DEPARTMENT", "MANAGER", "EMPLOYEE" };
-
-while (listIterator.hasNext()) {
-
-List list = listIterator.next();
-
-Table newTable = Table.newTable(spreadsheetDoc);
-
-for (int columnIndex = 0; columnIndex < tableLabel.length; columnIndex++) {
-
-newTable.getCellByPosition(columnIndex, 0).setStringValue(tableLabel[columnIndex]);
-
-}
-
-newTable.setTableName("ListTable" + (i++));
-
-convertFromListToTable(list, newTable, 0, 1);
-
-}
-
-spreadsheetDoc.save("TableListUpdate.ods");
-
-// covert table in spreadsheet to list in text document
-
-Table sheet1 = spreadsheetDoc.getTableByName("Sheet1");
-
-textDoc.newParagraph("ListConvertedFromTable");
-
-List newList = textDoc.addList();
-
-convertFromTableToList(sheet1, newList, 0, 0, sheet1.getColumnCount() - 1, sheet1.getRowCount()
- 1);
-
-textDoc.save("ListTableUpdate.odt");
-
-} catch (Exception e) {
-
-e.printStackTrace();
-
-}
-
-}
-
-</pre>
-
+    <p><strong><a href="index.html">Demos</a></strong> &gt;
<strong>List and Table Conversion</strong> <br />
 </p>
-
-<p>
-
-In the following two sections, I will review the implementation of the methods
-
-<code>convertFromListToTable</code> and <code>convertFromTableToList</code>.
<br/><br/>
-
-<b>Convert from List to Table</b>
-
-<br/><br/>
-
-This is a recursive method, similar to a depth-first tree traversal. You
-
-determine the paste cell address by <code>startColumn</code> and <code>startRow</code>.
First, all of the
-
-items in the list are retrieved. Second, each list item is converted to table
-
-cell. Its text content is extracted and set as the cell's display text. If the
-
-item has a sub list, its sub list is also handled the same as the parent list.
-
-<br/><br/> After all of the items are converted to cells, we invoke
-
-<code>CellRange.merge()</code> to merge the blank cells. The generation document
appears just
-
-like the picture shown earlier.<br/>
-
-<!--java code-->
-
-<pre class="brush:java;">
-
-private static int convertFromListToTable(List list, Table table, int startColumn, int startRow)
{
-
-java.util.List<listitem> items = list.getItems();
-
-int newItemCount = startRow;
-
-for (ListItem item : items) {
-
-Cell cell = table.getCellByPosition(startColumn, newItemCount);
-
-cell.setStringValue(item.getTextContent());
-
-cell.setVerticalAlignment(VerticalAlignmentType.MIDDLE);
-
-Iterator<list> listIterator = item.listIterator();
-
-startRow = newItemCount;
-
-while (listIterator.hasNext()) {
-
-List subList = listIterator.next();
-
-newItemCount = convertFromListToTable(subList, table, startColumn + 1, newItemCount);
-
-}
-
-// merge
-
-CellRange cellRange = table.getCellRangeByPosition(startColumn, startRow, startColumn, newItemCount);
-
-cellRange.merge();
-
-newItemCount++;
-
-}
-
-if (list.size() > 0) {
-
-return newItemCount - 1;
-
-} else {
-
-return startRow;
-
-}
-
-}
-
-</pre>
-
+<p><strong>Overview</strong><br />
 </p>
-
-<br/>
-
-<p>
-
-<b>Convert from Table to List</b>
-
-<br/><br/>
-
-This is also a recursive method. You determine the conversion range of the table
-
-by <code>startColumn</code>, <code>startRow</code>, <code>endColumn</code>
and <code>endRow</code>. First, every cell in the
-
-selected range is retrieved by <code>Table.getCellByPosition</code>. Next, a
list item is
-
-created to store the cell display text. If the <code>rowSpannedNumber > 1</code>,
that means
-
-this item has a sub list. Parts of the cells in the right columns of this cell
-
-become the items of the sub list. They are also determined by recursive calls to
-
-<code>convertFromTableToList</code>. If the <code>rowSpannedNumber = 1</code>,
there is no need to create
-
-a sub list, all of the content in the right cells is just added to this
-
-item.<br/>
-
-<!--java code-->
-
-<pre class="brush:java;">
-
-private static void convertFromTableToList(Table table, List list, int startColumn, int startRow,
int endColumn,
-
-int endRow) {
-
-while (startRow <= endRow) {
-
-Cell cell = table.getCellByPosition(startColumn, startRow);
-
-int rowSpannedNumber = cell.getRowSpannedNumber();
-
-String cellText = cell.getDisplayText();
-
-if (!"".equals(cellText)) {
-
-ListItem item = list.addItem(cellText);
-
-int columnSpannedNumber = cell.getColumnSpannedNumber();
-
-int newStartColumn = startColumn + columnSpannedNumber;
-
-if (newStartColumn <= endColumn) {
-
-if (rowSpannedNumber > 1) {
-
-List subList = item.addList();
-
-convertFromTableToList(table, subList, newStartColumn, startRow, endColumn, startRow
-
-+ rowSpannedNumber - 1);
-
-} else {
-
-int tmpStartColumn = newStartColumn;
-
-while (tmpStartColumn <= endColumn) {
-
-cell = table.getCellByPosition(tmpStartColumn, startRow);
-
-cellText = cell.getDisplayText();
-
-if (!"".equals(cellText)) {
-
-item.setTextContent(item.getTextContent() + "|" + cellText);
-
-}
-
-tmpStartColumn += cell.getColumnSpannedNumber();
-
-}
-
-}
-
-}
-
-}
-
-startRow += rowSpannedNumber;
-
-}
-
-}
-
-</pre>
-
+<p>Starting in version 0.4, we have added methods to support bullet, numbered and image
lists to the Simple API. This includes frequently used features  for processing lists and
list item. This demo is designed to show the power of List API and help you learn how to use
it.<br />
 </p>
+<p>This demo shows how to convert between a nested List and Table. As you can see in
the following two pictures, on the left we have a simple outline of a corporate 
+hierarchy. There are four departments in this company.  Each department has several managers
and each manager has several reporting staff.  Now we want 
+to change this list to a table, just like the picture on the right shows.<br />
+</p>
+<p><img alt="image1" src="image/demo4_organization_list.png" /><br />
+</p>
+<p>However, sometimes we want to convert in the opposite direction, from a table to
a list. Take the following two pictures as example. The left one is table of country calling
codes, which includes the codes of countries from different continents. Suppose you want to
convert this table representation into a nested list.  The picture on the right shows the
conversion result. The first level list show the continent names and the second level list
show the countries and their calling codes.  <br />
+</p>
+<p><img alt="image2" src="image/demo4_code_list.png" />   <br />
+</p>
+<p>You can see similar functionality in office software, such as selective copy and
paste. In the next section, I will show how easy to do these kinds of conversions using the
Simple API. </p>
+<p><strong>Code Introduction</strong></p>
+<p>Let's have a look at the main method. It will help us get an overview of this demo.
First, the list data text document, "ListTable.odt" and table data spreadsheet document "TableList.ods"
are loaded. Secondly, we use the list iteration function to get all of the lists in the text
document and invoke the method <code>convertFromListToTable</code> to convert
each of them to a table. Finally, we get the data table from "TableList.ods" and invoke the
method <code>convertFromTableToList</code> to convert this table to a list. All
of the updated documents are saved as new files. You can open them and see the conversion
results. <br />
+</p>
+<div class="codehilite"><pre><span class="n">public</span> <span
class="n">static</span> <span class="n">void</span> <span class="n">main</span><span
class="p">(</span><span class="n">String</span><span class="o">[]</span>
<span class="n">args</span><span class="p">)</span> <span class="p">{</span>
+    <span class="n">try</span> <span class="p">{</span>
+        <span class="n">TextDocument</span> <span class="n">textDoc</span>
<span class="o">=</span> <span class="n">TextDocument</span><span
class="o">.</span><span class="n">loadDocument</span><span class="p">(</span><span
class="s">&quot;ListTable.odt&quot;</span><span class="p">);</span>
+        <span class="n">SpreadsheetDocument</span> <span class="n">spreadsheetDoc</span>
<span class="o">=</span> <span class="n">SpreadsheetDocument</span><span
class="o">.</span><span class="n">loadDocument</span><span class="p">(</span><span
class="s">&quot;TableList.ods&quot;</span><span class="p">);</span>
+        <span class="sr">//</span> <span class="n">covert</span>
<span class="n">list</span> <span class="n">in</span> <span class="n">text</span>
<span class="n">document</span> <span class="n">to</span> <span
class="n">spreadsheet</span> <span class="n">table</span>
+        <span class="n">Iterator</span><span class="sr">&lt;list&gt;</span>
<span class="n">listIterator</span> <span class="o">=</span> <span
class="n">textDoc</span><span class="o">.</span><span class="n">getListIterator</span><span
class="p">();</span>
+        <span class="nb">int</span> <span class="n">i</span> <span
class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+        <span class="n">String</span><span class="o">[]</span> <span
class="n">tableLabel</span> <span class="o">=</span> <span class="p">{</span>
<span class="s">&quot;DEPARTMENT&quot;</span><span class="p">,</span>
<span class="s">&quot;MANAGER&quot;</span><span class="p">,</span>
<span class="s">&quot;EMPLOYEE&quot;</span> <span class="p">};</span>
+        <span class="k">while</span> <span class="p">(</span><span
class="n">listIterator</span><span class="o">.</span><span class="n">hasNext</span><span
class="p">())</span> <span class="p">{</span>
+            <span class="n">List</span> <span class="n">list</span>
<span class="o">=</span> <span class="n">listIterator</span><span
class="o">.</span><span class="k">next</span><span class="p">();</span>
+            <span class="n">Table</span> <span class="n">newTable</span>
<span class="o">=</span> <span class="n">Table</span><span class="o">.</span><span
class="n">newTable</span><span class="p">(</span><span class="n">spreadsheetDoc</span><span
class="p">);</span>
+            <span class="k">for</span> <span class="p">(</span><span
class="nb">int</span> <span class="n">columnIndex</span> <span class="o">=</span>
<span class="mi">0</span><span class="p">;</span> <span class="n">columnIndex</span>
<span class="o">&lt;</span> <span class="n">tableLabel</span><span
class="o">.</span><span class="nb">length</span><span class="p">;</span>
<span class="n">columnIndex</span><span class="o">++</span><span
class="p">)</span> <span class="p">{</span>
+                <span class="n">newTable</span><span class="o">.</span><span
class="n">getCellByPosition</span><span class="p">(</span><span class="n">columnIndex</span><span
class="p">,</span> <span class="mi">0</span><span class="p">)</span><span
class="o">.</span><span class="n">setStringValue</span><span class="p">(</span><span
class="n">tableLabel</span><span class="p">[</span><span class="n">columnIndex</span><span
class="p">]);</span>
+            <span class="p">}</span>
+            <span class="n">newTable</span><span class="o">.</span><span
class="n">setTableName</span><span class="p">(</span><span class="s">&quot;ListTable&quot;</span>
<span class="o">+</span> <span class="p">(</span><span class="n">i</span><span
class="o">++</span><span class="p">));</span>
+            <span class="n">convertFromListToTable</span><span class="p">(</span><span
class="n">list</span><span class="p">,</span> <span class="n">newTable</span><span
class="p">,</span> <span class="mi">0</span><span class="p">,</span>
<span class="mi">1</span><span class="p">);</span>
+        <span class="p">}</span>
+        <span class="n">spreadsheetDoc</span><span class="o">.</span><span
class="n">save</span><span class="p">(</span><span class="s">&quot;TableListUpdate.ods&quot;</span><span
class="p">);</span>
+        <span class="sr">//</span> <span class="n">covert</span>
<span class="n">table</span> <span class="n">in</span> <span class="n">spreadsheet</span>
<span class="n">to</span> <span class="n">list</span> <span class="n">in</span>
<span class="n">text</span> <span class="n">document</span>
+        <span class="n">Table</span> <span class="n">sheet1</span>
<span class="o">=</span> <span class="n">spreadsheetDoc</span><span
class="o">.</span><span class="n">getTableByName</span><span class="p">(</span><span
class="s">&quot;Sheet1&quot;</span><span class="p">);</span>
+        <span class="n">textDoc</span><span class="o">.</span><span
class="n">newParagraph</span><span class="p">(</span><span class="s">&quot;ListConvertedFromTable&quot;</span><span
class="p">);</span>
+        <span class="n">List</span> <span class="n">newList</span>
<span class="o">=</span> <span class="n">textDoc</span><span class="o">.</span><span
class="n">addList</span><span class="p">();</span>
+        <span class="n">convertFromTableToList</span><span class="p">(</span><span
class="n">sheet1</span><span class="p">,</span> <span class="n">newList</span><span
class="p">,</span> <span class="mi">0</span><span class="p">,</span>
<span class="mi">0</span><span class="p">,</span> <span class="n">sheet1</span><span
class="o">.</span><span class="n">getColumnCount</span><span class="p">()</span>
<span class="o">-</span> <span class="mi">1</span><span class="p">,</span>
<span class="n">sheet1</span><span class="o">.</span><span class="n">getRowCount</span><span
class="p">()</span> <span class="o">-</span> <span class="mi">1</span><span
class="p">);</span>
+        <span class="n">textDoc</span><span class="o">.</span><span
class="n">save</span><span class="p">(</span><span class="s">&quot;ListTableUpdate.odt&quot;</span><span
class="p">);</span>
+    <span class="p">}</span> <span class="n">catch</span> <span
class="p">(</span><span class="n">Exception</span> <span class="n">e</span><span
class="p">)</span> <span class="p">{</span>
+        <span class="n">e</span><span class="o">.</span><span
class="n">printStackTrace</span><span class="p">();</span>
+    <span class="p">}</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p>In the following two sections, I will review the implementation of the methods <code>convertFromListToTable</code>
and <code>convertFromTableToList</code>.  <br />
+</p>
+<p><strong><em>Convert from List to Table</em></strong></p>
+<p>This is a recursive method, similar to a depth-first tree traversal. You determine
the paste cell address by <code>startColumn</code> and <code>startRow</code>.
First, all of the items in the list are retrieved. Second, each list item is converted to
table cell. Its text content is extracted and set as the cell's display text. If the item
has a sub list, its sub list is also handled the same as the parent list. After all of the
items are converted to cells, we invoke <code>CellRange.merge()</code> to merge
the blank cells. The generation document appears just like the picture shown earlier.  <br
/>
+</p>
+<div class="codehilite"><pre><span class="n">private</span> <span
class="n">static</span> <span class="nb">int</span> <span class="n">convertFromListToTable</span><span
class="p">(</span><span class="n">List</span> <span class="n">list</span><span
class="p">,</span> <span class="n">Table</span> <span class="n">table</span><span
class="p">,</span> <span class="nb">int</span> <span class="n">startColumn</span><span
class="p">,</span> <span class="nb">int</span> <span class="n">startRow</span><span
class="p">)</span> <span class="p">{</span>
+    <span class="n">java</span><span class="o">.</span><span class="n">util</span><span
class="o">.</span><span class="n">List</span><span class="sr">&lt;listitem&gt;</span>
<span class="n">items</span> <span class="o">=</span> <span class="n">list</span><span
class="o">.</span><span class="n">getItems</span><span class="p">();</span>
+    <span class="nb">int</span> <span class="n">newItemCount</span>
<span class="o">=</span> <span class="n">startRow</span><span class="p">;</span>
+    <span class="k">for</span> <span class="p">(</span><span class="n">ListItem</span>
<span class="n">item</span> <span class="p">:</span> <span class="n">items</span><span
class="p">)</span> <span class="p">{</span>
+        <span class="n">Cell</span> <span class="n">cell</span> <span
class="o">=</span> <span class="n">table</span><span class="o">.</span><span
class="n">getCellByPosition</span><span class="p">(</span><span class="n">startColumn</span><span
class="p">,</span> <span class="n">newItemCount</span><span class="p">);</span>
+        <span class="n">cell</span><span class="o">.</span><span
class="n">setStringValue</span><span class="p">(</span><span class="n">item</span><span
class="o">.</span><span class="n">getTextContent</span><span class="p">());</span>
+        <span class="n">cell</span><span class="o">.</span><span
class="n">setVerticalAlignment</span><span class="p">(</span><span
class="n">VerticalAlignmentType</span><span class="o">.</span><span
class="n">MIDDLE</span><span class="p">);</span>
+        <span class="n">Iterator</span><span class="sr">&lt;list&gt;</span>
<span class="n">listIterator</span> <span class="o">=</span> <span
class="n">item</span><span class="o">.</span><span class="n">listIterator</span><span
class="p">();</span>
+        <span class="n">startRow</span> <span class="o">=</span>
<span class="n">newItemCount</span><span class="p">;</span>
+        <span class="k">while</span> <span class="p">(</span><span
class="n">listIterator</span><span class="o">.</span><span class="n">hasNext</span><span
class="p">())</span> <span class="p">{</span>
+            <span class="n">List</span> <span class="n">subList</span>
<span class="o">=</span> <span class="n">listIterator</span><span
class="o">.</span><span class="k">next</span><span class="p">();</span>
+            <span class="n">newItemCount</span> <span class="o">=</span>
<span class="n">convertFromListToTable</span><span class="p">(</span><span
class="n">subList</span><span class="p">,</span> <span class="n">table</span><span
class="p">,</span> <span class="n">startColumn</span> <span class="o">+</span>
<span class="mi">1</span><span class="p">,</span> <span class="n">newItemCount</span><span
class="p">);</span>
+        <span class="p">}</span>
+        <span class="sr">//</span> <span class="n">merge</span>
+        <span class="n">CellRange</span> <span class="n">cellRange</span>
<span class="o">=</span> <span class="n">table</span><span class="o">.</span><span
class="n">getCellRangeByPosition</span><span class="p">(</span><span
class="n">startColumn</span><span class="p">,</span> <span class="n">startRow</span><span
class="p">,</span> <span class="n">startColumn</span><span class="p">,</span>
<span class="n">newItemCount</span><span class="p">);</span>
+        <span class="n">cellRange</span><span class="o">.</span><span
class="n">merge</span><span class="p">();</span>
+        <span class="n">newItemCount</span><span class="o">++</span><span
class="p">;</span>
+    <span class="p">}</span>
+    <span class="k">if</span> <span class="p">(</span><span class="n">list</span><span
class="o">.</span><span class="n">size</span><span class="p">()</span>
<span class="o">&gt;</span> <span class="mi">0</span><span
class="p">)</span> <span class="p">{</span>
+        <span class="k">return</span> <span class="n">newItemCount</span>
<span class="o">-</span> <span class="mi">1</span><span class="p">;</span>
+    <span class="p">}</span> <span class="k">else</span> <span
class="p">{</span>
+        <span class="k">return</span> <span class="n">startRow</span><span
class="p">;</span>
+    <span class="p">}</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p><strong><em>Convert from Table to List</em></strong></p>
+<p>This is also a recursive method. You determine the conversion range of the table
by <code>startColumn</code>, <code>startRow</code>, <code>endColumn</code>
and <code>endRow</code>. First, every cell in the selected range is retrieved
by <code>Table.getCellByPosition</code>. Next, a list item is created to store
the cell display text. If the <code>rowSpannedNumber &gt; 1</code>, that means
this item has a sub list. Parts of the cells in the right columns of this cell become the
items of the sub list. They are also determined by recursive calls to <code>convertFromTableToList</code>.
If the <code>rowSpannedNumber = 1</code>, there is no need to create a sub list,
all of the content in the right cells is just added to this item. <br />
+</p>
+<div class="codehilite"><pre><span class="n">private</span> <span
class="n">static</span> <span class="n">void</span> <span class="n">convertFromTableToList</span><span
class="p">(</span><span class="n">Table</span> <span class="n">table</span><span
class="p">,</span> <span class="n">List</span> <span class="n">list</span><span
class="p">,</span> <span class="nb">int</span> <span class="n">startColumn</span><span
class="p">,</span> <span class="nb">int</span> <span class="n">startRow</span><span
class="p">,</span> <span class="nb">int</span> <span class="n">endColumn</span><span
class="p">,</span> <span class="nb">int</span> <span class="n">endRow</span><span
class="p">)</span> <span class="p">{</span>
+    <span class="k">while</span> <span class="p">(</span><span
class="n">startRow</span> <span class="o">&lt;=</span> <span class="n">endRow</span><span
class="p">)</span> <span class="p">{</span>
+        <span class="n">Cell</span> <span class="n">cell</span> <span
class="o">=</span> <span class="n">table</span><span class="o">.</span><span
class="n">getCellByPosition</span><span class="p">(</span><span class="n">startColumn</span><span
class="p">,</span> <span class="n">startRow</span><span class="p">);</span>
+        <span class="nb">int</span> <span class="n">rowSpannedNumber</span>
<span class="o">=</span> <span class="n">cell</span><span class="o">.</span><span
class="n">getRowSpannedNumber</span><span class="p">();</span>
+        <span class="n">String</span> <span class="n">cellText</span>
<span class="o">=</span> <span class="n">cell</span><span class="o">.</span><span
class="n">getDisplayText</span><span class="p">();</span>
+        <span class="k">if</span> <span class="p">(</span><span
class="o">!</span><span class="s">&quot;&quot;</span><span
class="o">.</span><span class="n">equals</span><span class="p">(</span><span
class="n">cellText</span><span class="p">))</span> <span class="p">{</span>
+            <span class="n">ListItem</span> <span class="n">item</span>
<span class="o">=</span> <span class="n">list</span><span class="o">.</span><span
class="n">addItem</span><span class="p">(</span><span class="n">cellText</span><span
class="p">);</span>
+            <span class="nb">int</span> <span class="n">columnSpannedNumber</span>
<span class="o">=</span> <span class="n">cell</span><span class="o">.</span><span
class="n">getColumnSpannedNumber</span><span class="p">();</span>
+            <span class="nb">int</span> <span class="n">newStartColumn</span>
<span class="o">=</span> <span class="n">startColumn</span> <span
class="o">+</span> <span class="n">columnSpannedNumber</span><span
class="p">;</span>
+            <span class="k">if</span> <span class="p">(</span><span
class="n">newStartColumn</span> <span class="o">&lt;=</span> <span
class="n">endColumn</span><span class="p">)</span> <span class="p">{</span>
+                <span class="k">if</span> <span class="p">(</span><span
class="n">rowSpannedNumber</span> <span class="o">&gt;</span> <span
class="mi">1</span><span class="p">)</span> <span class="p">{</span>
+                    <span class="n">List</span> <span class="n">subList</span>
<span class="o">=</span> <span class="n">item</span><span class="o">.</span><span
class="n">addList</span><span class="p">();</span>
+                    <span class="n">convertFromTableToList</span><span class="p">(</span><span
class="n">table</span><span class="p">,</span> <span class="n">subList</span><span
class="p">,</span> <span class="n">newStartColumn</span><span class="p">,</span>
<span class="n">startRow</span><span class="p">,</span> <span class="n">endColumn</span><span
class="p">,</span> <span class="n">startRow</span> <span class="o">+</span>
<span class="n">rowSpannedNumber</span> <span class="o">-</span> <span
class="mi">1</span><span class="p">);</span>
+                <span class="p">}</span> <span class="k">else</span>
<span class="p">{</span>
+                    <span class="nb">int</span> <span class="n">tmpStartColumn</span>
<span class="o">=</span> <span class="n">newStartColumn</span><span
class="p">;</span>
+                    <span class="k">while</span> <span class="p">(</span><span
class="n">tmpStartColumn</span> <span class="o">&lt;=</span> <span
class="n">endColumn</span><span class="p">)</span> <span class="p">{</span>
+                        <span class="n">cell</span> <span class="o">=</span>
<span class="n">table</span><span class="o">.</span><span class="n">getCellByPosition</span><span
class="p">(</span><span class="n">tmpStartColumn</span><span class="p">,</span>
<span class="n">startRow</span><span class="p">);</span>
+                        <span class="n">cellText</span> <span class="o">=</span>
<span class="n">cell</span><span class="o">.</span><span class="n">getDisplayText</span><span
class="p">();</span>
+                        <span class="k">if</span> <span class="p">(</span><span
class="o">!</span><span class="s">&quot;&quot;</span><span
class="o">.</span><span class="n">equals</span><span class="p">(</span><span
class="n">cellText</span><span class="p">))</span> <span class="p">{</span>
+                            <span class="n">item</span><span class="o">.</span><span
class="n">setTextContent</span><span class="p">(</span><span class="n">item</span><span
class="o">.</span><span class="n">getTextContent</span><span class="p">()</span>
<span class="o">+</span> <span class="s">&quot;|&quot;</span>
<span class="o">+</span> <span class="n">cellText</span><span class="p">);</span>
+                        <span class="p">}</span>
+                        <span class="n">tmpStartColumn</span> <span class="o">+=</span>
<span class="n">cell</span><span class="o">.</span><span class="n">getColumnSpannedNumber</span><span
class="p">();</span>
+                    <span class="p">}</span>
+                <span class="p">}</span>
+            <span class="p">}</span>
+        <span class="p">}</span>
+        <span class="n">startRow</span> <span class="o">+=</span>
<span class="n">rowSpannedNumber</span><span class="p">;</span>
+    <span class="p">}</span>
+<span class="p">}</span>
+</pre></div>
 
-</div>
-
-<hr/>
-
-<div class="contenttitle">
-
-<a name="download">Download</a>
-
-</div>
-
-<div class="bodytext">
-
-<p>
-
-Powered by Simple API version <a target="_new" href="../downloads.html"><img src="../images/link.png"></img>0.4</a>.
 
+<p><strong>Download</strong> <br />
 </p>
-
-<p>
-
-You can download the code of this demo from <a href="table_list_convertion.zip"><img
src="../images/link.png"></img>here</a>.
-
+<p>Powered by Simple API version <a href="../downloads.html">0.4</a>. 
<br />
+You can download the code of this demo from <a href="table_list_convertion.zip">here</a>.
<br />
 </p>
-
-</div>
-<!---------------------------------------------------------------------------------------------------->
-
-</div>
-    <div id="footer" class="smallgraytext"> <a href="../index.html">Home</a>
| <a href="#">About Us</a> | <a href="mailto:Daisy@odftoolkit.org">Contact
Us</a> </div>
-  </div>
-</div>
-</body>
-</html>
-
-<script type="text/javascript" src="scripts/shCore.js"></script>
-
-<script type="text/javascript" src="scripts/shBrushJava.js"></script>
-
-<script type="text/javascript"> SyntaxHighlighter.all();</script>
   </div>
 
   <div id="footera">



Mime
View raw message