<property name="ooxml.jar5.dir" location="${ooxml.lib}/jsr173_1.0_api.jar"/>
<property name="ooxml.jar5.url" value="${repository}/xmlbeans/jars/jsr173_1.0_api.jar"/>
<!-- No official release of openxml4j yet -->
- <property name="ooxml.jar6.dir" location="${ooxml.lib}/openxml4j-bin-alpha-080322.jar"/>
- <property name="ooxml.jar6.url" value="http://people.apache.org/~nick/openxml4j-bin-alpha-080322.jar"/>
+ <property name="ooxml.jar6.dir" location="${ooxml.lib}/openxml4j-bin-alpha-080403.jar"/>
+ <property name="ooxml.jar6.url" value="http://people.apache.org/~nick/openxml4j-bin-alpha-080403.jar"/>
<!-- See http://www.ecma-international.org/publications/standards/Ecma-376.htm -->
<!-- "Copy these file(s), free of charge" -->
this.author = author;
}
- /**
- * Fetches the rich text string of the comment
- */
- public HSSFRichTextString getString() {
- return txo.getStr();
- }
-
/**
* Sets the rich text string used by this comment.
*
}
return sheetComments;
}
+ /**
+ * Returns the sheet's comments object if there is one,
+ * or null if not
+ */
+ protected CommentsSource getCommentsSourceIfExists() {
+ return sheetComments;
+ }
/**
* Does this sheet have any comments on it? We need to know,
public String getContentType() { return TYPE; }
public String getRelation() { return REL; }
public String getDefaultFileName() { return DEFAULT_NAME; }
+
+ /**
+ * Returns the filename for the nth one of these,
+ * eg /xl/comments4.xml
+ */
+ public String getFileName(int index) {
+ if(DEFAULT_NAME.indexOf("#") == -1) {
+ // Generic filename in all cases
+ return getDefaultFileName();
+ }
+ return DEFAULT_NAME.replace("#", Integer.toString(index));
+ }
/**
* Fetches the InputStream to read the contents, based
for (int i=0 ; i < this.getNumberOfSheets(); i++) {
int sheetNumber = (i+1);
XSSFSheet sheet = (XSSFSheet) this.getSheetAt(i);
- PackagePartName partName = PackagingURIHelper.createPartName("/xl/worksheets/sheet" + sheetNumber + ".xml");
+ PackagePartName partName = PackagingURIHelper.createPartName(
+ WORKSHEET.getFileName(sheetNumber));
PackageRelationship rel =
corePart.addRelationship(partName, TargetMode.INTERNAL, WORKSHEET.getRelation(), "rSheet" + sheetNumber);
PackagePart part = pkg.createPart(partName, WORKSHEET.getContentType());
workbook.getSheets().getSheetArray(i).setSheetId(sheetNumber);
// If our sheet has comments, then write out those
- // TODO
+ if(sheet.hasComments()) {
+ CommentsTable ct = (CommentsTable)sheet.getCommentsSourceIfExists();
+ PackagePartName ctName = PackagingURIHelper.createPartName(
+ SHEET_COMMENTS.getFileName(sheetNumber));
+ part.addRelationship(ctName, TargetMode.INTERNAL, SHEET_COMMENTS.getRelation(), "rComments");
+ PackagePart ctPart = pkg.createPart(ctName, SHEET_COMMENTS.getContentType());
+
+ out = ctPart.getOutputStream();
+ ct.writeTo(out);
+ out.close();
+ }
}
// Write shared strings and styles
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Comment;
assertEquals(2, cc7.getColumn());
}
- public void DISABLEDtestWriteRead() throws Exception {
+ public void testWriteRead() throws Exception {
File xml = new File(
System.getProperty("HSSF.testdata.path") +
File.separator + "WithVariousData.xlsx"
assertEquals(commentText, comment.getString().getString());
assertEquals(cellRow, comment.getRow());
assertEquals(cellColumn, comment.getColumn());
+
+
+ // Change slightly, and re-test
+ comment.setString(new HSSFRichTextString("New Comment Text"));
+
+ out = new ByteArrayOutputStream();
+ wb.write(out);
+ out.close();
+
+ wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+ sheet = wb.getSheetAt(0);
+ cell = sheet.getRow(cellRow).getCell(cellColumn);
+ comment = cell.getCellComment();
+
+ assertNotNull(comment);
+ assertEquals(HSSFSimpleShape.OBJECT_TYPE_COMMENT, comment.getShapeType());
+ assertEquals(commentAuthor, comment.getAuthor());
+ assertEquals("New Comment Text", comment.getString().getString());
+ assertEquals(cellRow, comment.getRow());
+ assertEquals(cellColumn, comment.getColumn());
}
/**