public class SpreadsheetDocument extends Document implements ChartContainer
Modifier and Type | Class and Description |
---|---|
static class |
SpreadsheetDocument.OdfMediaType
This enum contains all possible media types of SpreadsheetDocument documents.
|
Document.ScriptType
OdfSchemaDocument.OdfXMLFile
OdfPackageDocument.Resource
selectionManager
mContentDom, mDocumentStyles, mMetaDom, mSettingsDom, mStylesDom
mDocumentMediaType, mDocumentPathInPackage, mPackage, ROOT_DOCUMENT_PATH
Modifier | Constructor and Description |
---|---|
protected |
SpreadsheetDocument(OdfPackage pkg,
String internalPath,
SpreadsheetDocument.OdfMediaType odfMediaType)
To avoid data duplication a new document is only created, if not already opened.
|
Modifier and Type | Method and Description |
---|---|
Table |
appendSheet(String name)
Adds a new blank sheet with the specified
name to this document. |
Table |
appendSheet(Table refTable,
String name)
Adds a new sheet with data from existing table.
|
void |
changeMode(SpreadsheetDocument.OdfMediaType mediaType)
Changes the document to the given mediatype.
|
Chart |
createChart(String title,
DataSet dataset,
Rectangle rect)
Creates a new Chart for this spreadsheet document.
|
Chart |
createChart(String title,
SpreadsheetDocument document,
CellRangeAddressList cellRangeAddr,
boolean firstRowAsLabel,
boolean firstColumnAsLabel,
boolean rowAsDataSeries,
Rectangle rect)
Creates a new Chart for this spreadsheet document.
|
Chart |
createChart(String title,
SpreadsheetDocument document,
CellRangeAddressList cellRangeAddr,
boolean firstRowAsLabel,
boolean firstColumnAsLabel,
boolean rowAsDataSeries,
Rectangle rect,
Cell cell)
Creates a new Chart for this spreadsheet document.
|
Chart |
createChart(String title,
String[] labels,
String[] legends,
double[][] data,
Rectangle rect)
Creates a new Chart for this spreadsheet document.
|
void |
deleteChartById(String chartId)
Deletes chart by chart id.
|
void |
deleteChartByTitle(String title)
Deletes chart(s) by chart title.
|
Table |
getActiveSheet()
Retrieves the active sheet of this document.
|
Chart |
getChartById(String chartId)
Gets chart with specified id.
|
List<Chart> |
getChartByTitle(String title)
Gets chart list with specified title.
|
int |
getChartCount()
Returns the chart count of this container
|
OfficeSpreadsheetElement |
getContentRoot()
Get the content root of a spreadsheet document.
|
Table |
getSheetByIndex(int index)
Retrieves sheet by index.
|
Table |
getSheetByName(String name)
Retrieves sheet by name.
|
int |
getSheetCount()
Returns the sheet count of this document.
|
OdfElement |
getTableContainerElement()
Get the ODF element which can have
|
Table |
insertSheet(int before)
Inserts a new blank sheet before the reference index.
|
Table |
insertSheet(Table refTable,
int before)
Inserts a new sheet with data from existing table.
|
static SpreadsheetDocument |
loadDocument(File file)
Creates an SpreadsheetDocument from the OpenDocument provided by a File.
|
static SpreadsheetDocument |
loadDocument(InputStream inputStream)
Creates an SpreadsheetDocument from the OpenDocument provided by a resource Stream.
|
static SpreadsheetDocument |
loadDocument(String documentPath)
Loads an SpreadsheetDocument from the provided path.
|
static SpreadsheetDocument |
newSpreadsheetDocument()
Creates an empty spreadsheet document.
|
static SpreadsheetDocument |
newSpreadsheetTemplateDocument()
Creates an empty spreadsheet template.
|
void |
removeSheet(int index)
Removes the sheet in the specified
index . |
addTable, addTable, close, getComponentMap, getContentRoot, getEmbeddedDocument, getEmbeddedDocuments, getEmbeddedDocuments, getLocale, getOdfMediaType, getOfficeMetadata, getScriptType, getSectionByName, getSectionIterator, getSelectionManager, getTableBuilder, getTableByName, getTableContainerImpl, getTableList, insertDocument, loadDocument, loadDocument, loadDocument, loadDocument, LoadTableTemplateFromForeignTable, loadTemplate, newImage, removeElementLinkedResource, save, save, save, setLocale, setLocale, setOdfMediaType, setPassword, setSelectionManager, toString
getBaseURI, getBookmarkRDFMetadata, getContentDom, getContentStream, getDocumentStyles, getFileDom, getInContentMetadata, getInContentMetadataFromCache, getManifestRDFMetadata, getMasterPages, getMetaDom, getMetaStream, getOfficeMasterStyles, getOrCreateDocumentStyles, getRDFMetadata, getSettingsDom, getSettingsStream, getStylesDom, getStylesStream, getTables, getXMLFilePath
flushDoms, getDocumentPath, getFileDom, getMediaTypeString, getPackage, getXMLFileMetadata, isExternalReference, isRootDocument, loadSubDocument, normalizeDocumentPath, removeDocument, save, setMediaTypeString
protected SpreadsheetDocument(OdfPackage pkg, String internalPath, SpreadsheetDocument.OdfMediaType odfMediaType)
public static SpreadsheetDocument newSpreadsheetDocument() throws Exception
Exception
- - if the document could not be createdpublic static SpreadsheetDocument newSpreadsheetTemplateDocument() throws Exception
Exception
- - if the template could not be createdpublic static SpreadsheetDocument loadDocument(InputStream inputStream) throws Exception
Since an InputStream does not provide the arbitrary (non sequentiell) read access needed by SpreadsheetDocument, the InputStream is cached. This usually takes more time compared to the other createInternalDocument methods. An advantage of caching is that there are no problems overwriting an input file.
If the resource stream is not a ODF spreadsheet document, ClassCastException might be thrown.
inputStream
- - the InputStream of the ODF spreadsheet document.Exception
- - if the document could not be created.public static SpreadsheetDocument loadDocument(String documentPath) throws Exception
SpreadsheetDocument relies on the file being available for read access over the whole lifecycle of SpreadsheetDocument.
If the resource stream is not a ODF spreadsheet document, ClassCastException might be thrown.
documentPath
- - the path from where the document can be loadedException
- - if the document could not be created.public static SpreadsheetDocument loadDocument(File file) throws Exception
SpreadsheetDocument relies on the file being available for read access over the whole lifecycle of SpreadsheetDocument.
If the resource stream is not a ODF spreadsheet document, ClassCastException might be thrown.
file
- - a file representing the ODF spreadsheet document.Exception
- - if the document could not be created.public OfficeSpreadsheetElement getContentRoot() throws Exception
getContentRoot
in class Document
Exception
- if the file DOM could not be created.public void changeMode(SpreadsheetDocument.OdfMediaType mediaType)
mediaType
- the related ODF mimetypepublic Table getSheetByIndex(int index)
index
- the index of the retrieved sheet, which starts from 0. If the index value is out
of range (index >= sheet count or index < 0), this method would return null
. @since 0.6public Table getSheetByName(String name)
name
- the name of the retrieved sheet.public Table getActiveSheet()
null
.public Table appendSheet(String name)
name
to this document.name
- the name of the new sheet.public Table appendSheet(Table refTable, String name)
NOTE: This method copies data from existing table, including linked resources and styles, if the source table is not in the target document. If these data has dependencies to other data of the source document, the data dependencies will not be copied. For example, document A has two sheets, "Sheet1" and "Sheet2". In "Sheet2", there is a cell with formula, "=sum(Sheet1.A1:Sheet1.A10)". After copy the data of "Sheet2" to the new sheet in document B, the result of this formula would be different or even invalid in document B.
refTable
- the reference table, which is the data source of the new sheet.name
- the name of the new sheet.public Table insertSheet(int before)
before
- the reference index, which starts from 0. If the index value is out of range
(index >= sheet count or index < 0), this method would return null
. @return
inserted sheet. @since 0.6public Table insertSheet(Table refTable, int before)
NOTE: This method copies data from existing table, including linked resources and styles, if the source table is not in the target document. If these data has dependencies to other data of the source document, the data dependencies will not be copied. For example, document A has two sheets, "Sheet1" and "Sheet2". In "Sheet2", there is a cell with formula, "=sum(Sheet1.A1:Sheet1.A10)". After copy the data of "Sheet2" to the new sheet in document B, the result of this formula would be different or even invalid in document B.
refTable
- the reference table, which is the data source of the new sheet.before
- the reference index, which starts from 0 and new sheet would be inserted before
it. If the index value is out of range (index >= sheet count or index < 0), this method
would return null
.public void removeSheet(int index)
index
.index
- the index of the removed sheet, which starts from 0. If the index value is out of
range (index >= sheet count or index < 0), this method would do nothing. @since 0.6public int getSheetCount()
public OdfElement getTableContainerElement()
TableContainer
getTableContainerElement
in interface TableContainer
public Chart createChart(String title, DataSet dataset, Rectangle rect)
createChart
in interface ChartContainer
title
- chart title.dataset
- chart data set.rect
- chart rectangle.public Chart createChart(String title, SpreadsheetDocument document, CellRangeAddressList cellRangeAddr, boolean firstRowAsLabel, boolean firstColumnAsLabel, boolean rowAsDataSeries, Rectangle rect)
createChart
in interface ChartContainer
title
- chart title.document
- the data source spreadsheet document.cellRangeAddr
- the cell range address list which is used as chart data set.firstRowAsLabel
- whether uses first row as label.firstColumnAsLabel
- whether uses first column as label.rowAsDataSeries
- whether uses data as series.rect
- chart rectangle.public Chart createChart(String title, String[] labels, String[] legends, double[][] data, Rectangle rect)
createChart
in interface ChartContainer
title
- chart rectangle.labels
- label stringslegends
- legend stringsdata
- chart data set.rect
- chart rectangle.public Chart createChart(String title, SpreadsheetDocument document, CellRangeAddressList cellRangeAddr, boolean firstRowAsLabel, boolean firstColumnAsLabel, boolean rowAsDataSeries, Rectangle rect, Cell cell)
title
- chart rectangle.document
- the data source spreadsheet document.cellRangeAddr
- the cell range list to be used as chart data.firstRowAsLabel
- whether use first row as label.firstColumnAsLabel
- whether use first column as label.rowAsDataSeries
- whether use row as data series.rect
- chart rectangle.cell
- the position cell where the new chart is inserted.public void deleteChartById(String chartId)
ChartContainer
deleteChartById
in interface ChartContainer
chartId
- the id of specified chart.public void deleteChartByTitle(String title)
ChartContainer
deleteChartByTitle
in interface ChartContainer
title
- the title of specified chart(s).public Chart getChartById(String chartId)
ChartContainer
getChartById
in interface ChartContainer
chartId
- the id of this chart.public List<Chart> getChartByTitle(String title)
ChartContainer
getChartByTitle
in interface ChartContainer
title
- the title of specified chart(s).public int getChartCount()
ChartContainer
getChartCount
in interface ChartContainer
Copyright © 2010–2018 Apache Software Foundation; Copyright © 2018–2020 The Document Foundation. All rights reserved.