Author: devinhan Date: Tue Sep 6 02:09:27 2011 New Revision: 1165478 URL: http://svn.apache.org/viewvc?rev=1165478&view=rev Log: update directory structure, add cookbook Added: incubator/odf/site/trunk/content/odftoolkit/simple/document/ incubator/odf/site/trunk/content/odftoolkit/simple/document/APIChangesFrom086.mdtext - copied unchanged from r1163976, incubator/odf/site/trunk/content/odftoolkit/simple/APIChangesFrom086.mdtext incubator/odf/site/trunk/content/odftoolkit/simple/document/PackageLayer.mdtext - copied unchanged from r1163976, incubator/odf/site/trunk/content/odftoolkit/simple/PackageLayer.mdtext incubator/odf/site/trunk/content/odftoolkit/simple/document/ProjectRoadmap.mdtext - copied unchanged from r1163976, incubator/odf/site/trunk/content/odftoolkit/simple/ProjectRoadmap.mdtext incubator/odf/site/trunk/content/odftoolkit/simple/document/ReleaseNotes.mdtext - copied unchanged from r1163976, incubator/odf/site/trunk/content/odftoolkit/simple/ReleaseNotes.mdtext incubator/odf/site/trunk/content/odftoolkit/simple/document/Requirements.mdtext - copied unchanged from r1163976, incubator/odf/site/trunk/content/odftoolkit/simple/Requirements.mdtext incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/ incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Cell Range.html incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Cell.html incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Charts.html incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Column and Row.html incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Fields.html incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Cell Range.html incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Cell.html incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Columns and Rows.html incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Metadata.html incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Presentation.html incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Slide.html incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Table.html incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Text Document.html incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate TextSearch.html incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Presentation Document.html incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Slide.html incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Style Handling.html incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Table.html incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Text Document.html incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/TextExtractor.html incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/cookbook.css incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/index.mdtext incubator/odf/site/trunk/content/odftoolkit/simple/document/index.mdtext incubator/odf/site/trunk/content/odftoolkit/simple/document/javadoc/ - copied from r1163976, incubator/odf/site/trunk/content/odftoolkit/simple/javadoc/ Modified: incubator/odf/site/trunk/content/odftoolkit/simple/APIChangesFrom086.mdtext incubator/odf/site/trunk/content/odftoolkit/simple/PackageLayer.mdtext incubator/odf/site/trunk/content/odftoolkit/simple/ProjectRoadmap.mdtext incubator/odf/site/trunk/content/odftoolkit/simple/ReleaseNotes.mdtext incubator/odf/site/trunk/content/odftoolkit/simple/Requirements.mdtext incubator/odf/site/trunk/content/odftoolkit/simple/demo/scripts/ incubator/odf/site/trunk/content/odftoolkit/simple/demo/styles/ incubator/odf/site/trunk/content/odftoolkit/simple/javadoc/ Added: incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Cell Range.html URL: http://svn.apache.org/viewvc/incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Cell%20Range.html?rev=1165478&view=auto ============================================================================== --- incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Cell Range.html (added) +++ incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Cell Range.html Tue Sep 6 02:09:27 2011 @@ -0,0 +1,125 @@ + + + + +Cell Range + + + + + +
+
+
+
+
+ +
+ + +
+ +
+You can get cell range by providing start and end index of the column and row,or just provide start and end address of the cell(if you are using the spreadsheet.) +
+
+	    CellRange cellRange = table.getCellRangeByPosition(1, 0, 2, 0);
+ CellRange cellRangeAdd = table.getCellRangeByPosition("$E1","$E6");
+
+
+
+The code below merges all of the selected cells into one: +
+
+	    Table table1 = document.getTableByName("Table1");
+ CellRange cellrange = table1.getCellRangeByPosition(0, 0, table1.getColumnCount()-1, table1.getRowCount()-1);
+ cellRange.merge();
+
+
+
+The code below shows how to merge the cells of the first column into one : +
+
+	    	table1 = document.getTableByName("Table1");
+ CellRange firstColumn = table1.getCellRangeByPosition(0, 0, 0, table1.getRowCount()-1);
+ firstColumn.merge();
+
+
+
+The code below shows how to merge the cells of the first 2 rows into one : +
+
+		table1 = document.getTableByName("Table1");
+ int rowCount = table1.getRowCount();
+ CellRange firstTwoRow = table1.getCellRangeByPosition(0, 0, table1.getColumnCount()-1, 1);
+ firstTwoRow.merge();
+
+
+
+Merge a spreadsheet's cell is the same as text document.Especially,when getting the cell range of spreadsheet,you can use special address instead of index. +
+
+		Table sheet1 = document.getTableByName("Sheet1");
+ CellRange cellRange2 = sheet1.getCellRangeByPosition("$E1","$E6");
+ cellRange2.setCellRangeName("TimeCellRange");
+ cellRange2.merge();
+
+

