Spreadsheet KPart Simulation
[Blog Map] This blog is inactive. New blog: EricWhite.com/blog
1 Overview
This example demonstrates how to use the elements and attributes for embedded, linked objects as defined in DIS 29500. It shows that the definition is more than adequate for configuring a KPart object that is embedded in a spreadsheet.
The C++ code reads Open XML for a spreadsheet and follows the appropriate rules for processing of SpreadsheetML. The sample spreadsheet includes a linked object in the same way that Microsoft Excel would specify an OLE object, but this code will show how a KPart can be instantiated for that purpose. The program reads the SpreadsheetML for data in the rows and cells and simulates the display of that data in a window. It also reads the definition for a linked object and uses those defined values to create a KPart object of the specified type and position. The C++ code was compiled using gcc on Linux to produce a working executable. The specification for the KPart comes entirely from the SpreadsheetML and can be used to instantiate a variety of different KPart objects without modification to the code.
The code is not intended to demonstrate the functionality of a spreadsheet program, so it has been simplified to read a maximum of ten rows and ten columns. The display of that data is in a simple, read-only grid without gridlines.
The linked object code shows how to instantiate a KPart, but does not fully implement every aspect of OLE processing that a commercial spreadsheet would. For example, a commercial spreadsheet would support the preference to show an image of the embedded object until the user wants to edit the embedded object, then the embedded object would be instantiated and activated for user interaction. This example does show how to use most of the elements including:
· Using the externalReferences element in workbook.xml to retrieve the id of the external part.
· Using the XML in containerxlexternalLinksexternalLink1.xml to specify the library (libkhtmlpart) and the part (KHTML).
· Using the oleObjects and oleObject elements to configure the specific part and the shapeId.
· Using the shape element in containerxldrawingsvmlDrawing1.vml to position the embedded object.
The example also shows the accepted method for processing Open XML by retrieving all parts of the document using relationships. Parts are retrieved by their content type or by id as appropriate.
The KPart shown in this example is the HTML browser. The target file is named in the embedded object target. The object allows scrolling through the HTML page and following links from that page. Here is a sample image from the example:
The data for each cell is simply 111, 222, 333, and so on for a 3x3 set of rows and columns. As you can see in the following image, the window can be resized to show more of the spreadsheet, but the embedded object keeps its defined absolute location as specified in vmlDrawing1.vml file.
2 Implementation Notes
The example has several limitation and caveats as described below. These choices were made to keep the example as comprehensible as possible and to focus on the key elements for object embedding.
· All of the separate parts of the spreadsheet would normally be contained in a single zipped document file. The example does not access the file in zipped format. Instead, it accesses the parts in their unzipped directory structure. The file name specified for the document is the top directory name (container). A commercial spreadsheet application would need to access the zipped document file directly.
· If you wish to run the example yourself, you will need to change the absolute file name that appears in externalLink1.xml.res. The use of an absolute file name in that element is normal for embedded objects.
· Only the first sheet is processed from the workbook. However, it is processed as a separate Sheet object that could be expanded to handle other sheets.
· Only one external link reference is processed in the example.
· The example only demonstrates absolute positioning of the embedded object. The VML file has options for other types of positioning that would normally be implemented in a commercial spreadsheet application.
· The example has been simplified to assume absolute positioning from the VML file. Other forms of positioning are left as an exercise for the reader.
· The example supports the use of UTF-8 characters in much of the XML processing, but may need to be expanded for full support of UTF-8 in its directory and file name manipulations.
3 Markup
This section shows the XML that configures the KPart.
3.1 workbook.xml
Shown below is the workbook, which contains the externalReferences element.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workbook xmlns="https://schemas.openxmlformats.org/spreadsheetml/2006/main"
xmlns:r="https://schemas.openxmlformats.org/officeDocument/2006/relationships">
<fileVersion appName="xl"
lastEdited="4"
lowestEdited="4"
rupBuild="4505"/>
<workbookPr defaultThemeVersion="124226"/>
<bookViews>
<workbookView xWindow="600"
yWindow="390"
windowWidth="19815"
windowHeight="11715"/>
</bookViews>
<sheets>
<sheet name="Sheet1"
sheetId="1"
r:id="rId1"/>
<sheet name="Sheet2"
sheetId="2"
r:id="rId2"/>
<sheet name="Sheet3"
sheetId="3"
r:id="rId3"/>
</sheets>
<externalReferences>
<externalReference r:id="rId4"/>
</externalReferences>
<calcPr calcId="125725"/>
</workbook>
3.2 externalLink1.xml
Shown below is the external link XML document, which configures the KPart:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<externalLink xmlns="https://schemas.openxmlformats.org/spreadsheetml/2006/main">
<oleLink xmlns:r="https://schemas.openxmlformats.org/officeDocument/2006/relationships"
r:id="rKp1"
progId="libkhtmlpart">
<oleItems>
<oleItem name="KHTML"
advise="1"
preferPic="false"/>
</oleItems>
</oleLink>
</externalLink>
3.3 sheet1.xml
Shown below is sheet1.xml, which specifies the row and cell data. It also contains the oleObjects and oleObject elements specifying that the embedded KPart is in this sheet.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<worksheet xmlns="https://schemas.openxmlformats.org/spreadsheetml/2006/main"
xmlns:r="https://schemas.openxmlformats.org/officeDocument/2006/relationships">
<dimension ref="A1"/>
<sheetViews>
<sheetView tabSelected="1"
workbookViewId="0">
<selection activeCell="B18"
sqref="B18"/>
</sheetView>
</sheetViews>
<sheetFormatPr defaultRowHeight="15"/>
<sheetData>
<row r="1"
spans="1:3">
<c r="A1">
<v>111</v>
</c>
<c r="B1">
<v>222</v>
</c>
<c r="C1">
<v>333</v>
</c>
</row>
Comments
Anonymous
March 10, 2008
The myth that Open XML's object embedding model is not compatible with KParts is much like the reanimatedAnonymous
April 02, 2008
Can you please post the entire document? I am having problems recreating it from these instructions. Thank youAnonymous
April 07, 2008
The entire source code is posted. Here are the links for a tutorial on developing a KPart: http://developer.kde.org/documentation/books/kde-2.0-development/index.html http://developer.kde.org/documentation/books/kde-2.0-development/ch12.html These are KDE 2.0 and the example is 3.0. I never found a comparable document for 3.0, but I did find a website that had the source for the same tutorial example for KDE 3.0. It would take me some time to locate that site again, but I think it was one of the main developer sites for KDE.