+ +
+
+ +
+
+ + Added: incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Cell.html URL: http://svn.apache.org/viewvc/incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Cell.html?rev=1165478&view=auto ============================================================================== --- incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Cell.html (added) +++ incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Cell.html Tue Sep 6 02:09:27 2011 @@ -0,0 +1,334 @@ + + + + +Cell + + + + + +
+
+
+
+
+ +
+ + +
+
+
+Get Cell +
+
+
+If you want to get the specified cell in a table,you can use the getCellByPosition method of Table. +
+
+The first parameter is the column index,the second parameter is the row index. +
+
+         TextDocument document = (TextDocument) TextDocument.loadDocument(filePath);
+ Table table=document.getTableByName("stringTable");
+ Cell cell=table.getCellByPosition(1, 1);
+
+
+If you are manipulating a spreadsheet,you can get the cell by its address: +
+
+	 Table sheet1 = document.getTableByName("Sheet1");
+ Cell odsCell=sheet1.getCellByPosition("A1");
+
+
+If you want to get a cell from a row,you can specify the index of the cell in the row. +
+
+	 Row row=table.getRowByIndex(1);
+ Cell cell2=row.getCellByIndex(1);
+ System.out.println(cell2.getStringValue());
+
+
+What can I do if I have a Cell instance and want to know which column and row it belongs to ? +
+
+The code below shows how you can do that: +
+
+	 Row row1=cell.getTableRow();
+ Column column1=cell.getTableColumn();
+
+
+
+Use the getStyleName() method you can get the style name of the cell. +
+
+If you want to change the style,it must be set when you set the display text. +
+
+	 String cellSytle=cell.getStyleName();
+ cell.setDisplayText("content", cellSytle);
+
+
+What can I do if I want to control the display alignment of the cell? +
+
+You can set the horizontal and vertical alignment to do so. +
+
+The code below shows how to get and set the alignment.You can refer to the javadoc about the alignment type. +
+
+	  StyleTypeDefinitions.HorizontalAlignmentType horizontalAlign=cell.getHorizontalAlignmentType();
+ StyleTypeDefinitions.VerticalAlignmentType verticalAlign=cell.getVerticalAlignmentType();
+ cell.setHorizontalAlignment(StyleTypeDefinitions.HorizontalAlignmentType.CENTER);
+ cell.setVerticalAlignment(StyleTypeDefinitions.VerticalAlignmentType.BOTTOM);
+
+
+If the content of the cell is too long,you can set the wrap option of the cell. +
+
+	   cell.setTextWrapped(true);
+
+
+If don't know the cell is wrapped or not,you can use the method: +
+
+	   boolean isTextWrapped=cell.isTextWrapped();
+
+
+If you want to set the background color of the cell,be care that the color type is org.odftoolkit.odfdom.type.Color. +
+
+	    Color cellBackgroundColor=cell.getCellBackgroundColor();
+ cell.setCellBackgroundColor(Color.valueOf("#000000"));
+
+
+How can I control the spanned number of the column/row: +
+
+	    int spannedNum=cell.getcgetColumnSpannedNumber();
+ cell.setColumnSpannedNumber(spannedNum);
+ int rowSpannedNum=cell.getRowSpannedNumber();
+ cell.setRowSpannedNumber(rowSpannedNum);
+
+
+For column,maybe you want to know the column repeated number: +
+
+	    int repeatedNum=cell.getColumnsRepeatedNumber();
+ cell.setColumnsRepeatedNumber(repeatedNum);
+
+
+How about formatting a cell's content? You can set the format string of the cell to do so. +
+
+For example you want to format the date to yyyy-MM-dd ,you can: +
+
+	      String cellFormatStr=cell.getFormatString();
+ cell.setDateValue(new GregorianCalendar(2010,5,1));
+ cell.setFormatString("yyyy-MM-dd");
+
+
+Be care that the setFormatString only works for float, date and percentage. +
+
+You may be confused by the difference between getFormatString and getFormula,the difference is that: +
+
+For the setFormula method,it just sets as a formula attribute,the cell value will not be calculated. +
+
+	      String formula=cell.getFormula();
+ cell.setFormula(formula);
+
+
+How can I clear the content of the cell? +
+
+RemoveContent remove all of the cell while the removeTextContent only remove the text content of the cell. +
+
+	   cell.removeContent();
+ cell.removeTextContent();
+
+
+
+ The cell value can have different types,for the setValueType method: the parameter can be
  • "boolean"
  • "currency"
  • "date"
  • "float"
  • "percentage"
  • "string"
  • "time"
  • "void"
If the parameter type is not a valid cell type, an IllegalArgumentException will be thrown. +
+
+	   String valueType=cell.getValueType();
+ cell.setValueType(valueType);
+
+
+For the following getXXXValue() method:it gets the cell value as xxx type.An IllegalArgumentException will be thrown if the cell type is not xxx. +
+ +
+ For setBooleanValue method:it sets the cell value as a boolean and sets the value type to be boolean. +
+
+	   boolean booleanValue=cell.getBooleanValue();
+ cell.setBooleanValue(booleanValue);
+
+
+
+For the following getting methods,if the value type is not "currency", an IllegalArgumentException will be thrown. +
+
+The currency code of the cell is like "USD", "EUR", "CNY", and the currency symbol is like "$" +
+
+	   String currencyCode=cell.getCurrencyCode();  
+ cell.setCurrencyCode("USD");
+
+
+You can also set currency value and currency format.Please note the overall format includes the symbol character, for example: $#,##0.00. +
+
+	   cell.setCurrencyValue(100.00, "USD");
+ cell.setCurrencyFormat("$", "$#,##0.00");
+
+
+
+	   Calendar dateValue=cell.getDateValue(); 
+ cell.setDateValue(new GregorianCalendar(2010,5,1));
+
+
+
+	  double floatValue=cell.getDoubleValue();  
+ cell.setDoubleValue(new Double(22.99f));
+
+
+
+	  double percentageValue=cell.getPercentageValue();
+ cell.setPercentageValue(0.89);
+
+
+
+If the cell type is not string, the display text will be returned. +
+
+	  String stringValue=cell.getStringValue();   
+ cell.setStringValue("simple");
+
+
+
+If you want to get the string type of time value,you can format it: +
+
+	  cell.setTimeValue(Calendar.getInstance());
+ SimpleDateFormat simpleFormat = new SimpleDateFormat("'PT'HH'H'mm'M'ss'S'");
+ String timeString= simpleFormat.format(cell.getTimeValue().getTime());
+
+
+
+ Please note the display text in ODF viewer might be different from the value set by this method, because the displayed text in ODF viewer is calculated and set by editor. +
+
+	  String displayText=cell.getDisplayText();
+ cell.setDisplayText(displayText);
+
+
+
+Set image +
+
+
+ From version 0.5.5, we support high level APIs for images. You can use following codes to set an image to a cell. +
+
+	    Image myImage = cell.setImage(new URI("http://www.xxx.com/a.jpg"));
+
+
+ You can use following codes to access an image in a cell. +
+
+	    Image image = cell.getImage();
+ String imagename = image.getName();
+ FrameRectangle rect = image.getRectangle();
+ rect.setX(1);
+ rect.setY(1);
+ image.setRectangle(rect);
+
+

+ +
+
+ +
+
+ + Added: incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Charts.html URL: http://svn.apache.org/viewvc/incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Charts.html?rev=1165478&view=auto ============================================================================== --- incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Charts.html (added) +++ incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Charts.html Tue Sep 6 02:09:27 2011 @@ -0,0 +1,183 @@ + + + + +Charts + + + + + +
+
+
+
+
+ +
+ + +
+
+
+Overview +
+
+
+ Since 0.6, Simple ODF provides methods to manipulate charts in text document, spreadsheet document and presentation document. You can create, update and delete charts with these methods. +
+ +
+ We all know, a chart is associated with a table. In order to create a chart, you must determine the data set of this chart. The data set can be a cell range of a table, for example: +
+
+		CellRangeAddressList cellRange = CellRangeAddressList.valueOf("A.A1:A.B3");
+ DataSet dataSet = new DataSet(cellRange, spreadsheetDoc, true, true, false);
+
+
+ Or a two dimensional array, for example: +
+
+		int row = 2, column = 3;
+ double[][] data = new double[column][row];
+ String[] labels = new String[row];
+ String[] legends = new String[column];
+ DataSet dataset = new DataSet(labels, legends, data);
+
+
+ You should also use rectangle to define the position and the size of this chart. For example: +
+
+		Rectangle rect = new Rectangle();
+ rect.x = 2000;
+ rect.y = 2700;
+ rect.width = 15000;
+ rect.height = 8000;
+ rect.y = 110000;
+
+
+ Then you can create a chart: +
+
+		spreadsheetDoc.createChart("Page Visit", dataSet,rect);
+
+
+ There are some shortcut methods to create charts, for example, below codes show how to create a chart in a text document: +
+
+		Chart chart = textDoc.createChart(
+ "Page Visit", spreadsheetDoc,
+ cellRange, true, true, false, rect);
+
+
+ If you want to create a chart in a spreadsheet document, you need to specify a cell to be the anchor of this chart, for example: +
+
+		spreadsheetDoc.createChart("Page Visit", spreadsheetDoc, cellRange,
+ true, true, false, rect, spreadsheetDoc.getTableByName("C")
+ .getCellByPosition("D10"));
+
+
+ If you want to create a chart in a presentation document, you can use the existing layout of a slide, which means, you don't need to specify a rectangle. The layouts that could contain a chart include: TITLE_PLUS_CHART, TITLE_PLUS_2_CHART, TITLE_LEFT_CHART_RIGHT_OUTLINE, TITLE_PLUS_3_OBJECT, and TITLE_PLUS_4_OBJECT. For example: +
+
+		Slide slide = presentationDoc.newSlide(2, "Slide3",
+ SlideLayout.TITLE_PLUS_2_CHART);
+ chart = slide.createChart("Count of Visits", spreadsheetDoc,
+ cellRange, true, true, false, null);
+
+
+
+ You can update charts properties, for example, the title, axis title, chart type, whether to apply 3D effect, whether to use legend with API. For example: +
+
+		chart.setChartTitle("New title");
+ chart.setAxisTitle("Hour", "Number");
+ chart.setChartType(ChartType.AREA);
+ chart.setApply3DEffect(true);
+ chart.setUseLegend(true);
+
+
+ You can update the data set too. For example: +
+
+		chart.setChartData(new DataSet(CellRangeAddressList.valueOf("A.A1:A.C4"), spreadsheetDoc, true, true, true));
+
+
+
+ You can get charts by title e.g. +
+
+		chart = textDoc.getChartByTitle("New title").get(0);
+
+
+ You can also get a chart by its unique ID. The unique ID of a chart in Simple ODF API is the path of the chart document (relative to the ODF document package). The unique ID can be gotten with method: +
+
+		String chartid = chart.getChartID();
+ chart = textDoc.getChartById(chartid);
+
+
+ You can also get the count of charts in this document. +
+
+		int count = textDoc.getChartCount();
+
+
+ You can delete a chart by ID or by title, e.g. +
+
+		textDoc.deleteChartById(chartid);
+ textDoc.deleteChartByTitle("New title");
+
+

+ +
+
+ +
+
+ + Added: incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Column and Row.html URL: http://svn.apache.org/viewvc/incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Column%20and%20Row.html?rev=1165478&view=auto ============================================================================== --- incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Column and Row.html (added) +++ incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Column and Row.html Tue Sep 6 02:09:27 2011 @@ -0,0 +1,166 @@ + + + + +Column and Row + + + + + +
+
+
+
+
+ +
+ + +
+ +
+The class Column/Row represents the column/row of table.To get all the columns or rows you can use the getColumnList or getRowList of the table instance. +
+
+	List<Column> columns = table.getColumnList();
+ List<Row> rows = table.getRowList();
+
+
+You can also get single column/row by specifying the index of the column/row. +
+
+The column/row index start from 0.If not found, null will be returned. +
+
+	
+ Column column = table.getColumnByIndex(2);
+ Row row = table.getRowByIndex(0);
+
+
+If you want to know the count of header column/row in the table,you can do like this: +
+
+	int headerColumnCount = table.getHeaderColumnCount();
+ int headerRowCount = table.getHeaderRowCount();
+
+
+If you want to know the index of the column/row,you can use the method below: +
+
+	int columnIndex=column.getColumnIndex();
+ int rowIndex=row.getRowIndex();
+
+
+Can I get the previous or next Column/Row by the current column/row instance? +
+
+Yes,you can ask the column/row instance itself,if it doesn't exist,null will be returned. +
+
+	Column previousCol=column.getPreviousColumn();
+ Column nextCol=column.getNextColumn();
+ Row previousRow=row.getPreviousRow();
+ Row nextRow=row.getNextRow();
+
+
+
+You can add a column to the end or insert many columns before the specified index +
+
+The appendColumn/Row method add an empty column/row at the end and return the new appended column/row +
+
+	Column newColumn=table.appendColumn();
+ Row newRow=table.appendRow();
+
+
+What can I do if I want to insert a column/row into the specified position? +
+
+ You can use the insertColumn/RowBefore method,whose first parameter is the index of the column/row to be inserted before; The second parameter is the number of columns/rows to be inserted. +
+
+	List<Column> cols = table.insertColumnsBefore(1, 2);
+ List<Row> newRows = table.insertRowsBefore(0, 2);
+
+
+
+You can delete a number of columns/rows by index +
+
+The first parameter is the index of the first column/row to delete; The second parameter is the number of columns/rows to delete. +
+
+The code below remove 1 column whose index is 2;remove 2 rows whose index is 1,2. +
+
+	table.removeColumnsByIndex(2, 1);
+ table.removeRowsByIndex(1, 2);
+
+
+
+If you want to change the width of the column or the height of the row,you can use it like this: +
+
+If the second parameter of row's setHeight is true, the row can fit the height to the text, vice versa. +
+
+	column.setWidth(column.getWidth()/2);
+ row.setHeight(row.getHeight()/2, true);
+
+

+ +
+
+ +
+
+ + Added: incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Fields.html URL: http://svn.apache.org/viewvc/incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Fields.html?rev=1165478&view=auto ============================================================================== --- incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Fields.html (added) +++ incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Fields.html Tue Sep 6 02:09:27 2011 @@ -0,0 +1,220 @@ + + + + +Fields + + + + + +
+
+
+
+
+ +
+ + +
+ +
+ You can use the following code to create a variable field, and set the value. +
+
+			TextDocument doc = TextDocument.newTextDocument();
+ Paragraph paragraph = doc.addParagraph("test_con_variable:");
+ VariableField simpleVariableField = Fields.createSimpleVariableField(doc, "test_con_variable");
+ simpleVariableField.updateField("true", paragraph.getOdfElement());
+
+
+ Following code can be used to set value to variable field, and append it to an ODF element. +
+
+			simpleVariableField.updateField("user variable content", null);
+ simpleVariableField.displayField(paragraph.getOdfElement());
+
+
+
+ Following code can be used to create a condition field. +
+
+			Paragraph newParagraph = doc.addParagraph("Condition Field Test:");
+ ConditionField conditionField = Fields.createConditionField(newParagraph.getOdfElement(), "test_con_variable == \"true\"",
+ "trueText", "falseText");
+
+
+
+Hidden Field +
+
+
+ Following code can be used to create a hidden field. +
+
+			newParagraph = doc.addParagraph("Hide Text Field Test:");
+ conditionField = Fields.createHiddenTextField(newParagraph.getOdfElement(), "test_con_variable == \"true\"", "hiddenText");
+
+
+
+ Following code can be used to create a reference field. +
+
+			OdfElement newTextSpanElement = ((TextPElement)doc.addParagraph("Reference Content:").getOdfElement()).newTextSpanElement();
+ newTextSpanElement.setTextContent("This is a test reference content.");
+ ReferenceField referenceField = Fields.createReferenceField(newTextSpanElement, "test-ref");
+
+
+ Following code can be used to append a reference field. +
+
+			referenceField.appendReferenceTo(doc.addParagraph("User Reference Field:").getOdfElement(), ReferenceField.DisplayType.TEXT);
+
+
+
+ Following code can be used to create a chapter field. +
+
+			ChapterField chapterField = Fields.createChapterField(doc.addParagraph("Chapter:").getOdfElement());
+
+
+
+ Following code can be used to create a title field. +
+
+			TitleField titleField = Fields.createTitleField(doc.addParagraph("The Title:").getOdfElement());
+
+
+ Following code can be used to create a subject field. +
+
+			SubjectField subjectField = Fields.createSubjectField(doc.addParagraph("The Subject:").getOdfElement());
+
+
+
+Author Field +
+
+
+ Following code can be used to create a author initial field and a author name field. +
+
+			AuthorField authorField = Fields.createAuthorInitialsField(doc.addParagraph("The initials of the author :").getOdfElement());
+ authorField = Fields.createAuthorNameField(doc.addParagraph("Author:").getOdfElement());
+
+
+
+ Following code can be used to create a current page number field. +
+
+			PageNumberField numberField = Fields.createCurrentPageNumberField(doc.addParagraph("Current Page Number:").getOdfElement());
+ numberField.setNumberFormat(NumberFormat.UPPERCASE_LATIN_ALPHABET);
+ numberField.setDisplayPage(DisplayType.NEXT_PAGE);
+
+
+ Following code can be used to create a previous page number and a next page number field. +
+
+			numberField = Fields.createPreviousPageNumberField(doc.addParagraph("Previous Page Number:").getOdfElement());
+ numberField = Fields.createNextPageNumberField(doc.addParagraph("Next Page Number:").getOdfElement());
+
+
+
+ Following code can be used to create a page count field, and set the number format. +
+
+			PageCountField countField = Fields.createPageCountField(doc.addParagraph("Page Count:").getOdfElement());
+ countField.setNumberFormat(NumberFormat.UPPERCASE_LATIN_ALPHABET);
+
+
+
+Date Field +
+
+
+ Following code can be used to create a date field, and set the format. +
+
+			DateField dateField = Fields.createDateField(doc.addParagraph("Date:").getOdfElement());
+ dateField.formatDate("yy-MM-dd");
+
+
+
+Time Field +
+
+
+ Following code can be used to create a time field, and set the format. +
+
+			TimeField timeField = Fields.createTimeField(doc.addParagraph("Time:").getOdfElement());
+ timeField.formatTime("HH:mm:ss a");
+
+

+ +
+
+ +
+
+ + Added: incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Cell Range.html URL: http://svn.apache.org/viewvc/incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate%20Cell%20Range.html?rev=1165478&view=auto ============================================================================== --- incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Cell Range.html (added) +++ incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Cell Range.html Tue Sep 6 02:09:27 2011 @@ -0,0 +1,112 @@ + + + + +Manipulate Cell Range + + + + +
+
+
+
+
+ +
+ + +
+ +
+You can get cell range by providing start and end index of the column and row,or just provide start and end address of the cell(if you are using the spreadsheet.) +
+
+	    CellRange cellRange = table.getCellRangeByPosition(1, 0, 2, 0);
+ CellRange cellRangeAdd = table.getCellRangeByPosition("$E1","$E6");
+
+
+
+The code below merges all of the selected cells into one: +
+
+	    Table table1 = document.getTableByName("Table1");
+ CellRange cellrange = table1.getCellRangeByPosition(0, 0, table1.getColumnCount()-1, table1.getRowCount()-1);
+ cellRange.merge();
+
+
+
+The code below shows how to merge the cells of the first column into one : +
+
+	    	table1 = document.getTableByName("Table1");
+ CellRange firstColumn = table1.getCellRangeByPosition(0, 0, 0, table1.getRowCount()-1);
+ firstColumn.merge();
+
+
+
+The code below shows how to merge the cells of the first 2 rows into one : +
+
+		table1 = document.getTableByName("Table1");
+ int rowCount = table1.getRowCount();
+ CellRange firstTwoRow = table1.getCellRangeByPosition(0, 0, table1.getColumnCount()-1, 1);
+ firstTwoRow.merge();
+
+
+
+Merge a spreadsheet's cell is the same as text document.Especially,when getting the cell range of spreadsheet,you can use special address instead of index. +
+
+		Table sheet1 = document.getTableByName("Sheet1");
+ CellRange cellRange2 = sheet1.getCellRangeByPosition("$E1","$E6");
+ cellRange2.setCellRangeName("TimeCellRange");
+ cellRange2.merge();
+
+

+ +
+
+ +
+
+ + Added: incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Cell.html URL: http://svn.apache.org/viewvc/incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate%20Cell.html?rev=1165478&view=auto ============================================================================== --- incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Cell.html (added) +++ incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Cell.html Tue Sep 6 02:09:27 2011 @@ -0,0 +1,321 @@ + + + + +Manipulate Cell + + + + +
+
+
+
+
+ +
+ + +
+
+
+Get Cell +
+
+
+If you want to get the specified cell in a table,you can use the getCellByPosition method of Table. +
+
+The first parameter is the column index,the second parameter is the row index. +
+
+         TextDocument document = (TextDocument) TextDocument.loadDocument(filePath);
+ Table table=document.getTableByName("stringTable");
+ Cell cell=table.getCellByPosition(1, 1);
+
+
+If you are manipulating a spreadsheet,you can get the cell by its address: +
+
+	 Table sheet1 = document.getTableByName("Sheet1");
+ Cell odsCell=sheet1.getCellByPosition("A1");
+
+
+If you want to get a cell from a row,you can specify the index of the cell in the row. +
+
+	 Row row=table.getRowByIndex(1);
+ Cell cell2=row.getCellByIndex(1);
+ System.out.println(cell2.getStringValue());
+
+
+What can I do if I have a Cell instance and want to know which column and row it belongs to ? +
+
+The code below shows how you can do that: +
+
+	 Row row1=cell.getTableRow();
+ Column column1=cell.getTableColumn();
+
+
+
+Use the getStyleName() method you can get the style name of the cell. +
+
+If you want to change the style,it must be set when you set the display text. +
+
+	 String cellSytle=cell.getStyleName();
+ cell.setDisplayText("content", cellSytle);
+
+
+What can I do if I want to control the display alignment of the cell? +
+
+You can set the horizontal and vertical alignment to do so. +
+
+The code below shows how to get and set the alignment.You can refer to the javadoc about the alignment type. +
+
+	  StyleTypeDefinitions.HorizontalAlignmentType horizontalAlign=cell.getHorizontalAlignmentType();
+ StyleTypeDefinitions.VerticalAlignmentType verticalAlign=cell.getVerticalAlignmentType();
+ cell.setHorizontalAlignment(StyleTypeDefinitions.HorizontalAlignmentType.CENTER);
+ cell.setVerticalAlignment(StyleTypeDefinitions.VerticalAlignmentType.BOTTOM);
+
+
+If the content of the cell is too long,you can set the wrap option of the cell. +
+
+	   cell.setTextWrapped(true);
+
+
+If don't know the cell is wrapped or not,you can use the method: +
+
+	   boolean isTextWrapped=cell.isTextWrapped();
+
+
+If you want to set the background color of the cell,be care that the color type is org.odftoolkit.odfdom.type.Color. +
+
+	    Color cellBackgroundColor=cell.getCellBackgroundColor();
+ cell.setCellBackgroundColor(Color.valueOf("#000000"));
+
+
+How can I control the spanned number of the column/row: +
+
+	    int spannedNum=cell.getcgetColumnSpannedNumber();
+ cell.setColumnSpannedNumber(spannedNum);
+ int rowSpannedNum=cell.getRowSpannedNumber();
+ cell.setRowSpannedNumber(rowSpannedNum);
+
+
+For column,maybe you want to know the column repeated number: +
+
+	    int repeatedNum=cell.getColumnsRepeatedNumber();
+ cell.setColumnsRepeatedNumber(repeatedNum);
+
+
+How about formatting a cell's content? You can set the format string of the cell to do so. +
+
+For example you want to format the date to yyyy-MM-dd ,you can: +
+
+	      String cellFormatStr=cell.getFormatString();
+ cell.setDateValue(new GregorianCalendar(2010,5,1));
+ cell.setFormatString("yyyy-MM-dd");
+
+
+Be care that the setFormatString only works for float, date and percentage. +
+
+You may be confused by the difference between getFormatString and getFormula,the difference is that: +
+
+For the setFormula method,it just sets as a formula attribute,the cell value will not be calculated. +
+
+	      String formula=cell.getFormula();
+ cell.setFormula(formula);
+
+
+How can I clear the content of the cell? +
+
+RemoveContent remove all of the cell while the removeTextContent only remove the text content of the cell. +
+
+	   cell.removeContent();
+ cell.removeTextContent();
+
+
+
+ The cell value can have different types,for the setValueType method: the parameter can be
  • "boolean"
  • "currency"
  • "date"
  • "float"
  • "percentage"
  • "string"
  • "time"
  • "void"
If the parameter type is not a valid cell type, an IllegalArgumentException will be thrown. +
+
+	   String valueType=cell.getValueType();
+ cell.setValueType(valueType);
+
+
+For the following getXXXValue() method:it gets the cell value as xxx type.An IllegalArgumentException will be thrown if the cell type is not xxx. +
+ +
+ For setBooleanValue method:it sets the cell value as a boolean and sets the value type to be boolean. +
+
+	   boolean booleanValue=cell.getBooleanValue();
+ cell.setBooleanValue(booleanValue);
+
+
+
+For the following getting methods,if the value type is not "currency", an IllegalArgumentException will be thrown. +
+
+The currency code of the cell is like "USD", "EUR", "CNY", and the currency symbol is like "$" +
+
+	   String currencyCode=cell.getCurrencyCode();  
+ cell.setCurrencyCode("USD");
+
+
+You can also set currency value and currency format.Please note the overall format includes the symbol character, for example: $#,##0.00. +
+
+	   cell.setCurrencyValue(100.00, "USD");
+ cell.setCurrencyFormat("$", "$#,##0.00");
+
+
+
+	   Calendar dateValue=cell.getDateValue(); 
+ cell.setDateValue(new GregorianCalendar(2010,5,1));
+
+
+
+	  double floatValue=cell.getDoubleValue();  
+ cell.setDoubleValue(new Double(22.99f));
+
+
+
+	  double percentageValue=cell.getPercentageValue();
+ cell.setPercentageValue(0.89);
+
+
+
+If the cell type is not string, the display text will be returned. +
+
+	  String stringValue=cell.getStringValue();   
+ cell.setStringValue("simple");
+
+
+
+If you want to get the string type of time value,you can format it: +
+
+	  cell.setTimeValue(Calendar.getInstance());
+ SimpleDateFormat simpleFormat = new SimpleDateFormat("'PT'HH'H'mm'M'ss'S'");
+ String timeString= simpleFormat.format(cell.getTimeValue().getTime());
+
+
+
+ Please note the display text in ODF viewer might be different from the value set by this method, because the displayed text in ODF viewer is calculated and set by editor. +
+
+	  String displayText=cell.getDisplayText();
+ cell.setDisplayText(displayText);
+
+
+
+Set image +
+
+
+ From version 0.5.5, we support high level APIs for images. You can use following codes to set an image to a cell. +
+
+	    Image myImage = cell.setImage(new URI("http://www.xxx.com/a.jpg"));
+
+
+ You can use following codes to access an image in a cell. +
+
+	    Image image = cell.getImage();
+ String imagename = image.getName();
+ FrameRectangle rect = image.getRectangle();
+ rect.setX(1);
+ rect.setY(1);
+ image.setRectangle(rect);
+
+

+ +
+
+ +
+
+ + Added: incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Columns and Rows.html URL: http://svn.apache.org/viewvc/incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate%20Columns%20and%20Rows.html?rev=1165478&view=auto ============================================================================== --- incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Columns and Rows.html (added) +++ incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Columns and Rows.html Tue Sep 6 02:09:27 2011 @@ -0,0 +1,153 @@ + + + + +Manipulate Columns and Rows + + + + +
+
+
+
+
+ +
+ + +
+ +
+The class Column/Row represents the column/row of table.To get all the columns or rows you can use the getColumnList or getRowList of the table instance. +
+
+	List<Column> columns = table.getColumnList();
+ List<Row> rows = table.getRowList();
+
+
+You can also get single column/row by specifying the index of the column/row. +
+
+The column/row index start from 0.If not found, null will be returned. +
+
+	
+ Column column = table.getColumnByIndex(2);
+ Row row = table.getRowByIndex(0);
+
+
+If you want to know the count of header column/row in the table,you can do like this: +
+
+	int headerColumnCount = table.getHeaderColumnCount();
+ int headerRowCount = table.getHeaderRowCount();
+
+
+If you want to know the index of the column/row,you can use the method below: +
+
+	int columnIndex=column.getColumnIndex();
+ int rowIndex=row.getRowIndex();
+
+
+Can I get the previous or next Column/Row by the current column/row instance? +
+
+Yes,you can ask the column/row instance itself,if it doesn't exist,null will be returned. +
+
+	Column previousCol=column.getPreviousColumn();
+ Column nextCol=column.getNextColumn();
+ Row previousRow=row.getPreviousRow();
+ Row nextRow=row.getNextRow();
+
+
+
+You can add a column to the end or insert many columns before the specified index +
+
+The appendColumn/Row method add an empty column/row at the end and return the new appended column/row +
+
+	Column newColumn=table.appendColumn();
+ Row newRow=table.appendRow();
+
+
+What can I do if I want to insert a column/row into the specified position? +
+
+ You can use the insertColumn/RowBefore method,whose first parameter is the index of the column/row to be inserted before; The second parameter is the number of columns/rows to be inserted. +
+
+	List<Column> cols = table.insertColumnsBefore(1, 2);
+ List<Row> newRows = table.insertRowsBefore(0, 2);
+
+
+
+You can delete a number of columns/rows by index +
+
+The first parameter is the index of the first column/row to delete; The second parameter is the number of columns/rows to delete. +
+
+The code below remove 1 column whose index is 2;remove 2 rows whose index is 1,2. +
+
+	table.removeColumnsByIndex(2, 1);
+ table.removeRowsByIndex(1, 2);
+
+
+
+If you want to change the width of the column or the height of the row,you can use it like this: +
+
+If the second parameter of row's setHeight is true, the row can fit the height to the text, vice versa. +
+
+	column.setWidth(column.getWidth()/2);
+ row.setHeight(row.getHeight()/2, true);
+
+

+ +
+
+ +
+
+ + Added: incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Metadata.html URL: http://svn.apache.org/viewvc/incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate%20Metadata.html?rev=1165478&view=auto ============================================================================== --- incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Metadata.html (added) +++ incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Metadata.html Tue Sep 6 02:09:27 2011 @@ -0,0 +1,143 @@ + + + + +Manipulate Metadata + + + + + +
+
+
+
+
+ +
+ + +
+
+
+Overview +
+
+
+ This Meta API supports to access and set document metadata. It covers the metadata definitions in ODF Specification 1.2 Committee Draft05 +
+ +
+ First you load an ODF text document(for example),then get the meta file DOM and then use the meta DOM to create an instance of the Meta. Use Meta you can access all the supported elements. +
+
+	TextDocument doc = (TextDocument) TextDocument.loadDocument("testtable.odt");
+ OdfFileDom metadom = doc.getMetaDom();
+ Meta metadata = new Meta(metadom);
+
+
+
+ After creating the Meta instance,you can use it to manipulate the metadata: for example, you can set a value for the <meta:generator> like this: +
+
+	metadata.setGenerator("OpenOffice.org/3.0$Win32 OpenOffice.org_project/300m15$Build-9379");
+
+
+ The <meta:keyword> may contain many keywords, you can set the whole list of keywords and add one keyword as you want. the api currently do not provide the direct method for deleting one keyword ,you can get the keyword list first,and then delete the keyword,finally set the list to the element. +
+
+       metadata.addKeyword("java");
+ List<String> keywords=metadata.getKeywords();
+ keywords.remove("java");
+ metadata.setKeywords(keywords);
+
+
+
+ To manipulate the user defined data,you should get the list of their names,and then use the names to update the data or its datatype or delete the whole user defined data. you can use the setUserDefinedData(String name, String type, String value) method to update data,if the name not exists in the document,the method will add the new user defined data. +
+
+      List<String> names=metadata.getUserDefinedDataNames();
+ for (String name : names) {
+ metadata.removeUserDefinedDataByName(name);
+ }
+ String key="newId";
+ //org.odftoolkit.odfdom.dom.attribute.meta.MetaValueTypeAttribute.Value + metadata.setUserDefinedData(key, Value.STRING.toString(), "new001");
+ //update the datatype + metadata.setUserDefinedDataType(key, Value.BOOLEAN.toString());
+ //update the data value + metadata.setUserDefinedDataValue(key, "false");
+
+ //get the datatype + String dataType=metadata.getUserDefinedDataType(key);
+ //get the data value + String dataValue=metadata.getUserDefinedDataValue(key);
+
+
+
+ if you want to access the document statistics,you should get a DocumentStatistic instance, if the return is null,it means that this ODF document doesn't have any document statistic information,you should create a document statistics object. +
+
+	DocumentStatistic stat = metadata.getDocumentStatistic();
+ if(stat==null) {
+ stat=new DocumentStatistic(metadata.getOfficeMetaElement().newMetaDocumentStatisticElement());
+ }
+
+ stat.setCellCount(3);
+ Integer cellCount=stat.getCellCount();
+
+

+ +
+
+ +
+
+ +